[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/tool/lp/classes/output/ -> plan_page.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   * Plan page output.
  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  defined('MOODLE_INTERNAL') || die();
  26  
  27  use renderable;
  28  use templatable;
  29  use stdClass;
  30  use moodle_url;
  31  use core_competency\api;
  32  use core_competency\plan;
  33  use core_competency\external\competency_exporter;
  34  use core_competency\external\plan_exporter;
  35  use tool_lp\external\competency_path_exporter;
  36  
  37  /**
  38   * Plan page class.
  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 plan_page implements renderable, templatable {
  45  
  46      /** @var plan */
  47      protected $plan;
  48  
  49      /**
  50       * Construct.
  51       *
  52       * @param plan $plan
  53       */
  54      public function __construct($plan) {
  55          $this->plan = $plan;
  56      }
  57  
  58      /**
  59       * Export the data.
  60       *
  61       * @param renderer_base $output
  62       * @return stdClass
  63       */
  64      public function export_for_template(\renderer_base $output) {
  65          $frameworks = array();
  66          $scales = array();
  67  
  68          $planexporter = new plan_exporter($this->plan, array('template' => $this->plan->get_template()));
  69  
  70          $data = new stdClass();
  71          $data->plan = $planexporter->export($output);
  72          $data->competencies = array();
  73          $data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(false);
  74          $data->contextid = $this->plan->get_context()->id;
  75  
  76          if ($data->plan->iscompleted) {
  77              $ucproperty = 'usercompetencyplan';
  78              $ucexporter = 'core_competency\\external\\user_competency_plan_exporter';
  79          } else {
  80              $ucproperty = 'usercompetency';
  81              $ucexporter = 'core_competency\\external\\user_competency_exporter';
  82          }
  83  
  84          $pclist = api::list_plan_competencies($this->plan);
  85          $proficientcount = 0;
  86          foreach ($pclist as $pc) {
  87              $comp = $pc->competency;
  88              $usercomp = $pc->$ucproperty;
  89  
  90              // Get the framework.
  91              if (!isset($frameworks[$comp->get_competencyframeworkid()])) {
  92                  $frameworks[$comp->get_competencyframeworkid()] = $comp->get_framework();
  93              }
  94              $framework = $frameworks[$comp->get_competencyframeworkid()];
  95  
  96              // Get the scale.
  97              $scaleid = $comp->get_scaleid();
  98              if ($scaleid === null) {
  99                  $scaleid = $framework->get_scaleid();
 100              }
 101              if (!isset($scales[$framework->get_scaleid()])) {
 102                  $scales[$framework->get_scaleid()] = $framework->get_scale();
 103              }
 104              $scale = $scales[$framework->get_scaleid()];
 105  
 106              // Prepare the data.
 107              $record = new stdClass();
 108              $exporter = new competency_exporter($comp, array('context' => $framework->get_context()));
 109              $record->competency = $exporter->export($output);
 110  
 111              // Competency path.
 112              $exporter = new competency_path_exporter([
 113                  'ancestors' => $comp->get_ancestors(),
 114                  'framework' => $framework,
 115                  'context' => $framework->get_context()
 116              ]);
 117              $record->comppath = $exporter->export($output);
 118  
 119              $exporter = new $ucexporter($usercomp, array('scale' => $scale));
 120              $record->$ucproperty = $exporter->export($output);
 121  
 122              $data->competencies[] = $record;
 123              if ($usercomp->get_proficiency()) {
 124                  $proficientcount++;
 125              }
 126          }
 127          $data->competencycount = count($data->competencies);
 128          $data->proficientcompetencycount = $proficientcount;
 129          if ($data->competencycount) {
 130              $data->proficientcompetencypercentage = ((float) $proficientcount / (float) $data->competencycount) * 100.0;
 131          } else {
 132              $data->proficientcompetencypercentage = 0.0;
 133          }
 134          $data->proficientcompetencypercentageformatted = format_float($data->proficientcompetencypercentage);
 135          return $data;
 136      }
 137  }


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