Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing to edit activity names with correct access rights #56

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 17 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions lang/en/report_editdates.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';