Exemplo n.º 1
0
 /**
  * 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);
 }
Exemplo n.º 2
0
 /**
  * Duplicate a learning plan template.
  *
  * Requires moodle/competency:templatemanage capability at the template context.
  *
  * @param int $id the template id.
  * @return template
  */
 public static function duplicate_template($id)
 {
     static::require_enabled();
     $template = new template($id);
     // First we do a permissions check.
     if (!$template->can_manage()) {
         throw new required_capability_exception($template->get_context(), 'moodle/competency:templatemanage', 'nopermissions', '');
     }
     // OK - all set.
     $competencies = template_competency::list_competencies($id, false);
     // Adding the suffix copy.
     $template->set_shortname(get_string('duplicateditemname', 'core_competency', $template->get_shortname()));
     $template->set_id(0);
     $duplicatedtemplate = $template->create();
     // Associate each competency for the duplicated template.
     foreach ($competencies as $competency) {
         self::add_competency_to_template($duplicatedtemplate->get_id(), $competency->get_id());
     }
     // Trigger a template created event.
     \core\event\competency_template_created::create_from_template($duplicatedtemplate)->trigger();
     return $duplicatedtemplate;
 }
Exemplo n.º 3
0
 /**
  * Update from template.
  *
  * Bulk update a lot of plans from a template
  *
  * @param  template $template
  * @return bool
  */
 public static function update_multiple_from_template(template $template)
 {
     global $DB;
     if (!$template->is_valid()) {
         // As we will bypass this model's validation we rely on the template being validated.
         throw new \coding_exception('The template must be validated before updating plans.');
     }
     $params = array('templateid' => $template->get_id(), 'status' => self::STATUS_COMPLETE, 'name' => $template->get_shortname(), 'description' => $template->get_description(), 'descriptionformat' => $template->get_descriptionformat(), 'duedate' => $template->get_duedate());
     $sql = "UPDATE {" . self::TABLE . "}\n                   SET name = :name,\n                       description = :description,\n                       descriptionformat = :descriptionformat,\n                       duedate = :duedate\n                 WHERE templateid = :templateid\n                   AND status != :status";
     return $DB->execute($sql, $params);
 }