Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.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   * Page listing the evidence of prior learning of a user.
  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  namespace tool_lp\output;
  25  
  26  use renderable;
  27  use templatable;
  28  use renderer_base;
  29  use stdClass;
  30  use single_button;
  31  use moodle_url;
  32  use core_competency\api;
  33  use tool_lp\external\user_evidence_summary_exporter;
  34  use core_competency\user_evidence;
  35  use context_user;
  36  
  37  /**
  38   * Class for the page listing the evidence of prior learning of a user.
  39   *
  40   * @package    tool_lp
  41   * @copyright  2015 Frédéric Massart - FMCorz.net
  42   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  43   */
  44  class user_evidence_list_page implements renderable, templatable {
  45  
  46      /** @var array $navigation List of links to display on the page. Each link contains a url and a title. */
  47      protected $navigation = array();
  48  
  49      /** @var tool_lp\user_evidence[] $evidence List of user evidence. */
  50      protected $evidence = array();
  51  
  52      /** @var context_user|null $context context.  */
  53      protected $context = null;
  54  
  55      /** @var int|null $userid Userid. */
  56      protected $userid = null;
  57  
  58      /** @var bool Can the user manage the evidence. */
  59      protected $canmanage;
  60  
  61      /**
  62       * Construct this renderable.
  63       *
  64       * @param int $userid
  65       */
  66      public function __construct($userid) {
  67          $this->userid = $userid;
  68          $this->context = context_user::instance($userid);
  69          $this->evidence = api::list_user_evidence($userid);
  70          $this->canmanage = user_evidence::can_manage_user($this->userid);
  71  
  72          if ($this->canmanage) {
  73              $addevidence = new single_button(
  74                 new moodle_url('/admin/tool/lp/user_evidence_edit.php', array('userid' => $userid)),
  75                 get_string('addnewuserevidence', 'tool_lp'), 'get'
  76              );
  77              $this->navigation[] = $addevidence;
  78          }
  79      }
  80  
  81      /**
  82       * Export this data so it can be used as the context for a mustache template.
  83       *
  84       * @param renderer_base $output
  85       * @return stdClass
  86       */
  87      public function export_for_template(renderer_base $output) {
  88          $data = new stdClass();
  89          $data->userid = $this->userid;
  90          $data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
  91          $data->canmanage = $this->canmanage;
  92  
  93          $data->evidence = array();
  94          if ($this->evidence) {
  95              foreach ($this->evidence as $evidence) {
  96                  $userevidencesummaryexporter = new user_evidence_summary_exporter($evidence, array(
  97                      'context' => $this->context
  98                  ));
  99                  $data->evidence[] = $userevidencesummaryexporter->export($output);
 100              }
 101          }
 102  
 103          $data->navigation = array();
 104          foreach ($this->navigation as $button) {
 105              $data->navigation[] = $output->render($button);
 106          }
 107  
 108          return $data;
 109      }
 110  }