[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 core_user; 28 use renderer_base; 29 use stdClass; 30 use core_competency\url; 31 use core_competency\user_competency; 32 33 /** 34 * Class for exporting user competency data. 35 * 36 * @copyright 2015 Damyon Wiese 37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 38 */ 39 class user_competency_exporter extends persistent_exporter { 40 41 protected static function define_class() { 42 return 'core_competency\\user_competency'; 43 } 44 45 protected static function define_related() { 46 // We cache the scale so it does not need to be retrieved from the framework every time. 47 return array('scale' => 'grade_scale'); 48 } 49 50 protected function get_other_values(renderer_base $output) { 51 $result = new stdClass(); 52 53 if ($this->persistent->get_grade() === null) { 54 $gradename = '-'; 55 } else { 56 $gradename = $this->related['scale']->scale_items[$this->persistent->get_grade() - 1]; 57 } 58 $result->gradename = $gradename; 59 60 if ($this->persistent->get_proficiency() === null) { 61 $proficiencyname = get_string('no'); 62 } else { 63 $proficiencyname = get_string($this->persistent->get_proficiency() ? 'yes' : 'no'); 64 } 65 $result->proficiencyname = $proficiencyname; 66 67 $statusname = '-'; 68 if ($this->persistent->get_status() != user_competency::STATUS_IDLE) { 69 $statusname = (string) user_competency::get_status_name($this->persistent->get_status()); 70 } 71 $result->statusname = $statusname; 72 73 $result->canrequestreview = $this->persistent->can_request_review(); 74 $result->canreview = $this->persistent->can_review(); 75 76 $result->isstatusidle = $this->persistent->get_status() == user_competency::STATUS_IDLE; 77 $result->isstatusinreview = $this->persistent->get_status() == user_competency::STATUS_IN_REVIEW; 78 $result->isstatuswaitingforreview = $this->persistent->get_status() == user_competency::STATUS_WAITING_FOR_REVIEW; 79 80 $result->isrequestreviewallowed = $result->canrequestreview && $result->isstatusidle; 81 $result->iscancelreviewrequestallowed = $result->canrequestreview && $result->isstatuswaitingforreview; 82 $result->isstartreviewallowed = $result->canreview && $result->isstatuswaitingforreview; 83 $result->isstopreviewallowed = $result->canreview && $result->isstatusinreview; 84 85 if (!empty($result->isstatusinreview)) { 86 // TODO Make this more efficient. 87 $userexporter = new user_summary_exporter(core_user::get_user($this->persistent->get_reviewerid(), '*', MUST_EXIST)); 88 $result->reviewer = $userexporter->export($output); 89 } 90 91 $result->url = url::user_competency($this->persistent->get_id())->out(false); 92 93 return (array) $result; 94 } 95 96 protected static function define_other_properties() { 97 return array( 98 'canrequestreview' => array( 99 'type' => PARAM_BOOL, 100 ), 101 'canreview' => array( 102 'type' => PARAM_BOOL, 103 ), 104 'gradename' => array( 105 'type' => PARAM_TEXT 106 ), 107 'isrequestreviewallowed' => array( 108 'type' => PARAM_BOOL, 109 ), 110 'iscancelreviewrequestallowed' => array( 111 'type' => PARAM_BOOL, 112 ), 113 'isstartreviewallowed' => array( 114 'type' => PARAM_BOOL, 115 ), 116 'isstopreviewallowed' => array( 117 'type' => PARAM_BOOL, 118 ), 119 'isstatusidle' => array( 120 'type' => PARAM_BOOL, 121 ), 122 'isstatusinreview' => array( 123 'type' => PARAM_BOOL, 124 ), 125 'isstatuswaitingforreview' => array( 126 'type' => PARAM_BOOL, 127 ), 128 'proficiencyname' => array( 129 'type' => PARAM_RAW 130 ), 131 'reviewer' => array( 132 'type' => user_summary_exporter::read_properties_definition(), 133 'optional' => true 134 ), 135 'statusname' => array( 136 'type' => PARAM_RAW 137 ), 138 'url' => array( 139 'type' => PARAM_URL 140 ), 141 ); 142 } 143 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |