[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/tool/lp/classes/output/ -> user_competency_course_navigation.php (source)

   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   * User competency page class.
  19   *
  20   * @package    tool_lp
  21   * @copyright  2015 Damyon Wiese
  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 renderer_base;
  28  use templatable;
  29  use context_course;
  30  use \core_competency\external\competency_exporter;
  31  use \core_competency\external\user_summary_exporter;
  32  use stdClass;
  33  
  34  /**
  35   * User competency course navigation class.
  36   *
  37   * @package    tool_lp
  38   * @copyright  2015 Damyon Wiese
  39   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  40   */
  41  class user_competency_course_navigation implements renderable, templatable {
  42  
  43      /** @var userid */
  44      protected $userid;
  45  
  46      /** @var competencyid */
  47      protected $competencyid;
  48  
  49      /** @var courseid */
  50      protected $courseid;
  51  
  52      /** @var baseurl */
  53      protected $baseurl;
  54  
  55      /**
  56       * Construct.
  57       *
  58       * @param int $userid
  59       * @param int $competencyid
  60       * @param int $courseid
  61       * @param string $baseurl
  62       */
  63      public function __construct($userid, $competencyid, $courseid, $baseurl) {
  64          $this->userid = $userid;
  65          $this->competencyid = $competencyid;
  66          $this->courseid = $courseid;
  67          $this->baseurl = $baseurl;
  68      }
  69  
  70      /**
  71       * Export the data.
  72       *
  73       * @param renderer_base $output
  74       * @return stdClass
  75       */
  76      public function export_for_template(renderer_base $output) {
  77          global $CFG, $DB, $PAGE;
  78  
  79          $context = context_course::instance($this->courseid);
  80  
  81          $data = new stdClass();
  82          $data->userid = $this->userid;
  83          $data->competencyid = $this->competencyid;
  84          $data->courseid = $this->courseid;
  85          $data->baseurl = $this->baseurl;
  86          $data->groupselector = '';
  87  
  88          if (has_any_capability(array('moodle/competency:usercompetencyview', 'moodle/competency:coursecompetencymanage'),
  89                  $context)) {
  90              $course = $DB->get_record('course', array('id' => $this->courseid));
  91              $currentgroup = groups_get_course_group($course, true);
  92              if ($currentgroup !== false) {
  93                  $select = groups_allgroups_course_menu($course, $PAGE->url, true, $currentgroup);
  94                  $data->groupselector = $select;
  95              }
  96              // Fetch showactive.
  97              $defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
  98              $showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
  99              $showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context);
 100  
 101              $users = get_enrolled_users($context, 'moodle/competency:coursecompetencygradable', $currentgroup,
 102                                          'u.*', null, 0, 0, $showonlyactiveenrol);
 103  
 104              $data->users = array();
 105              foreach ($users as $user) {
 106                  $exporter = new user_summary_exporter($user);
 107                  $user = $exporter->export($output);
 108                  if ($user->id == $this->userid) {
 109                      $user->selected = true;
 110                  }
 111                  $data->users[] = $user;
 112              }
 113              $data->hasusers = true;
 114          } else {
 115              $data->users = array();
 116              $data->hasusers = false;
 117          }
 118  
 119          $coursecompetencies = \core_competency\api::list_course_competencies($this->courseid);
 120          $data->competencies = array();
 121          $contextcache = array();
 122          foreach ($coursecompetencies as $coursecompetency) {
 123              $frameworkid = $coursecompetency['competency']->get_competencyframeworkid();
 124              if (!isset($contextcache[$frameworkid])) {
 125                  $contextcache[$frameworkid] = $coursecompetency['competency']->get_context();
 126              }
 127              $context = $contextcache[$frameworkid];
 128              $coursecompetencycontext = $context;
 129              $exporter = new competency_exporter($coursecompetency['competency'], array('context' => $coursecompetencycontext));
 130              $competency = $exporter->export($output);
 131              if ($competency->id == $this->competencyid) {
 132                  $competency->selected = true;
 133              }
 134              $data->competencies[] = $competency;
 135          }
 136          $data->hascompetencies = count($data->competencies);
 137          return $data;
 138      }
 139  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1