/** * Sets up the table. * * @param string $uniqueid Unique id of table. * @param \core_competency\template $template The template. */ public function __construct($uniqueid, \core_competency\template $template) { parent::__construct($uniqueid); // This object should not be used without the right permissions. if (!$template->can_read()) { throw new \required_capability_exception($template->get_context(), 'moodle/competency:templateview', 'nopermissions', ''); } // Set protected properties. $this->template = $template; $this->context = $this->template->get_context(); // Define columns in the table. $this->define_table_columns(); // Define configs. $this->define_table_configs(); }
/** * Template event viewed. * * Requires moodle/competency:templateview capability at the system context. * * @param mixed $templateorid The id or the template. * @return boolean */ public static function template_viewed($templateorid) { static::require_enabled(); $template = $templateorid; if (!is_object($template)) { $template = new template($template); } // First we do a permissions check. if (!$template->can_read()) { throw new required_capability_exception($template->get_context(), 'moodle/competency:templateview', 'nopermissions', ''); } // Trigger a template viewed event. \core\event\competency_template_viewed::create_from_template($template)->trigger(); return true; }
/** * Set-up a template page. * * Example: * list($title, $subtitle) = page_helper::setup_for_template($pagecontextid, $url, $template, $pagetitle); * echo $OUTPUT->heading($title); * echo $OUTPUT->heading($subtitle, 3); * * @param int $pagecontextid The page context ID. * @param moodle_url $url The current page. * @param \core_competency\template $template The template, if any. * @param string $subtitle The title of the subpage, if any. * @param string $returntype The desired return page. * @return array With the following: * - Page title * - Page sub title * - Return URL */ public static function setup_for_template($pagecontextid, moodle_url $url, $template = null, $subtitle = '', $returntype = null) { global $PAGE, $SITE; $pagecontext = context::instance_by_id($pagecontextid); $context = $pagecontext; if (!empty($template)) { $context = $template->get_context(); } $templatesurl = new moodle_url('/admin/tool/lp/learningplans.php', array('pagecontextid' => $pagecontextid)); $templateurl = null; if ($template) { $templateurl = new moodle_url('/admin/tool/lp/templatecompetencies.php', ['templateid' => $template->get_id(), 'pagecontextid' => $pagecontextid]); } $returnurl = $templatesurl; if ($returntype != 'templates' && $templateurl) { $returnurl = $templateurl; } $PAGE->navigation->override_active_url($templatesurl); $PAGE->set_context($pagecontext); if (!empty($template)) { $title = format_string($template->get_shortname(), true, array('context' => $context)); } else { $title = get_string('templates', 'tool_lp'); } if ($pagecontext->contextlevel == CONTEXT_SYSTEM) { $heading = $SITE->fullname; } else { if ($pagecontext->contextlevel == CONTEXT_COURSECAT) { $heading = $pagecontext->get_context_name(); } else { throw new coding_exception('Unexpected context!'); } } $PAGE->set_pagelayout('admin'); $PAGE->set_url($url); $PAGE->set_title($title); $PAGE->set_heading($heading); if (!empty($template)) { $PAGE->navbar->add($title, $templateurl); if (!empty($subtitle)) { $PAGE->navbar->add($subtitle, $url); } } else { if (!empty($subtitle)) { // We're in a sub page without a specific template. $PAGE->navbar->add($subtitle, $url); } } return array($title, $subtitle, $returnurl); }