[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/tool/lp/classes/external/ -> user_competency_summary_in_course_exporter.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 for exporting user competency data with all the evidence in a course
  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\external;
  25  
  26  use core_competency\api;
  27  use core_competency\user_competency;
  28  use context_course;
  29  use renderer_base;
  30  use stdClass;
  31  
  32  /**
  33   * Class for exporting user competency data with additional related data in a plan.
  34   *
  35   * @copyright  2015 Damyon Wiese
  36   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class user_competency_summary_in_course_exporter extends \core_competency\external\exporter {
  39  
  40      protected static function define_related() {
  41          // We cache the context so it does not need to be retrieved from the framework every time.
  42          return array('competency' => '\\core_competency\\competency',
  43                       'relatedcompetencies' => '\\core_competency\\competency[]',
  44                       'user' => '\\stdClass',
  45                       'course' => '\\stdClass',
  46                       'usercompetencycourse' => '\\core_competency\\user_competency_course?',
  47                       'evidence' => '\\core_competency\\evidence[]',
  48                       'scale' => '\\grade_scale');
  49      }
  50  
  51      protected static function define_other_properties() {
  52          return array(
  53              'usercompetencysummary' => array(
  54                  'type' => user_competency_summary_exporter::read_properties_definition()
  55              ),
  56              'course' => array(
  57                  'type' => course_summary_exporter::read_properties_definition(),
  58              ),
  59              'coursemodules' => array(
  60                  'type' => course_module_summary_exporter::read_properties_definition(),
  61                  'multiple' => true
  62              )
  63          );
  64      }
  65  
  66      protected function get_other_values(renderer_base $output) {
  67          // Arrays are copy on assign.
  68          $related = $this->related;
  69          $result = new stdClass();
  70          // Remove course from related as it is not wanted by the user_competency_summary_exporter.
  71          unset($related['course']);
  72          $related['usercompetencyplan'] = null;
  73          $related['usercompetency'] = null;
  74          $exporter = new user_competency_summary_exporter(null, $related);
  75          $result->usercompetencysummary = $exporter->export($output);
  76          $result->usercompetencysummary->cangrade = user_competency::can_grade_user_in_course($this->related['user']->id,
  77              $this->related['course']->id);
  78  
  79          $context = context_course::instance($this->related['course']->id);
  80          $exporter = new course_summary_exporter($this->related['course'], array('context' => $context));
  81          $result->course = $exporter->export($output);
  82  
  83          $coursemodules = api::list_course_modules_using_competency($this->related['competency']->get_id(),
  84                                                                     $this->related['course']->id);
  85  
  86          $fastmodinfo = get_fast_modinfo($this->related['course']->id);
  87          $exportedmodules = array();
  88          foreach ($coursemodules as $cm) {
  89              $cminfo = $fastmodinfo->cms[$cm];
  90              $cmexporter = new course_module_summary_exporter(null, array('cm' => $cminfo));
  91              $exportedmodules[] = $cmexporter->export($output);
  92          }
  93          $result->coursemodules = $exportedmodules;
  94  
  95          return (array) $result;
  96      }
  97  }


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