[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/report/competency/classes/output/ -> report.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   * Class containing data for learning plan template competencies page
  19   *
  20   * @package    report_competency
  21   * @copyright  2015 Damyon Wiese
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace report_competency\output;
  25  
  26  use context_course;
  27  use renderable;
  28  use core_user;
  29  use templatable;
  30  use renderer_base;
  31  use moodle_url;
  32  use stdClass;
  33  use core_competency\api;
  34  use core_competency\external\user_competency_course_exporter;
  35  use core_competency\external\user_summary_exporter;
  36  use core_competency\url;
  37  use core_competency\user_competency;
  38  use tool_lp\external\competency_summary_exporter;
  39  use tool_lp\external\course_summary_exporter;
  40  
  41  /**
  42   * Class containing data for learning plan template competencies page
  43   *
  44   * @copyright  2015 Damyon Wiese
  45   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  46   */
  47  class report implements renderable, templatable {
  48  
  49      /** @var context $context */
  50      protected $context;
  51      /** @var int $courseid */
  52      protected $courseid;
  53      /** @var array $competencies */
  54      protected $competencies;
  55  
  56      /**
  57       * Construct this renderable.
  58       *
  59       * @param int $courseid The course id
  60       * @param int $userid The user id
  61       */
  62      public function __construct($courseid, $userid) {
  63          $this->courseid = $courseid;
  64          $this->userid = $userid;
  65          $this->context = context_course::instance($courseid);
  66      }
  67  
  68      /**
  69       * Export this data so it can be used as the context for a mustache template.
  70       *
  71       * @param \renderer_base $output
  72       * @return stdClass
  73       */
  74      public function export_for_template(renderer_base $output) {
  75          global $DB;
  76  
  77          $data = new stdClass();
  78          $data->courseid = $this->courseid;
  79  
  80          $course = $DB->get_record('course', array('id' => $this->courseid));
  81          $coursecontext = context_course::instance($course->id);
  82          $exporter = new course_summary_exporter($course, array('context' => $coursecontext));
  83          $coursecompetencysettings = api::read_course_competency_settings($course->id);
  84          $data->pushratingstouserplans = $coursecompetencysettings->get_pushratingstouserplans();
  85          $data->course = $exporter->export($output);
  86  
  87          $data->usercompetencies = array();
  88          $scalecache = array();
  89          $frameworkcache = array();
  90  
  91          $user = core_user::get_user($this->userid);
  92  
  93          $exporter = new user_summary_exporter($user);
  94          $data->user = $exporter->export($output);
  95          $data->usercompetencies = array();
  96          $coursecompetencies = api::list_course_competencies($this->courseid);
  97          $usercompetencycourses = api::list_user_competencies_in_course($this->courseid, $user->id);
  98  
  99          foreach ($usercompetencycourses as $usercompetencycourse) {
 100              $onerow = new stdClass();
 101              $competency = null;
 102              foreach ($coursecompetencies as $coursecompetency) {
 103                  if ($coursecompetency['competency']->get_id() == $usercompetencycourse->get_competencyid()) {
 104                      $competency = $coursecompetency['competency'];
 105                      break;
 106                  }
 107              }
 108              if (!$competency) {
 109                  continue;
 110              }
 111              // Fetch the framework.
 112              if (!isset($frameworkcache[$competency->get_competencyframeworkid()])) {
 113                  $frameworkcache[$competency->get_competencyframeworkid()] = $competency->get_framework();
 114              }
 115              $framework = $frameworkcache[$competency->get_competencyframeworkid()];
 116  
 117              // Fetch the scale.
 118              $scaleid = $competency->get_scaleid();
 119              if ($scaleid === null) {
 120                  $scaleid = $framework->get_scaleid();
 121                  if (!isset($scalecache[$scaleid])) {
 122                      $scalecache[$competency->get_scaleid()] = $framework->get_scale();
 123                  }
 124  
 125              } else if (!isset($scalecache[$scaleid])) {
 126                  $scalecache[$competency->get_scaleid()] = $competency->get_scale();
 127              }
 128              $scale = $scalecache[$competency->get_scaleid()];
 129  
 130              $exporter = new user_competency_course_exporter($usercompetencycourse, array('scale' => $scale));
 131              $record = $exporter->export($output);
 132              $onerow->usercompetencycourse = $record;
 133              $exporter = new competency_summary_exporter(null, array(
 134                  'competency' => $competency,
 135                  'framework' => $framework,
 136                  'context' => $framework->get_context(),
 137                  'relatedcompetencies' => array(),
 138                  'linkedcourses' => array()
 139              ));
 140              $onerow->competency = $exporter->export($output);
 141              array_push($data->usercompetencies, $onerow);
 142          }
 143  
 144          return $data;
 145      }
 146  }


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