[ 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 with all the evidence 19 * 20 * @package tool_lp 21 * @copyright 2015 Damyon Wiese 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 namespace tool_lp\external; 25 26 use context_user; 27 use renderer_base; 28 use stdClass; 29 use core_competency\external\comment_area_exporter; 30 use core_competency\external\evidence_exporter; 31 use core_competency\external\user_competency_exporter; 32 use core_competency\external\user_competency_plan_exporter; 33 use core_competency\external\user_competency_course_exporter; 34 use core_competency\external\user_summary_exporter; 35 use core_competency\user_competency; 36 37 /** 38 * Class for exporting user competency data with additional related data. 39 * 40 * @copyright 2015 Damyon Wiese 41 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 42 */ 43 class user_competency_summary_exporter extends \core_competency\external\exporter { 44 45 protected static function define_related() { 46 // We cache the context so it does not need to be retrieved from the framework every time. 47 return array('competency' => '\\core_competency\\competency', 48 'relatedcompetencies' => '\\core_competency\\competency[]', 49 'user' => '\\stdClass', 50 'usercompetency' => '\\core_competency\\user_competency?', 51 'usercompetencyplan' => '\\core_competency\\user_competency_plan?', 52 'usercompetencycourse' => '\\core_competency\\user_competency_course?', 53 'evidence' => '\\core_competency\\evidence[]'); 54 } 55 56 protected static function define_other_properties() { 57 return array( 58 'showrelatedcompetencies' => array( 59 'type' => PARAM_BOOL 60 ), 61 'cangrade' => array( 62 'type' => PARAM_BOOL 63 ), 64 'competency' => array( 65 'type' => competency_summary_exporter::read_properties_definition() 66 ), 67 'user' => array( 68 'type' => user_summary_exporter::read_properties_definition(), 69 ), 70 'usercompetency' => array( 71 'type' => user_competency_exporter::read_properties_definition(), 72 'optional' => true 73 ), 74 'usercompetencyplan' => array( 75 'type' => user_competency_plan_exporter::read_properties_definition(), 76 'optional' => true 77 ), 78 'usercompetencycourse' => array( 79 'type' => user_competency_course_exporter::read_properties_definition(), 80 'optional' => true 81 ), 82 'evidence' => array( 83 'type' => evidence_exporter::read_properties_definition(), 84 'multiple' => true 85 ), 86 'commentarea' => array( 87 'type' => comment_area_exporter::read_properties_definition(), 88 'optional' => true 89 ), 90 ); 91 } 92 93 protected function get_other_values(renderer_base $output) { 94 global $DB; 95 $result = new stdClass(); 96 97 $result->showrelatedcompetencies = true; 98 99 $competency = $this->related['competency']; 100 $exporter = new competency_summary_exporter(null, array( 101 'competency' => $competency, 102 'context' => $competency->get_context(), 103 'framework' => $competency->get_framework(), 104 'linkedcourses' => array(), 105 'relatedcompetencies' => $this->related['relatedcompetencies'] 106 )); 107 $result->competency = $exporter->export($output); 108 109 $result->cangrade = user_competency::can_grade_user($this->related['user']->id); 110 if ($this->related['user']) { 111 $exporter = new user_summary_exporter($this->related['user']); 112 $result->user = $exporter->export($output); 113 } 114 $related = array('scale' => $competency->get_scale()); 115 if ($this->related['usercompetency']) { 116 $exporter = new user_competency_exporter($this->related['usercompetency'], $related); 117 $result->usercompetency = $exporter->export($output); 118 } 119 if ($this->related['usercompetencyplan']) { 120 $exporter = new user_competency_plan_exporter($this->related['usercompetencyplan'], $related); 121 $result->usercompetencyplan = $exporter->export($output); 122 } 123 if ($this->related['usercompetencycourse']) { 124 $exporter = new user_competency_course_exporter($this->related['usercompetencycourse'], $related); 125 $result->usercompetencycourse = $exporter->export($output); 126 } 127 128 $allevidence = array(); 129 $usercache = array(); 130 $scale = $competency->get_scale(); 131 132 $result->evidence = array(); 133 if (count($this->related['evidence'])) { 134 foreach ($this->related['evidence'] as $evidence) { 135 $actionuserid = $evidence->get_actionuserid(); 136 if (!empty($actionuserid)) { 137 $usercache[$evidence->get_actionuserid()] = true; 138 } 139 } 140 $users = array(); 141 if (!empty($usercache)) { 142 list($sql, $params) = $DB->get_in_or_equal(array_keys($usercache)); 143 $users = $DB->get_records_select('user', 'id ' . $sql, $params); 144 } 145 146 foreach ($users as $user) { 147 $usercache[$user->id] = $user; 148 } 149 150 foreach ($this->related['evidence'] as $evidence) { 151 $actionuserid = $evidence->get_actionuserid(); 152 $related = array( 153 'scale' => $scale, 154 'usercompetency' => ($this->related['usercompetency'] ? $this->related['usercompetency'] : null), 155 'usercompetencyplan' => ($this->related['usercompetencyplan'] ? $this->related['usercompetencyplan'] : null), 156 ); 157 $related['actionuser'] = !empty($actionuserid) ? $usercache[$actionuserid] : null; 158 $exporter = new evidence_exporter($evidence, $related); 159 $allevidence[] = $exporter->export($output); 160 } 161 $result->evidence = $allevidence; 162 } 163 164 $usercompetency = !empty($this->related['usercompetency']) ? $this->related['usercompetency'] : null; 165 166 if (!empty($usercompetency) && $usercompetency->can_read_comments()) { 167 $commentareaexporter = new comment_area_exporter($usercompetency->get_comment_object()); 168 $result->commentarea = $commentareaexporter->export($output); 169 } 170 171 return (array) $result; 172 } 173 }
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 |