See Release Notes
Long Term Support Release
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. 19 * 20 * @package core_competency 21 * @copyright 2015 Damyon Wiese 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 namespace core_competency\external; 25 defined('MOODLE_INTERNAL') || die(); 26 27 use context_system; 28 use core_user; 29 use renderer_base; 30 use stdClass; 31 use core_competency\url; 32 use core_competency\user_competency; 33 use core_user\external\user_summary_exporter; 34 35 /** 36 * Class for exporting user competency data. 37 * 38 * @copyright 2015 Damyon Wiese 39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 40 */ 41 class user_competency_exporter extends \core\external\persistent_exporter { 42 43 protected static function define_class() { 44 return user_competency::class; 45 } 46 47 protected static function define_related() { 48 // We cache the scale so it does not need to be retrieved from the framework every time. 49 return array('scale' => 'grade_scale'); 50 } 51 52 protected function get_other_values(renderer_base $output) { 53 $result = new stdClass(); 54 55 if ($this->persistent->get('grade') === null) { 56 $gradename = '-'; 57 } else { 58 $gradename = $this->related['scale']->scale_items[$this->persistent->get('grade') - 1]; 59 } 60 $result->gradename = $gradename; 61 62 if ($this->persistent->get('proficiency') === null) { 63 $proficiencyname = get_string('no'); 64 } else { 65 $proficiencyname = get_string($this->persistent->get('proficiency') ? 'yes' : 'no'); 66 } 67 $result->proficiencyname = $proficiencyname; 68 69 $statusname = '-'; 70 if ($this->persistent->get('status') != user_competency::STATUS_IDLE) { 71 $statusname = (string) user_competency::get_status_name($this->persistent->get('status')); 72 } 73 $result->statusname = $statusname; 74 75 $result->canrequestreview = $this->persistent->can_request_review(); 76 $result->canreview = $this->persistent->can_review(); 77 78 $result->isstatusidle = $this->persistent->get('status') == user_competency::STATUS_IDLE; 79 $result->isstatusinreview = $this->persistent->get('status') == user_competency::STATUS_IN_REVIEW; 80 $result->isstatuswaitingforreview = $this->persistent->get('status') == user_competency::STATUS_WAITING_FOR_REVIEW; 81 82 $result->isrequestreviewallowed = $result->canrequestreview && $result->isstatusidle; 83 $result->iscancelreviewrequestallowed = $result->canrequestreview && $result->isstatuswaitingforreview; 84 $result->isstartreviewallowed = $result->canreview && $result->isstatuswaitingforreview; 85 $result->isstopreviewallowed = $result->canreview && $result->isstatusinreview; 86 87 if (!empty($result->isstatusinreview)) { 88 // TODO Make this more efficient. 89 $userexporter = new user_summary_exporter(core_user::get_user($this->persistent->get('reviewerid'), '*', MUST_EXIST)); 90 $result->reviewer = $userexporter->export($output); 91 } 92 93 $result->url = url::user_competency($this->persistent->get('id'))->out(false); 94 95 return (array) $result; 96 } 97 98 /** 99 * Get the format parameters for gradename. 100 * 101 * @return array 102 */ 103 protected function get_format_parameters_for_gradename() { 104 return [ 105 'context' => context_system::instance(), // The system context is cached, so we can get it right away. 106 ]; 107 } 108 109 protected static function define_other_properties() { 110 return array( 111 'canrequestreview' => array( 112 'type' => PARAM_BOOL, 113 ), 114 'canreview' => array( 115 'type' => PARAM_BOOL, 116 ), 117 'gradename' => array( 118 'type' => PARAM_TEXT 119 ), 120 'isrequestreviewallowed' => array( 121 'type' => PARAM_BOOL, 122 ), 123 'iscancelreviewrequestallowed' => array( 124 'type' => PARAM_BOOL, 125 ), 126 'isstartreviewallowed' => array( 127 'type' => PARAM_BOOL, 128 ), 129 'isstopreviewallowed' => array( 130 'type' => PARAM_BOOL, 131 ), 132 'isstatusidle' => array( 133 'type' => PARAM_BOOL, 134 ), 135 'isstatusinreview' => array( 136 'type' => PARAM_BOOL, 137 ), 138 'isstatuswaitingforreview' => array( 139 'type' => PARAM_BOOL, 140 ), 141 'proficiencyname' => array( 142 'type' => PARAM_RAW 143 ), 144 'reviewer' => array( 145 'type' => user_summary_exporter::read_properties_definition(), 146 'optional' => true 147 ), 148 'statusname' => array( 149 'type' => PARAM_RAW 150 ), 151 'url' => array( 152 'type' => PARAM_URL 153 ), 154 ); 155 } 156 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body