Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.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   * Class for exporting a template statistics summary.
  19   *
  20   * @package    tool_lp
  21   * @copyright  2016 Damyon Wiese
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace tool_lp\external;
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  use renderer_base;
  28  use moodle_url;
  29  use core_competency\external\competency_exporter;
  30  use core_competency\external\performance_helper;
  31  
  32  /**
  33   * Class for exporting a cohort summary from an stdClass.
  34   *
  35   * @copyright  2015 Damyon Wiese
  36   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class template_statistics_exporter extends \core\external\exporter {
  39  
  40      public static function define_properties() {
  41          return array(
  42              'competencycount' => array(
  43                  'type' => PARAM_INT,
  44              ),
  45              'unlinkedcompetencycount' => array(
  46                  'type' => PARAM_INT,
  47              ),
  48              'plancount' => array(
  49                  'type' => PARAM_INT,
  50              ),
  51              'completedplancount' => array(
  52                  'type' => PARAM_INT,
  53              ),
  54              'usercompetencyplancount' => array(
  55                  'type' => PARAM_INT,
  56              ),
  57              'proficientusercompetencyplancount' => array(
  58                  'type' => PARAM_INT,
  59              )
  60          );
  61      }
  62  
  63      public static function define_other_properties() {
  64          return array(
  65              'linkedcompetencypercentage' => array(
  66                  'type' => PARAM_FLOAT
  67              ),
  68              'linkedcompetencypercentageformatted' => array(
  69                  'type' => PARAM_RAW
  70              ),
  71              'linkedcompetencycount' => array(
  72                  'type' => PARAM_INT
  73              ),
  74              'completedplanpercentage' => array(
  75                  'type' => PARAM_FLOAT
  76              ),
  77              'completedplanpercentageformatted' => array(
  78                  'type' => PARAM_RAW
  79              ),
  80              'proficientusercompetencyplanpercentage' => array(
  81                  'type' => PARAM_FLOAT
  82              ),
  83              'proficientusercompetencyplanpercentageformatted' => array(
  84                  'type' => PARAM_RAW
  85              ),
  86              'leastproficient' => array(
  87                  'type' => competency_exporter::read_properties_definition(),
  88                  'multiple' => true
  89              ),
  90              'leastproficientcount' => array(
  91                  'type' => PARAM_INT
  92              ),
  93          );
  94      }
  95  
  96      protected function get_other_values(renderer_base $output) {
  97          $linkedcompetencycount = $this->data->competencycount - $this->data->unlinkedcompetencycount;
  98          if ($linkedcompetencycount < 0) {
  99              // Should never happen.
 100              $linkedcompetencycount = 0;
 101          }
 102          $linkedcompetencypercentage = 0;
 103          $linkedcompetencypercentageformatted = '';
 104          if ($this->data->competencycount > 0) {
 105              $linkedcompetencypercentage = ((float) $linkedcompetencycount / (float) $this->data->competencycount) * 100.0;
 106              $linkedcompetencypercentageformatted = format_float($linkedcompetencypercentage);
 107          }
 108          $completedplanpercentage = 0;
 109          $completedplanpercentageformatted = '';
 110          if ($this->data->plancount > 0) {
 111              $completedplanpercentage = ((float) $this->data->completedplancount / (float) $this->data->plancount) * 100.0;
 112              $completedplanpercentageformatted = format_float($completedplanpercentage);
 113          }
 114          $proficientusercompetencyplanpercentage = 0;
 115          $proficientusercompetencyplanpercentageformatted = '';
 116          if ($this->data->usercompetencyplancount > 0) {
 117              $proficientusercompetencyplanpercentage = ((float) $this->data->proficientusercompetencyplancount
 118                      / (float) $this->data->usercompetencyplancount) * 100.0;
 119              $proficientusercompetencyplanpercentageformatted = format_float($proficientusercompetencyplanpercentage);
 120          }
 121          $competencies = array();
 122          $helper = new performance_helper();
 123          foreach ($this->data->leastproficientcompetencies as $competency) {
 124              $context = $helper->get_context_from_competency($competency);
 125              $exporter = new competency_exporter($competency, array('context' => $context));
 126              $competencies[] = $exporter->export($output);
 127          }
 128          return array(
 129              'linkedcompetencycount' => $linkedcompetencycount,
 130              'linkedcompetencypercentage' => $linkedcompetencypercentage,
 131              'linkedcompetencypercentageformatted' => $linkedcompetencypercentageformatted,
 132              'completedplanpercentage' => $completedplanpercentage,
 133              'completedplanpercentageformatted' => $completedplanpercentageformatted,
 134              'proficientusercompetencyplanpercentage' => $proficientusercompetencyplanpercentage,
 135              'proficientusercompetencyplanpercentageformatted' => $proficientusercompetencyplanpercentageformatted,
 136              'leastproficient' => $competencies,
 137              'leastproficientcount' => count($competencies)
 138          );
 139      }
 140  }