2023-10-18 08:46:44 +02:00
|
|
|
<?php
|
2024-06-02 23:23:32 +02:00
|
|
|
// This file is part of the Studyplan plugin for Moodle
|
|
|
|
//
|
|
|
|
// 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 <https://www.gnu.org/licenses/>.
|
2024-07-19 12:31:26 +02:00
|
|
|
|
2024-06-02 23:23:32 +02:00
|
|
|
/**
|
|
|
|
* No file description
|
|
|
|
* @package local_treestudyplan
|
|
|
|
* @copyright 2023 P.M. Kuipers
|
|
|
|
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
2023-10-18 08:46:44 +02:00
|
|
|
|
2023-10-24 21:55:53 +02:00
|
|
|
namespace local_treestudyplan\form;
|
2024-01-26 12:26:01 +01:00
|
|
|
defined('MOODLE_INTERNAL') || die();
|
2023-10-23 21:54:09 +02:00
|
|
|
|
2024-01-26 12:26:01 +01:00
|
|
|
require_once($CFG->dirroot.'/repository/lib.php');
|
2023-10-23 21:54:09 +02:00
|
|
|
use local_treestudyplan\aggregator;
|
2023-10-19 17:48:43 +02:00
|
|
|
use local_treestudyplan\studyplan;
|
2024-05-10 15:22:52 +02:00
|
|
|
use local_treestudyplan\debug;
|
2023-11-05 15:49:32 +01:00
|
|
|
use local_treestudyplan\studyplanservice;
|
2023-10-23 21:54:09 +02:00
|
|
|
use local_treestudyplan\courseservice;
|
2024-08-22 10:46:32 +02:00
|
|
|
use local_treestudyplan\contextinfo;
|
2023-10-24 21:55:53 +02:00
|
|
|
use local_treestudyplan\form\text_integer;
|
2023-10-21 23:24:25 +02:00
|
|
|
use moodle_exception;
|
2023-10-20 14:03:13 +02:00
|
|
|
use stdClass;
|
|
|
|
|
2023-10-19 17:35:51 +02:00
|
|
|
/**
|
2024-06-02 19:23:40 +02:00
|
|
|
* Moodleform class for the studyplan editor. A Moodleform is used here to facilitate a rich editor
|
|
|
|
* in the studyplan description
|
2023-10-19 17:35:51 +02:00
|
|
|
*/
|
|
|
|
class studyplan_editform extends formbase {
|
2023-10-19 17:48:43 +02:00
|
|
|
/**
|
|
|
|
* Capability required to edit study plans
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
const CAP_EDIT = "local/treestudyplan:editstudyplan";
|
2023-10-20 14:03:13 +02:00
|
|
|
|
2023-10-19 17:35:51 +02:00
|
|
|
/**
|
2024-06-02 19:23:40 +02:00
|
|
|
* Translate parameters into customdata.
|
|
|
|
*
|
2023-10-19 17:48:43 +02:00
|
|
|
* @param object $params The parameters for form initialization
|
2023-10-20 14:03:13 +02:00
|
|
|
* @return array Form data based on parameters
|
2024-06-02 19:23:40 +02:00
|
|
|
*/
|
2023-10-20 14:03:13 +02:00
|
|
|
public static function init_customdata(object $params) {
|
|
|
|
$customdata = new stdClass;
|
2024-06-02 23:23:32 +02:00
|
|
|
$customdata->create = $params->mode == 'create' ? true : false;
|
2024-06-02 19:23:40 +02:00
|
|
|
if ($customdata->create) {
|
2023-10-23 21:54:09 +02:00
|
|
|
$customdata->context = \context::instance_by_id($params->contextid);
|
|
|
|
} else {
|
2024-06-02 19:23:40 +02:00
|
|
|
|
2023-10-23 21:54:09 +02:00
|
|
|
$customdata->plan = studyplan::find_by_id($params->studyplan_id);
|
|
|
|
$customdata->context = $customdata->plan->context();
|
|
|
|
$customdata->simplemodel = $customdata->plan->simple_model();
|
|
|
|
}
|
|
|
|
|
2023-10-20 14:03:13 +02:00
|
|
|
$customdata->editoroptions = [
|
|
|
|
'trusttext' => true,
|
|
|
|
'subdirs' => true,
|
|
|
|
'maxfiles' => 20,
|
2024-06-02 23:23:32 +02:00
|
|
|
'maxbytes' => 20 * 1024 * 1024,
|
|
|
|
'context' => \context_system::instance(), // Keep the files in system context.
|
2023-10-23 21:54:09 +02:00
|
|
|
];
|
|
|
|
$customdata->fileoptions = [
|
|
|
|
'subdirs' => 0,
|
2024-06-02 23:23:32 +02:00
|
|
|
'maxbytes' => 10 * 1024 * 1024, // Max 10MiB should be sufficient for a picture.
|
2023-10-23 21:54:09 +02:00
|
|
|
'areamaxbytes' => 10485760,
|
2024-06-02 23:23:32 +02:00
|
|
|
'maxfiles' => 1, // Just one file.
|
2023-12-13 12:22:34 +01:00
|
|
|
'accepted_types' => ['.jpg', '.png', '.jpeg', '.svg', '.svgz'],
|
2024-01-26 12:26:01 +01:00
|
|
|
'return_types' => \FILE_INTERNAL | \FILE_EXTERNAL,
|
2023-10-20 14:03:13 +02:00
|
|
|
];
|
2024-06-02 19:23:40 +02:00
|
|
|
return $customdata;
|
2023-10-20 14:03:13 +02:00
|
|
|
}
|
|
|
|
|
2023-10-19 17:35:51 +02:00
|
|
|
/**
|
|
|
|
* Generate form data from parameters
|
|
|
|
* Also validate parameters and access permissions here
|
2024-06-02 19:23:40 +02:00
|
|
|
*
|
2023-10-20 14:03:13 +02:00
|
|
|
* @param object $customdata The parameters for form initialization
|
2023-10-19 17:35:51 +02:00
|
|
|
* @return array Form data based on parameters
|
2024-06-02 19:23:40 +02:00
|
|
|
*/
|
2023-10-20 14:03:13 +02:00
|
|
|
public function init_formdata(object $customdata) {
|
|
|
|
global $DB;
|
|
|
|
/* Use direct database retrieval to avoid our abstractions causing trouble
|
2024-06-02 19:23:40 +02:00
|
|
|
with existing moodle code assumptions.
|
2023-10-20 14:03:13 +02:00
|
|
|
The form API does seem needlessly convoluted in it's use, but we need the editor...
|
|
|
|
*/
|
2024-06-02 19:23:40 +02:00
|
|
|
if ($customdata->create) {
|
2023-10-23 21:54:09 +02:00
|
|
|
$entry = new stdClass;
|
|
|
|
$entry->context_id = $customdata->context->id;
|
2024-06-02 19:23:40 +02:00
|
|
|
$entry->aggregation = get_config("local_treestudyplan", "aggregation_mode");
|
|
|
|
$agcfg = json_decode(aggregator::create($entry->aggregation, "")->config_string(), true);
|
|
|
|
|
2023-10-23 21:54:09 +02:00
|
|
|
// Determine the next august 1st for default value purposes.
|
|
|
|
$august = strtotime("first day of august this year");
|
2024-06-02 19:23:40 +02:00
|
|
|
if ($august < time()) {
|
2023-10-23 21:54:09 +02:00
|
|
|
$august = strtotime("first day of august next year");
|
|
|
|
}
|
|
|
|
$entry->startdate = $august;
|
2024-06-02 23:23:32 +02:00
|
|
|
$entry->enddate = $august + (364 * 24 * 60 * 60); // Not bothering about leap years here.
|
2023-10-23 21:54:09 +02:00
|
|
|
$entry->periods = 4;
|
|
|
|
} else {
|
|
|
|
$entry = $DB->get_record(studyplan::TABLE, ['id' => $customdata->plan->id()]);
|
|
|
|
|
|
|
|
$entry->startdate = strtotime($customdata->simplemodel['pages'][0]['startdate']);
|
|
|
|
$entry->enddate = strtotime($customdata->simplemodel['pages'][0]['enddate']);
|
|
|
|
$entry->periods = $customdata->simplemodel['pages'][0]['periods'];
|
2024-06-02 19:23:40 +02:00
|
|
|
$agcfg = json_decode($customdata->plan->aggregator()->config_string(), true);
|
2023-10-23 21:54:09 +02:00
|
|
|
}
|
|
|
|
|
2024-06-02 23:23:32 +02:00
|
|
|
// Prepare the editor.
|
2023-10-20 14:03:13 +02:00
|
|
|
$entry = file_prepare_standard_editor( $entry,
|
2023-10-23 21:54:09 +02:00
|
|
|
'description',
|
|
|
|
$customdata->editoroptions,
|
|
|
|
\context_system::instance(),
|
|
|
|
'local_treestudyplan',
|
|
|
|
'studyplan',
|
2024-06-02 19:23:40 +02:00
|
|
|
($customdata->create) ? null : $customdata->plan->id()
|
2023-10-23 21:54:09 +02:00
|
|
|
);
|
|
|
|
|
2024-06-02 23:23:32 +02:00
|
|
|
// Prepare file area for the icon.
|
2023-10-23 21:54:09 +02:00
|
|
|
// Get an unused draft itemid which will be used for this form.
|
|
|
|
$draftitemid = file_get_submitted_draft_itemid('icon');
|
|
|
|
file_prepare_draft_area(
|
|
|
|
// The $draftitemid is the target location.
|
|
|
|
$draftitemid,
|
2024-06-02 23:23:32 +02:00
|
|
|
// The combination of contextid / component / filearea / itemid.
|
|
|
|
// Form the virtual bucket that files are currently stored in.
|
|
|
|
// And will be copied from.
|
2023-10-23 21:54:09 +02:00
|
|
|
\context_system::instance()->id,
|
|
|
|
'local_treestudyplan',
|
|
|
|
'icon',
|
2024-06-02 19:23:40 +02:00
|
|
|
($customdata->create) ? null : $customdata->plan->id(),
|
2023-10-23 21:54:09 +02:00
|
|
|
$customdata->fileoptions
|
|
|
|
);
|
|
|
|
$entry->icon = $draftitemid;
|
|
|
|
|
|
|
|
// Add aggregation configs to entry.
|
|
|
|
|
2024-06-02 19:23:40 +02:00
|
|
|
foreach ($agcfg as $key => $val) {
|
2023-10-23 21:54:09 +02:00
|
|
|
$entrykey = $entry->aggregation."_".$key;
|
|
|
|
$entry->$entrykey = $val;
|
|
|
|
}
|
|
|
|
|
2023-10-20 14:03:13 +02:00
|
|
|
return $entry;
|
2023-10-23 21:54:09 +02:00
|
|
|
|
2023-10-19 17:35:51 +02:00
|
|
|
}
|
2023-10-18 08:46:44 +02:00
|
|
|
|
2023-10-19 17:35:51 +02:00
|
|
|
/**
|
|
|
|
* Set up the form definition
|
|
|
|
*/
|
2023-10-18 08:46:44 +02:00
|
|
|
public function definition() {
|
|
|
|
$mform = $this->_form;
|
2023-10-20 14:03:13 +02:00
|
|
|
$customdata = (object)$this->_customdata;
|
2023-10-23 21:54:09 +02:00
|
|
|
|
2024-06-02 23:23:32 +02:00
|
|
|
// Register integer type.
|
|
|
|
text_integer::register();
|
2023-10-23 21:54:09 +02:00
|
|
|
|
2024-06-02 23:23:32 +02:00
|
|
|
// Define the form.
|
2023-10-23 21:54:09 +02:00
|
|
|
$field = 'name';
|
2024-06-02 19:23:40 +02:00
|
|
|
$mform->addElement('text', $field,
|
|
|
|
get_string('studyplan_name', 'local_treestudyplan'),
|
2023-10-23 21:54:09 +02:00
|
|
|
[]);
|
|
|
|
$mform->addRule($field, null, 'required', null, 'client');
|
|
|
|
|
|
|
|
$field = 'shortname';
|
2024-06-02 19:23:40 +02:00
|
|
|
$mform->addElement('text', $field,
|
|
|
|
get_string('studyplan_shortname', 'local_treestudyplan'),
|
2023-10-23 21:54:09 +02:00
|
|
|
[]);
|
|
|
|
$mform->addRule($field, null, 'required', null, 'client');
|
|
|
|
|
|
|
|
$field = 'idnumber';
|
2024-06-02 19:23:40 +02:00
|
|
|
$mform->addElement('text', $field,
|
|
|
|
get_string('studyplan_idnumber', 'local_treestudyplan'),
|
2023-10-23 21:54:09 +02:00
|
|
|
[]);
|
|
|
|
|
|
|
|
$contextlist = [];
|
2024-08-22 10:46:32 +02:00
|
|
|
// Add system if the user has permissions.
|
2024-11-01 12:43:44 +01:00
|
|
|
if (has_all_capabilities([courseservice::CAP_EDIT, 'moodle/category:viewcourselist'], \context_system::instance())) {
|
2024-08-22 10:46:32 +02:00
|
|
|
$contextlist[1] = get_string("coresystem");
|
|
|
|
}
|
|
|
|
// Add any other contexts the user has access to.
|
|
|
|
foreach (courseservice::categories_by_capability(courseservice::CAP_EDIT) as $c) {
|
|
|
|
$ctx = $c->get_context();
|
|
|
|
$ci = new contextinfo($ctx);
|
|
|
|
$contextlist[$ctx->id] = implode(" / ", $ci->path(false));
|
2023-10-23 21:54:09 +02:00
|
|
|
}
|
2023-12-12 23:44:02 +01:00
|
|
|
|
2024-06-02 19:23:40 +02:00
|
|
|
$mform->addElement('autocomplete', 'context_id',
|
|
|
|
get_string('studyplan_context', 'local_treestudyplan'),
|
2023-10-23 21:54:09 +02:00
|
|
|
$contextlist);
|
|
|
|
|
|
|
|
$mform->addRule('context_id', null, 'required', null, 'client');
|
|
|
|
|
|
|
|
$mform->addElement(
|
|
|
|
'filemanager',
|
|
|
|
'icon',
|
|
|
|
get_string('studyplan_icon', 'local_treestudyplan'),
|
|
|
|
null,
|
|
|
|
$customdata->fileoptions
|
|
|
|
);
|
|
|
|
|
2023-11-05 15:49:32 +01:00
|
|
|
if ($customdata->create) {
|
2024-06-02 19:23:40 +02:00
|
|
|
$timeless = \get_config("local_treestudyplan", "timelessperiods");
|
2024-06-02 23:23:32 +02:00
|
|
|
if (!$timeless) {
|
|
|
|
// Only add these fields if a new studyplan is created, to easily initialize the first page.
|
2024-03-10 23:09:33 +01:00
|
|
|
$field = 'startdate';
|
2024-06-02 19:23:40 +02:00
|
|
|
$mform->addElement('date_selector', $field,
|
|
|
|
get_string('studyplan_startdate', 'local_treestudyplan'),
|
2024-03-10 23:09:33 +01:00
|
|
|
[]);
|
|
|
|
$mform->addRule($field, null, 'required', null, 'client');
|
|
|
|
|
|
|
|
$field = 'enddate';
|
2024-06-02 19:23:40 +02:00
|
|
|
$mform->addElement('date_selector', $field,
|
|
|
|
get_string('studyplan_enddate', 'local_treestudyplan'),
|
2024-03-10 23:09:33 +01:00
|
|
|
[]);
|
|
|
|
$mform->addRule($field, null, 'required', null, 'client');
|
2024-06-02 19:23:40 +02:00
|
|
|
|
2024-03-10 23:09:33 +01:00
|
|
|
}
|
2023-11-05 15:49:32 +01:00
|
|
|
$field = 'periods';
|
2024-06-02 19:23:40 +02:00
|
|
|
$mform->addElement('text_integer', $field,
|
|
|
|
get_string('studyplan_slots', 'local_treestudyplan'),
|
2023-11-05 15:49:32 +01:00
|
|
|
["unsigned" => true]);
|
|
|
|
$mform->setType($field, PARAM_INT);
|
|
|
|
$mform->addRule($field, null, 'required', null, 'client');
|
2023-10-23 21:54:09 +02:00
|
|
|
|
2024-03-10 15:56:35 +01:00
|
|
|
} else {
|
2024-06-02 23:23:32 +02:00
|
|
|
// These fields are only relevant if the studyplan is edited.
|
2024-03-10 15:56:35 +01:00
|
|
|
$field = 'suspended';
|
2024-06-02 19:23:40 +02:00
|
|
|
$mform->addElement('advcheckbox', $field,
|
|
|
|
get_string('studyplan_suspend', 'local_treestudyplan'),
|
|
|
|
get_string('studyplan_suspend_details', 'local_treestudyplan'),
|
2024-03-10 15:56:35 +01:00
|
|
|
[],
|
|
|
|
);
|
2024-04-19 16:46:30 +02:00
|
|
|
|
2024-07-19 17:41:49 +02:00
|
|
|
$field = 'template';
|
|
|
|
$mform->addElement('advcheckbox', $field,
|
|
|
|
get_string('studyplan_template', 'local_treestudyplan'),
|
|
|
|
get_string('studyplan_template_details', 'local_treestudyplan'),
|
|
|
|
[],
|
|
|
|
);
|
2023-11-05 15:49:32 +01:00
|
|
|
}
|
2023-10-23 21:54:09 +02:00
|
|
|
|
|
|
|
$aggregators = [];
|
2024-06-02 23:23:32 +02:00
|
|
|
foreach (aggregator::list_model() as $a) {
|
|
|
|
// Add method only if not deprecated or currently used.
|
|
|
|
if ($customdata->simplemodel['aggregation'] == $a['id'] || !($a['deprecated'])) {
|
2023-10-23 21:54:09 +02:00
|
|
|
$aggregators[$a['id']] = $a['name'];
|
|
|
|
}
|
|
|
|
}
|
2024-04-19 16:46:30 +02:00
|
|
|
$field = 'aggregation';
|
2024-06-02 19:23:40 +02:00
|
|
|
$mform->addElement('select', $field,
|
|
|
|
get_string('choose_aggregation_style', 'local_treestudyplan'),
|
2023-10-23 21:54:09 +02:00
|
|
|
$aggregators);
|
|
|
|
|
|
|
|
/* Start Bistate aggregation specific items */
|
|
|
|
$field = 'bistate_thresh_excellent';
|
2024-06-02 19:23:40 +02:00
|
|
|
$mform->addElement('text_integer', $field,
|
|
|
|
get_string('setting_bistate_thresh_excellent', 'local_treestudyplan'),
|
2023-10-24 21:55:53 +02:00
|
|
|
["unsigned" => false],
|
2023-10-23 21:54:09 +02:00
|
|
|
);
|
|
|
|
$mform->setType($field, PARAM_INT);
|
2024-06-02 19:23:40 +02:00
|
|
|
$mform->hideif ($field, "aggregation", "neq", "bistate");
|
2023-10-23 21:54:09 +02:00
|
|
|
|
|
|
|
$field = 'bistate_thresh_good';
|
2024-06-02 19:23:40 +02:00
|
|
|
$mform->addElement('text_integer', $field,
|
|
|
|
get_string('setting_bistate_thresh_good', 'local_treestudyplan'),
|
2023-10-24 21:55:53 +02:00
|
|
|
["unsigned" => true],
|
2023-10-23 21:54:09 +02:00
|
|
|
);
|
|
|
|
$mform->setType($field, PARAM_INT);
|
2024-06-02 19:23:40 +02:00
|
|
|
$mform->hideif ($field, "aggregation", "neq", "bistate");
|
2023-10-23 21:54:09 +02:00
|
|
|
|
|
|
|
$field = 'bistate_thresh_completed';
|
2024-06-02 19:23:40 +02:00
|
|
|
$mform->addElement('text_integer', $field,
|
|
|
|
get_string('setting_bistate_thresh_completed', 'local_treestudyplan'),
|
2023-10-24 21:55:53 +02:00
|
|
|
["unsigned" => true],
|
2023-10-23 21:54:09 +02:00
|
|
|
);
|
|
|
|
$mform->setType($field, PARAM_INT);
|
2024-06-02 19:23:40 +02:00
|
|
|
$mform->hideif ($field, "aggregation", "neq", "bistate");
|
2023-10-23 21:54:09 +02:00
|
|
|
|
|
|
|
$field = 'bistate_use_failed';
|
2024-06-02 19:23:40 +02:00
|
|
|
$mform->addElement('checkbox', $field,
|
|
|
|
get_string('setting_bistate_support_failed', 'local_treestudyplan'),
|
2023-10-23 21:54:09 +02:00
|
|
|
[],
|
|
|
|
);
|
2024-06-02 19:23:40 +02:00
|
|
|
$mform->hideif ($field, "aggregation", "neq", "bistate");
|
|
|
|
|
2023-10-23 21:54:09 +02:00
|
|
|
$field = 'bistate_accept_pending_as_submitted';
|
2024-06-02 19:23:40 +02:00
|
|
|
$mform->addElement('checkbox', $field,
|
|
|
|
get_string('setting_bistate_accept_pending_submitted', 'local_treestudyplan'),
|
2023-10-23 21:54:09 +02:00
|
|
|
[],
|
|
|
|
);
|
2024-06-02 19:23:40 +02:00
|
|
|
$mform->hideif ($field, "aggregation", "neq", "bistate");
|
2023-10-23 21:54:09 +02:00
|
|
|
|
|
|
|
/* End Bistate aggregation specific items */
|
|
|
|
|
2023-10-20 14:03:13 +02:00
|
|
|
$mform->addElement('editor', 'description_editor',
|
2024-06-02 19:23:40 +02:00
|
|
|
get_string('studyplan_description', 'local_treestudyplan'),
|
|
|
|
null,
|
2023-10-20 14:03:13 +02:00
|
|
|
$customdata->editoroptions);
|
|
|
|
$mform->setType('description_editor', PARAM_RAW);
|
2023-10-18 08:46:44 +02:00
|
|
|
}
|
2023-10-19 17:35:51 +02:00
|
|
|
|
2024-06-02 19:23:40 +02:00
|
|
|
/**
|
2023-10-20 14:03:13 +02:00
|
|
|
* Process the submitted data and perform necessary actions
|
|
|
|
* @param object $entry The processed form data;
|
2023-10-21 23:24:25 +02:00
|
|
|
* @return bool false if submission not successful
|
2023-10-19 17:35:51 +02:00
|
|
|
* @throws \moodle_exception if an error must be given for a specific reason.
|
|
|
|
*/
|
2023-10-20 14:03:13 +02:00
|
|
|
protected function process_submitted_data($entry) {
|
|
|
|
$customdata = (object)$this->_customdata;
|
|
|
|
|
2023-10-23 21:54:09 +02:00
|
|
|
// Add aggregation configs to entry.
|
2024-06-02 23:23:32 +02:00
|
|
|
// Retrieve default config string from selected aggregation method.
|
|
|
|
$agcfg = json_decode(aggregator::create($entry->aggregation, "")->config_string(), true);
|
2024-06-02 19:23:40 +02:00
|
|
|
foreach ($agcfg as $key => $val) {
|
2023-10-23 21:54:09 +02:00
|
|
|
$entrykey = $entry->aggregation."_".$key;
|
2024-06-02 19:23:40 +02:00
|
|
|
$agcfg[$key] = $entry->$entrykey;
|
2023-10-23 21:54:09 +02:00
|
|
|
}
|
2024-06-02 19:23:40 +02:00
|
|
|
$aggregationconfig = json_encode($agcfg);
|
2023-10-23 21:54:09 +02:00
|
|
|
|
2024-04-19 16:46:30 +02:00
|
|
|
if ($customdata->create) {
|
2023-10-23 21:54:09 +02:00
|
|
|
|
2024-06-02 23:23:32 +02:00
|
|
|
// Use our own abstraction to create the record, so caches are maintained.
|
2023-10-23 21:54:09 +02:00
|
|
|
$plan = studyplan::add(['name' => $entry->name,
|
|
|
|
'shortname' => $entry->shortname,
|
|
|
|
'idnumber' => $entry->idnumber,
|
2023-12-12 23:44:02 +01:00
|
|
|
'context_id' => $entry->context_id,
|
2023-10-23 21:54:09 +02:00
|
|
|
'aggregation' => $entry->aggregation,
|
2024-06-02 19:23:40 +02:00
|
|
|
'aggregation_config' => $aggregationconfig,
|
|
|
|
'startdate' => date("Y-m-d", $entry->startdate),
|
|
|
|
'enddate' => date("Y-m-d", $entry->enddate),
|
2023-10-23 21:54:09 +02:00
|
|
|
'periods' => $entry->periods,
|
|
|
|
]);
|
2024-06-02 23:23:32 +02:00
|
|
|
// Process the provided files in the description editor.
|
2023-10-23 21:54:09 +02:00
|
|
|
$entry = file_postupdate_standard_editor($entry,
|
|
|
|
'description',
|
|
|
|
$customdata->editoroptions,
|
|
|
|
\context_system::instance(),
|
|
|
|
'local_treestudyplan',
|
|
|
|
'studyplan',
|
2024-06-02 19:23:40 +02:00
|
|
|
$plan->id());
|
2024-06-02 23:23:32 +02:00
|
|
|
// Update the description.
|
2023-10-23 21:54:09 +02:00
|
|
|
$plan->edit([
|
|
|
|
'description' => $entry->description,
|
|
|
|
'descriptionformat' => $entry->descriptionformat,
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
$plan = $customdata->plan;
|
2024-06-02 19:23:40 +02:00
|
|
|
|
2024-06-02 23:23:32 +02:00
|
|
|
// Process the provided files in the description editor.
|
2023-10-23 21:54:09 +02:00
|
|
|
$entry = file_postupdate_standard_editor($entry,
|
|
|
|
'description',
|
|
|
|
$customdata->editoroptions,
|
|
|
|
\context_system::instance(),
|
|
|
|
'local_treestudyplan',
|
|
|
|
'studyplan',
|
|
|
|
$plan->id());
|
|
|
|
|
2024-06-02 23:23:32 +02:00
|
|
|
// Use our own abstraction to update the record, so caches are maintained.
|
2023-10-23 21:54:09 +02:00
|
|
|
$plan->edit(['name' => $entry->name,
|
|
|
|
'shortname' => $entry->shortname,
|
|
|
|
'idnumber' => $entry->idnumber,
|
2023-12-12 23:44:02 +01:00
|
|
|
'context_id' => $entry->context_id,
|
2023-10-23 21:54:09 +02:00
|
|
|
'description' => $entry->description,
|
|
|
|
'descriptionformat' => $entry->descriptionformat,
|
|
|
|
'aggregation' => $entry->aggregation,
|
2024-06-02 19:23:40 +02:00
|
|
|
'aggregation_config' => $aggregationconfig,
|
2024-03-10 15:56:35 +01:00
|
|
|
'suspended' => $entry->suspended,
|
2024-04-19 16:46:30 +02:00
|
|
|
'template' => $entry->template,
|
2023-10-23 21:54:09 +02:00
|
|
|
]);
|
|
|
|
}
|
2023-10-21 23:24:25 +02:00
|
|
|
|
2023-10-23 21:54:09 +02:00
|
|
|
// Now save the icon file in correct part of the File API.
|
|
|
|
file_save_draft_area_files(
|
|
|
|
// The $entry->icon property contains the itemid of the draft file area.
|
|
|
|
$entry->icon,
|
2024-06-02 23:23:32 +02:00
|
|
|
// The combination of contextid / component / filearea / itemid.
|
|
|
|
// Form the virtual bucket that file are stored in.
|
2023-10-23 21:54:09 +02:00
|
|
|
\context_system::instance()->id,
|
|
|
|
'local_treestudyplan',
|
|
|
|
'icon',
|
|
|
|
$plan->id(),
|
|
|
|
$customdata->fileoptions
|
|
|
|
);
|
2023-11-05 15:49:32 +01:00
|
|
|
|
|
|
|
/* Return the simple model of the plan to make sure we can update stuff.
|
|
|
|
Parse it through the clean_returnvalue function of exernal api (of which studyplanservice is a subclass)
|
2024-06-02 19:23:40 +02:00
|
|
|
so we return it in a consistent way
|
2023-11-05 15:49:32 +01:00
|
|
|
*/
|
2024-06-02 19:23:40 +02:00
|
|
|
$response = studyplanservice::clean_returnvalue(studyplan::simple_structure(), $plan->simple_model());
|
2024-05-10 15:22:52 +02:00
|
|
|
debug::dump($response);
|
|
|
|
return $response;
|
2023-10-19 17:35:51 +02:00
|
|
|
}
|
2024-06-02 23:23:32 +02:00
|
|
|
}
|