[ 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 containing data for course competencies page 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\output; 25 defined('MOODLE_INTERNAL') || die(); 26 27 use renderable; 28 use templatable; 29 use renderer_base; 30 use stdClass; 31 use moodle_url; 32 use context_system; 33 use context_course; 34 use core_competency\api; 35 use tool_lp\course_competency_statistics; 36 use core_competency\competency; 37 use core_competency\course_competency; 38 use core_competency\external\competency_exporter; 39 use core_competency\external\course_competency_exporter; 40 use core_competency\external\course_competency_settings_exporter; 41 use core_competency\external\user_competency_course_exporter; 42 use core_competency\external\user_competency_exporter; 43 use tool_lp\external\competency_path_exporter; 44 use tool_lp\external\course_competency_statistics_exporter; 45 use tool_lp\external\course_module_summary_exporter; 46 47 /** 48 * Class containing data for course competencies page 49 * 50 * @copyright 2015 Damyon Wiese 51 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 52 */ 53 class course_competencies_page implements renderable, templatable { 54 55 /** @var int $courseid Course id for this page. */ 56 protected $courseid = null; 57 58 /** @var context $context The context for this page. */ 59 protected $context = null; 60 61 /** @var \core_competency\course_competency[] $competencies List of competencies. */ 62 protected $coursecompetencylist = array(); 63 64 /** @var bool $canmanagecompetencyframeworks Can the current user manage competency frameworks. */ 65 protected $canmanagecompetencyframeworks = false; 66 67 /** @var bool $canmanagecoursecompetencies Can the current user manage course competency frameworks.. */ 68 protected $canmanagecoursecompetencies = false; 69 70 /** @var string $manageurl manage url. */ 71 protected $manageurl = null; 72 73 /** 74 * Construct this renderable. 75 * @param int $courseid The course record for this page. 76 */ 77 public function __construct($courseid) { 78 $this->context = context_course::instance($courseid); 79 $this->courseid = $courseid; 80 $this->coursecompetencylist = api::list_course_competencies($courseid); 81 $this->canmanagecoursecompetencies = has_capability('moodle/competency:coursecompetencymanage', $this->context); 82 $this->canconfigurecoursecompetencies = has_capability('moodle/competency:coursecompetencyconfigure', $this->context); 83 $this->cangradecompetencies = has_capability('moodle/competency:competencygrade', $this->context); 84 $this->coursecompetencysettings = api::read_course_competency_settings($courseid); 85 $this->coursecompetencystatistics = new course_competency_statistics($courseid); 86 87 // Check the lowest level in which the user can manage the competencies. 88 $this->manageurl = null; 89 $this->canmanagecompetencyframeworks = false; 90 $contexts = array_reverse($this->context->get_parent_contexts(true)); 91 foreach ($contexts as $context) { 92 $canmanage = has_capability('moodle/competency:competencymanage', $context); 93 if ($canmanage) { 94 $this->manageurl = new moodle_url('/admin/tool/lp/competencyframeworks.php', 95 array('pagecontextid' => $context->id)); 96 $this->canmanagecompetencyframeworks = true; 97 break; 98 } 99 } 100 } 101 102 /** 103 * Export this data so it can be used as the context for a mustache template. 104 * 105 * @param renderer_base $output Renderer base. 106 * @return stdClass 107 */ 108 public function export_for_template(renderer_base $output) { 109 global $USER; 110 111 $data = new stdClass(); 112 $data->courseid = $this->courseid; 113 $data->pagecontextid = $this->context->id; 114 $data->competencies = array(); 115 $contextcache = array(); 116 117 $gradable = is_enrolled($this->context, $USER, 'moodle/competency:coursecompetencygradable'); 118 if ($gradable) { 119 $usercompetencycourses = api::list_user_competencies_in_course($this->courseid, $USER->id); 120 $data->gradableuserid = $USER->id; 121 } 122 123 $ruleoutcomelist = course_competency::get_ruleoutcome_list(); 124 $ruleoutcomeoptions = array(); 125 foreach ($ruleoutcomelist as $value => $text) { 126 $ruleoutcomeoptions[$value] = array('value' => $value, 'text' => (string) $text, 'selected' => false); 127 } 128 129 foreach ($this->coursecompetencylist as $coursecompetencyelement) { 130 $coursecompetency = $coursecompetencyelement['coursecompetency']; 131 $competency = $coursecompetencyelement['competency']; 132 if (!isset($contextcache[$competency->get_competencyframeworkid()])) { 133 $contextcache[$competency->get_competencyframeworkid()] = $competency->get_context(); 134 } 135 $context = $contextcache[$competency->get_competencyframeworkid()]; 136 137 $compexporter = new competency_exporter($competency, array('context' => $context)); 138 $ccexporter = new course_competency_exporter($coursecompetency, array('context' => $context)); 139 140 $ccoutcomeoptions = (array) (object) $ruleoutcomeoptions; 141 $ccoutcomeoptions[$coursecompetency->get_ruleoutcome()]['selected'] = true; 142 143 $coursemodules = api::list_course_modules_using_competency($competency->get_id(), $this->courseid); 144 145 $fastmodinfo = get_fast_modinfo($this->courseid); 146 $exportedmodules = array(); 147 foreach ($coursemodules as $cmid) { 148 $cminfo = $fastmodinfo->cms[$cmid]; 149 $cmexporter = new course_module_summary_exporter(null, array('cm' => $cminfo)); 150 $exportedmodules[] = $cmexporter->export($output); 151 } 152 // Competency path. 153 $pathexporter = new competency_path_exporter([ 154 'ancestors' => $competency->get_ancestors(), 155 'framework' => $competency->get_framework(), 156 'context' => $context 157 ]); 158 159 $onerow = array( 160 'competency' => $compexporter->export($output), 161 'coursecompetency' => $ccexporter->export($output), 162 'ruleoutcomeoptions' => $ccoutcomeoptions, 163 'coursemodules' => $exportedmodules, 164 'comppath' => $pathexporter->export($output) 165 ); 166 if ($gradable) { 167 $foundusercompetencycourse = false; 168 foreach ($usercompetencycourses as $usercompetencycourse) { 169 if ($usercompetencycourse->get_competencyid() == $competency->get_id()) { 170 $foundusercompetencycourse = $usercompetencycourse; 171 } 172 } 173 if ($foundusercompetencycourse) { 174 $related = array( 175 'scale' => $competency->get_scale() 176 ); 177 $exporter = new user_competency_course_exporter($foundusercompetencycourse, $related); 178 $onerow['usercompetencycourse'] = $exporter->export($output); 179 } 180 } 181 array_push($data->competencies, $onerow); 182 } 183 184 $data->canmanagecompetencyframeworks = $this->canmanagecompetencyframeworks; 185 $data->canmanagecoursecompetencies = $this->canmanagecoursecompetencies; 186 $data->canconfigurecoursecompetencies = $this->canconfigurecoursecompetencies; 187 $data->cangradecompetencies = $this->cangradecompetencies; 188 $exporter = new course_competency_settings_exporter($this->coursecompetencysettings); 189 $data->settings = $exporter->export($output); 190 $related = array('context' => $this->context); 191 $exporter = new course_competency_statistics_exporter($this->coursecompetencystatistics, $related); 192 $data->statistics = $exporter->export($output); 193 $data->manageurl = null; 194 if ($this->canmanagecompetencyframeworks) { 195 $data->manageurl = $this->manageurl->out(true); 196 } 197 198 return $data; 199 } 200 201 }
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 |