mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-75148 mod_data: Add isplugin info to presets
This activity currently supports two different preset types: - Datapreset plugins, that can be installed copying them to the mod/data/preset folder. - Presets saved manually by users. This commit adds an attribute to the presets to mark them, in order to identify them later (because, for instance, the plugins can't be removed). Apart from that, the methods in lib.php, involved with this issue, have been deprecated. New methods have been implemented in the manager class, covering them with PHPUnit tests.
This commit is contained in:
parent
abeae6acb2
commit
9d10f7d19e
9 changed files with 508 additions and 88 deletions
|
@ -28,21 +28,27 @@
|
|||
* @package mod_data
|
||||
*/
|
||||
|
||||
use mod_data\manager;
|
||||
|
||||
require_once('../../config.php');
|
||||
require_once($CFG->dirroot.'/mod/data/lib.php');
|
||||
require_once($CFG->dirroot.'/mod/data/preset_form.php');
|
||||
|
||||
$id = optional_param('id', 0, PARAM_INT); // The course module id.
|
||||
// The course module id.
|
||||
$id = optional_param('id', 0, PARAM_INT);
|
||||
|
||||
$manager = null;
|
||||
if ($id) {
|
||||
$cm = get_coursemodule_from_id('data', $id, null, null, MUST_EXIST);
|
||||
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
|
||||
$data = $DB->get_record('data', array('id' => $cm->instance), '*', MUST_EXIST);
|
||||
list($course, $cm) = get_course_and_cm_from_cmid($id, manager::MODULE);
|
||||
$manager = manager::create_from_coursemodule($cm);
|
||||
$data = $manager->get_instance();
|
||||
} else {
|
||||
$d = required_param('d', PARAM_INT); // database activity id
|
||||
$data = $DB->get_record('data', array('id' => $d), '*', MUST_EXIST);
|
||||
$course = $DB->get_record('course', array('id' => $data->course), '*', MUST_EXIST);
|
||||
$cm = get_coursemodule_from_instance('data', $data->id, $course->id, null, MUST_EXIST);
|
||||
// We must have the database activity id.
|
||||
$d = required_param('d', PARAM_INT);
|
||||
$data = $DB->get_record('data', ['id' => $d], '*', MUST_EXIST);
|
||||
$manager = manager::create_from_instance($data);
|
||||
$cm = $manager->get_coursemodule();
|
||||
$course = get_course($cm->course);
|
||||
}
|
||||
|
||||
$action = optional_param('action', 'view', PARAM_ALPHA); // The page action.
|
||||
|
@ -52,7 +58,8 @@ if (!in_array($action, $allowedactions)) {
|
|||
throw new moodle_exception('invalidaccess');
|
||||
}
|
||||
|
||||
$context = context_module::instance($cm->id, MUST_EXIST);
|
||||
$context = $manager->get_context();
|
||||
|
||||
require_login($course, false, $cm);
|
||||
require_capability('mod/data:managetemplates', $context);
|
||||
|
||||
|
@ -70,7 +77,7 @@ $data->cmidnumber = $cm->idnumber;
|
|||
$data->instance = $cm->instance;
|
||||
|
||||
$renderer = $PAGE->get_renderer('mod_data');
|
||||
$presets = data_get_available_presets($context);
|
||||
$presets = $manager->get_available_presets();
|
||||
|
||||
if ($action === 'export') {
|
||||
if (headers_sent()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue