Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are 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 user evidence with all competencies.
  19   *
  20   * @package    tool_lp
  21   * @copyright  2016 Serge Gauthier - <serge.gauthier.2@umontreal.ca>
  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 moodle_url;
  28  use renderer_base;
  29  use core_files\external\stored_file_exporter;
  30  use core_competency\external\performance_helper;
  31  
  32  /**
  33   * Class for exporting user evidence with all competencies.
  34   *
  35   * @copyright  2016 Serge Gauthier - <serge.gauthier.2@umontreal.ca>
  36   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class user_evidence_summary_exporter extends \core\external\persistent_exporter {
  39  
  40      protected static function define_class() {
  41          return \core_competency\user_evidence::class;
  42      }
  43  
  44      protected static function define_other_properties() {
  45          return array(
  46              'canmanage' => array(
  47                  'type' => PARAM_BOOL
  48              ),
  49              'filecount' => array(
  50                  'type' => PARAM_INT
  51              ),
  52              'files' => array(
  53                  'type' => stored_file_exporter::read_properties_definition(),
  54                  'multiple' => true
  55              ),
  56              'hasurlorfiles' => array(
  57                  'type' => PARAM_BOOL
  58              ),
  59              'urlshort' => array(
  60                  'type' => PARAM_TEXT
  61              ),
  62              'competencycount' => array(
  63                  'type' => PARAM_INT
  64              ),
  65              'usercompetencies' => array(
  66                  'type' => user_evidence_competency_summary_exporter::read_properties_definition(),
  67                  'optional' => true,
  68                  'multiple' => true
  69              ),
  70              'userhasplan' => array(
  71                  'type' => PARAM_BOOL
  72              ),
  73          );
  74      }
  75  
  76      protected function get_other_values(renderer_base $output) {
  77          $urlshort = '';
  78          $url = $this->persistent->get('url');
  79          if (!empty($url)) {
  80              $murl = new moodle_url($url);
  81              $shorturl = preg_replace('@^https?://(www\.)?@', '', $murl->out(false));
  82              $urlshort = shorten_text($shorturl, 30, true);
  83          }
  84  
  85          $files = array();
  86          $storedfiles = $this->persistent->get_files();
  87          if (!empty($storedfiles)) {
  88              foreach ($storedfiles as $storedfile) {
  89                  $fileexporter = new stored_file_exporter($storedfile, array('context' => $this->related['context']));
  90                  $files[] = $fileexporter->export($output);
  91              }
  92          }
  93  
  94          $userevidencecompetencies = array();
  95          $usercompetencies = $this->persistent->get_user_competencies();
  96          $helper = new performance_helper();
  97          foreach ($usercompetencies as $usercompetency) {
  98              $competency = $usercompetency->get_competency();
  99  
 100              $context = $helper->get_context_from_competency($competency);
 101              $framework = $helper->get_framework_from_competency($competency);
 102              $scale = $helper->get_scale_from_competency($competency);
 103  
 104              $related = array('competency' => $competency,
 105                               'usercompetency' => $usercompetency,
 106                               'scale' => $scale,
 107                               'context' => $context);
 108  
 109              $userevidencecompetencysummaryexporter = new user_evidence_competency_summary_exporter(null, $related);
 110  
 111              $userevidencecompetencies[] = $userevidencecompetencysummaryexporter->export($output);
 112          }
 113  
 114          $values = array(
 115              'canmanage' => $this->persistent->can_manage(),
 116              'filecount' => count($files),
 117              'files' => $files,
 118              'userhasplan' => $this->persistent->user_has_plan(),
 119              'hasurlorfiles' => !empty($files) || !empty($url),
 120              'urlshort' => $urlshort,
 121              'competencycount' => count($userevidencecompetencies),
 122              'usercompetencies' => $userevidencecompetencies
 123          );
 124  
 125          return $values;
 126      }
 127  
 128  }