function user_can_edit() { // Don't allow people to edit the block if they can't even use it if (!has_capability('moodle/community:add', context::instance_by_id($this->instance->parentcontextid))) { return false; } return parent::user_can_edit(); }
/** * Code executed after a course is restored with this block present in the restore data. Allows for setting the new course * section ID for the restored course as part of this block's instance configuration. * * @return bool Status indicator */ public function after_restore() { // Get the correct course_sections record ID for the new course $section = $DB->get_record('course_sections', 'course', $this->instance->pageid, 'section', $this->config->section); if (!empty($section->id)) { $this->config->section_id = $section->id; parent::instance_config_commit(); } return true; }
/** * Save config instance data * * @param $data * @param $pinned */ function instance_config_save($data, $pinned = false) { $newdata = new stdClass(); $newdata->reports = array(); foreach ($data as $key => $value) { if (strcmp($key, 'report_' . $value) == 0) { // make the requested reports into an array $report = new stdClass(); $report->id = $value; $report->params = array(); $newdata->reports[$value] = $report; } else { $newdata->{$key} = $value; } } return parent::instance_config_save($newdata, $pinned); }