first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+106
View File
@@ -0,0 +1,106 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Class for exporting content associated to a record.
*
* @package mod_data
* @copyright 2017 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_data\external;
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
use renderer_base;
use core_external\external_files;
use core_external\util as external_util;
/**
* Class for exporting content associated to a record.
*
* @copyright 2017 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class content_exporter extends exporter {
protected static function define_properties() {
return array(
'id' => array(
'type' => PARAM_INT,
'description' => 'Content id.',
),
'fieldid' => array(
'type' => PARAM_INT,
'description' => 'The field type of the content.',
'default' => 0,
),
'recordid' => array(
'type' => PARAM_INT,
'description' => 'The record this content belongs to.',
'default' => 0,
),
'content' => array(
'type' => PARAM_RAW,
'description' => 'Contents.',
'null' => NULL_ALLOWED,
),
'content1' => array(
'type' => PARAM_RAW,
'description' => 'Contents.',
'null' => NULL_ALLOWED,
),
'content2' => array(
'type' => PARAM_RAW,
'description' => 'Contents.',
'null' => NULL_ALLOWED,
),
'content3' => array(
'type' => PARAM_RAW,
'description' => 'Contents.',
'null' => NULL_ALLOWED,
),
'content4' => array(
'type' => PARAM_RAW,
'description' => 'Contents.',
'null' => NULL_ALLOWED,
),
);
}
protected static function define_related() {
return array(
'context' => 'context',
);
}
protected static function define_other_properties() {
return array(
'files' => array(
'type' => external_files::get_properties_for_exporter(),
'multiple' => true,
'optional' => true,
),
);
}
protected function get_other_values(renderer_base $output) {
$values = ['files' => external_util::get_area_files($this->related['context']->id, 'mod_data', 'content', $this->data->id)];
return $values;
}
}
+248
View File
@@ -0,0 +1,248 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Class for exporting partial database data.
*
* @package mod_data
* @copyright 2017 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_data\external;
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
use renderer_base;
use core_external\external_files;
use core_external\util as external_util;
/**
* Class for exporting partial database data (some fields are only viewable by admins).
*
* @copyright 2017 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class database_summary_exporter extends exporter {
protected static function define_properties() {
return array(
'id' => array(
'type' => PARAM_INT,
'description' => 'Database id'),
'course' => array(
'type' => PARAM_INT,
'description' => 'Course id'),
'name' => array(
'type' => PARAM_RAW,
'description' => 'Database name'),
'intro' => array(
'type' => PARAM_RAW,
'description' => 'The Database intro',
),
'introformat' => array(
'choices' => array(FORMAT_HTML, FORMAT_MOODLE, FORMAT_PLAIN, FORMAT_MARKDOWN),
'type' => PARAM_INT,
'default' => FORMAT_MOODLE
),
'lang' => array(
'type' => PARAM_LANG,
'description' => 'Forced activity language',
'null' => NULL_ALLOWED,
),
'comments' => array(
'type' => PARAM_BOOL,
'description' => 'comments enabled',
),
'timeavailablefrom' => array(
'type' => PARAM_INT,
'description' => 'timeavailablefrom field',
),
'timeavailableto' => array(
'type' => PARAM_INT,
'description' => 'timeavailableto field',
),
'timeviewfrom' => array(
'type' => PARAM_INT,
'description' => 'timeviewfrom field',
),
'timeviewto' => array(
'type' => PARAM_INT,
'description' => 'timeviewto field',
),
'requiredentries' => array(
'type' => PARAM_INT,
'description' => 'requiredentries field',
),
'requiredentriestoview' => array(
'type' => PARAM_INT,
'description' => 'requiredentriestoview field',
),
'maxentries' => array(
'type' => PARAM_INT,
'description' => 'maxentries field',
),
'rssarticles' => array(
'type' => PARAM_INT,
'description' => 'rssarticles field',
),
'singletemplate' => array(
'type' => PARAM_RAW,
'description' => 'singletemplate field',
'null' => NULL_ALLOWED,
),
'listtemplate' => array(
'type' => PARAM_RAW,
'description' => 'listtemplate field',
'null' => NULL_ALLOWED,
),
'listtemplateheader' => array(
'type' => PARAM_RAW,
'description' => 'listtemplateheader field',
'null' => NULL_ALLOWED,
),
'listtemplatefooter' => array(
'type' => PARAM_RAW,
'description' => 'listtemplatefooter field',
'null' => NULL_ALLOWED,
),
'addtemplate' => array(
'type' => PARAM_RAW,
'description' => 'addtemplate field',
'null' => NULL_ALLOWED,
),
'rsstemplate' => array(
'type' => PARAM_RAW,
'description' => 'rsstemplate field',
'null' => NULL_ALLOWED,
),
'rsstitletemplate' => array(
'type' => PARAM_RAW,
'description' => 'rsstitletemplate field',
'null' => NULL_ALLOWED,
),
'csstemplate' => array(
'type' => PARAM_RAW,
'description' => 'csstemplate field',
'null' => NULL_ALLOWED,
),
'jstemplate' => array(
'type' => PARAM_RAW,
'description' => 'jstemplate field',
'null' => NULL_ALLOWED,
),
'asearchtemplate' => array(
'type' => PARAM_RAW,
'description' => 'asearchtemplate field',
'null' => NULL_ALLOWED,
),
'approval' => array(
'type' => PARAM_BOOL,
'description' => 'approval field',
),
'manageapproved' => array(
'type' => PARAM_BOOL,
'description' => 'manageapproved field',
),
'scale' => array(
'type' => PARAM_INT,
'description' => 'scale field',
'optional' => true,
),
'assessed' => array(
'type' => PARAM_INT,
'description' => 'assessed field',
'optional' => true,
),
'assesstimestart' => array(
'type' => PARAM_INT,
'description' => 'assesstimestart field',
'optional' => true,
),
'assesstimefinish' => array(
'type' => PARAM_INT,
'description' => 'assesstimefinish field',
'optional' => true,
),
'defaultsort' => array(
'type' => PARAM_INT,
'description' => 'defaultsort field',
),
'defaultsortdir' => array(
'type' => PARAM_INT,
'description' => 'defaultsortdir field',
),
'editany' => array(
'type' => PARAM_BOOL,
'description' => 'editany field (not used any more)',
'optional' => true,
),
'notification' => array(
'type' => PARAM_INT,
'description' => 'notification field (not used any more)',
'optional' => true,
),
'timemodified' => array(
'type' => PARAM_INT,
'description' => 'Time modified',
'optional' => true,
),
);
}
protected static function define_related() {
return array(
'context' => 'context'
);
}
protected static function define_other_properties() {
return array(
'coursemodule' => array(
'type' => PARAM_INT
),
'introfiles' => array(
'type' => external_files::get_properties_for_exporter(),
'multiple' => true,
'optional' => true,
),
);
}
protected function get_other_values(renderer_base $output) {
$context = $this->related['context'];
$values = array(
'coursemodule' => $context->instanceid,
'introfiles' => external_util::get_area_files($context->id, 'mod_data', 'intro', false, false),
);
return $values;
}
/**
* Get the formatting parameters for the intro.
*
* @return array
*/
protected function get_format_parameters_for_intro() {
return [
'component' => 'mod_data',
'filearea' => 'intro',
'options' => array('noclean' => true),
];
}
}
+123
View File
@@ -0,0 +1,123 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace mod_data\external;
use core\notification;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_multiple_structure;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
use mod_data\manager;
use mod_data\preset;
/**
* This is the external method for deleting a saved preset.
*
* @package mod_data
* @since Moodle 4.1
* @copyright 2022 Amaia Anabitarte <amaia@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class delete_saved_preset extends external_api {
/**
* Parameters.
*
* @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters([
'dataid' => new external_value(PARAM_INT, 'Id of the data activity', VALUE_REQUIRED),
'presetnames' => new external_multiple_structure(
new external_value(PARAM_TEXT, 'The preset name to delete', VALUE_REQUIRED)
)
]);
}
/**
* Delete saved preset from the file system.
*
* @param int $dataid Id of the data activity to check context and permissions.
* @param array $presetnames List of saved preset names to delete.
* @return array True if the content has been deleted; false and the warning, otherwise.
*/
public static function execute(int $dataid, array $presetnames): array {
global $DB;
$result = false;
$warnings = [];
$params = self::validate_parameters(self::execute_parameters(), ['dataid' => $dataid, 'presetnames' => $presetnames]);
$instance = $DB->get_record('data', ['id' => $params['dataid']], '*', MUST_EXIST);
$manager = manager::create_from_instance($instance);
foreach ($params['presetnames'] as $presetname) {
try {
$preset = preset::create_from_instance($manager, $presetname);
if ($preset->can_manage()) {
if ($preset->delete()) {
notification::success(get_string('presetdeleted', 'mod_data'));
$result = true;
} else {
// An error ocurred while deleting the preset.
$warnings[] = [
'item' => $presetname,
'warningcode' => 'failedpresetdelete',
'message' => get_string('failedpresetdelete', 'mod_data')
];
notification::error(get_string('failedpresetdelete', 'mod_data'));
}
} else {
// The user has no permission to delete the preset.
$warnings[] = [
'item' => $presetname,
'warningcode' => 'cannotdeletepreset',
'message' => get_string('cannotdeletepreset', 'mod_data')
];
notification::error(get_string('cannotdeletepreset', 'mod_data'));
}
} catch (\moodle_exception $e) {
// The saved preset has not been deleted.
$warnings[] = [
'item' => $presetname,
'warningcode' => 'exception',
'message' => $e->getMessage()
];
notification::error($e->getMessage());
}
}
return [
'result' => $result,
'warnings' => $warnings
];
}
/**
* Return.
*
* @return external_single_structure
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'result' => new external_value(PARAM_BOOL, 'The processing result'),
'warnings' => new external_warnings()
]);
}
}
+85
View File
@@ -0,0 +1,85 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Class for exporting field data.
*
* @package mod_data
* @copyright 2017 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_data\external;
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
/**
* Class for exporting field data.
*
* @copyright 2017 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class field_exporter extends exporter {
protected static function define_properties() {
$properties = array(
'id' => array(
'type' => PARAM_INT,
'description' => 'Field id.',
),
'dataid' => array(
'type' => PARAM_INT,
'description' => 'The field type of the content.',
'default' => 0,
),
'type' => array(
'type' => PARAM_PLUGIN,
'description' => 'The field type.',
),
'name' => array(
'type' => PARAM_TEXT,
'description' => 'The field name.',
),
'description' => array(
'type' => PARAM_RAW,
'description' => 'The field description.',
),
'required' => array(
'type' => PARAM_BOOL,
'description' => 'Whether is a field required or not.',
'default' => 0,
),
);
// Field possible parameters.
for ($i = 1; $i <= 10; $i++) {
$properties["param$i"] = array(
'type' => PARAM_RAW,
'description' => 'Field parameters',
'null' => NULL_ALLOWED,
);
}
return $properties;
}
protected static function define_related() {
// Context is required for text formatting.
return array(
'context' => 'context',
);
}
}
+97
View File
@@ -0,0 +1,97 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace mod_data\external;
use core\notification;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
use mod_data\local\importer\preset_importer;
use mod_data\manager;
/**
* This is the external method for deleting a saved preset.
*
* @package mod_data
* @since Moodle 4.1
* @copyright 2022 Amaia Anabitarte <amaia@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class get_mapping_information extends external_api {
/**
* Parameters.
*
* @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters([
'cmid' => new external_value(PARAM_INT, 'Id of the data activity', VALUE_REQUIRED),
'importedpreset' => new external_value(PARAM_TEXT, 'Preset to be imported'),
]);
}
/**
* Get importing information for the given database course module.
*
* @param int $cmid Id of the course module where to import the preset.
* @param string $importedpreset Plugin or saved preset to be imported.
* @return array Information needed to decide whether to show the dialogue or not.
*/
public static function execute(int $cmid, string $importedpreset): array {
$params = self::validate_parameters(
self::execute_parameters(),
['cmid' => $cmid, 'importedpreset' => $importedpreset]
);
try {
// Let's get the manager.
list($course, $cm) = get_course_and_cm_from_cmid($params['cmid'], manager::MODULE);
$manager = manager::create_from_coursemodule($cm);
$importer = preset_importer::create_from_plugin_or_directory($manager, $params['importedpreset']);
$result['data'] = $importer->get_mapping_information();
} catch (\moodle_exception $e) {
$result['warnings'][] = [
'item' => $importedpreset,
'warningcode' => 'exception',
'message' => $e->getMessage()
];
notification::error($e->getMessage());
}
return $result;
}
/**
* Return.
*
* @return external_single_structure
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'data' => new external_single_structure([
'needsmapping' => new external_value(PARAM_BOOL, 'Whether the importing needs mapping or not'),
'presetname' => new external_value(PARAM_TEXT, 'Name of the applied preset'),
'fieldstocreate' => new external_value(PARAM_TEXT, 'List of field names to create'),
'fieldstoremove' => new external_value(PARAM_TEXT, 'List of field names to remove'),
], 'Information to import if everything went fine', VALUE_OPTIONAL),
'warnings' => new external_warnings(),
]);
}
}
+143
View File
@@ -0,0 +1,143 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Class for exporting record data.
*
* @package mod_data
* @copyright 2017 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_data\external;
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
use renderer_base;
use core_user;
use core_tag\external\tag_item_exporter;
/**
* Class for exporting record data.
*
* @copyright 2017 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class record_exporter extends exporter {
protected static function define_properties() {
return array(
'id' => array(
'type' => PARAM_INT,
'description' => 'Record id.',
),
'userid' => array(
'type' => PARAM_INT,
'description' => 'The id of the user who created the record.',
'default' => 0,
),
'groupid' => array(
'type' => PARAM_INT,
'description' => 'The group id this record belongs to (0 for no groups).',
'default' => 0,
),
'dataid' => array(
'type' => PARAM_INT,
'description' => 'The database id this record belongs to.',
'default' => 0,
),
'timecreated' => array(
'type' => PARAM_INT,
'description' => 'Time the record was created.',
'default' => 0,
),
'timemodified' => array(
'type' => PARAM_INT,
'description' => 'Last time the record was modified.',
'default' => 0,
),
'approved' => array(
'type' => PARAM_BOOL,
'description' => 'Whether the entry has been approved (if the database is configured in that way).',
'default' => 0,
),
);
}
protected static function define_related() {
return array(
'database' => 'stdClass',
'user' => 'stdClass?',
'context' => 'context',
'contents' => 'stdClass[]?',
);
}
protected static function define_other_properties() {
return array(
'canmanageentry' => array(
'type' => PARAM_BOOL,
'description' => 'Whether the current user can manage this entry',
),
'fullname' => array(
'type' => PARAM_TEXT,
'description' => 'The user who created the entry fullname.',
'optional' => true,
),
'contents' => array(
'type' => content_exporter::read_properties_definition(),
'description' => 'The record contents.',
'multiple' => true,
'optional' => true,
),
'tags' => array(
'type' => tag_item_exporter::read_properties_definition(),
'description' => 'Tags.',
'multiple' => true,
'optional' => true,
),
);
}
protected function get_other_values(renderer_base $output) {
global $PAGE;
$values = array(
'canmanageentry' => data_user_can_manage_entry($this->data, $this->related['database'], $this->related['context']),
);
if (!empty($this->related['user']) and !empty($this->related['user']->id)) {
$values['fullname'] = fullname($this->related['user']);
} else if ($this->data->userid) {
$user = core_user::get_user($this->data->userid);
$values['fullname'] = fullname($user);
}
if (!empty($this->related['contents'])) {
$contents = [];
foreach ($this->related['contents'] as $content) {
$related = array('context' => $this->related['context']);
$exporter = new content_exporter($content, $related);
$contents[] = $exporter->export($PAGE->get_renderer('core'));
}
$values['contents'] = $contents;
}
$values['tags'] = \core_tag\external\util::get_item_tags('mod_data', 'data_records', $this->data->id);
return $values;
}
}