Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.
   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * List plans derived from the template.
  19   *
  20   * @package    tool_lp
  21   * @copyright  2015 Frédéric Massart - FMCorz.net
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require(__DIR__ . '/../../../config.php');
  26  
  27  $id = required_param('id', PARAM_INT);
  28  $pagecontextid = required_param('pagecontextid', PARAM_INT);  // Reference to the context we came from.
  29  
  30  require_login(0, false);
  31  \core_competency\api::require_enabled();
  32  
  33  $template = \core_competency\api::read_template($id);
  34  $context = $template->get_context();
  35  $canreadtemplate = $template->can_read();
  36  $canmanagetemplate = $template->can_manage();
  37  if (!$canreadtemplate) {
  38      throw new required_capability_exception($context, 'moodle/competency:templateview', 'nopermissions', '');
  39  }
  40  
  41  // Set up the page.
  42  $url = new moodle_url('/admin/tool/lp/template_plans.php', array(
  43      'id' => $id,
  44      'pagecontextid' => $pagecontextid
  45  ));
  46  list($title, $subtitle) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, $template,
  47      get_string('userplans', 'core_competency'));
  48  
  49  // Capture the form submission.
  50  $form = new \tool_lp\form\template_plans($url->out(false));
  51  if ($canmanagetemplate && ($data = $form->get_data()) && !empty($data->users)) {
  52      $i = 0;
  53      foreach ($data->users as $userid) {
  54          $result = \core_competency\api::create_plan_from_template($template->get('id'), $userid);
  55          if ($result) {
  56              $i++;
  57          }
  58      }
  59      if ($i == 0) {
  60          $notification = get_string('noplanswerecreated', 'tool_lp');
  61      } else if ($i == 1) {
  62          $notification = get_string('oneplanwascreated', 'tool_lp');
  63      } else {
  64          $notification = get_string('aplanswerecreated', 'tool_lp', $i);
  65      }
  66      redirect($url, $notification);
  67  }
  68  
  69  // Display the page.
  70  $output = $PAGE->get_renderer('tool_lp');
  71  echo $output->header();
  72  echo $output->heading($title);
  73  echo $output->heading($subtitle, 3);
  74  
  75  // Do not display form when the template is hidden.
  76  if ($canmanagetemplate) {
  77      if (!$template->get('visible')) {
  78          // Display message that plan can not be created if the template is hidden.
  79          echo $output->notify_message(get_string('cannotcreateuserplanswhentemplatehidden', 'tool_lp'));
  80      } else if ($template->get('duedate') > 0 && $template->get('duedate') < time() + 900) {
  81          // Prevent the user from creating plans when the due date is passed, or in less than 15 minutes.
  82          echo $output->notify_message(get_string('cannotcreateuserplanswhentemplateduedateispassed', 'tool_lp'));
  83      } else {
  84          echo $form->display();
  85      }
  86  }
  87  
  88  $page = new \tool_lp\output\template_plans_page($template, $url);
  89  echo $output->render($page);
  90  echo $output->footer();