From 48a75249b9a97f41187093de2b59b09ba0f48154 Mon Sep 17 00:00:00 2001 From: Matthias Opitz Date: Mon, 27 Mar 2023 16:42:01 +0100 Subject: [PATCH] allowing to edit activity names with correct access rights --- form.php | 7 +++++++ index.php | 19 +++++++++++++++++-- lang/en/report_editdates.php | 1 + 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/form.php b/form.php index aa6a258..ec8ac8e 100644 --- a/form.php +++ b/form.php @@ -184,6 +184,13 @@ public function definition() { mt_rand( 0, 255 ) . ', .5)' ); + // Add a textbox for editing the activity name. + $elname = 'name_' . $cm->modname . '_' . $cm->id; + $mform->addElement('text', $elname, get_string('activityname', 'report_editdates'), + array('size'=>'64')); + $mform->setType($elname, PARAM_TEXT); + $mform->setDefault($elname, $cm->name); + // Call get_settings method for the acitivity/module. // Get instance of the mod's date exractor class. $mod = report_editdates_mod_date_extractor::make($cm->modname, $course); diff --git a/index.php b/index.php index edef980..56113df 100644 --- a/index.php +++ b/index.php @@ -89,6 +89,9 @@ } else if ($data = $mform->get_data()) { // Process submitted data. + // Start transaction. + $transaction = $DB->start_delegated_transaction(); + $moddatesettings = array(); $blockdatesettings = array(); $sectiondatesettings = array(); @@ -141,11 +144,23 @@ } } } + + // Update activity name. + if (count($cmsettings) == 3 && $cmsettings[0] == 'name') { + $modcontext = context_module::instance($cmsettings[2]); + // User should be capable of updating individual module. + if (has_capability('moodle/course:manageactivities', $modcontext)) { + $cm = $modinfo->get_cm($cmsettings[2]); + $update = new stdClass(); + $update->id = $cm->instance; + $update->name = $value; + $update->timemodified = time(); + $DB->update_record($cmsettings[1], $update); + } + } } } - // Start transaction. - $transaction = $DB->start_delegated_transaction(); // Allow to update only if user is capable. if (has_capability('moodle/course:update', $coursecontext)) { $DB->set_field('course', 'startdate', $course->startdate, array('id' => $course->id)); diff --git a/lang/en/report_editdates.php b/lang/en/report_editdates.php index 8970b88..349e8d5 100644 --- a/lang/en/report_editdates.php +++ b/lang/en/report_editdates.php @@ -56,3 +56,4 @@ $string['editrestrictedaccess'] = 'Edit restricted access (opens a new window)'; $string['event:reportviewed'] = 'Edit dates report viewed'; $string['privacy:metadata'] = 'The Dates plugin does not store any personal data.'; +$string['activityname'] = 'Activity name'; \ No newline at end of file