Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403]
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 * Migrate frameworks results. 19 * 20 * @package tool_lpmigrate 21 * @copyright 2016 Frédéric Massart - FMCorz.net 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 namespace tool_lpmigrate\output; 25 defined('MOODLE_INTERNAL') || die(); 26 27 use context; 28 use context_course; 29 use context_module; 30 use moodle_url; 31 use renderable; 32 use templatable; 33 use stdClass; 34 use core_competency\competency; 35 use core_competency\competency_framework; 36 use core_competency\external\competency_exporter; 37 use core_competency\external\competency_framework_exporter; 38 use core_competency\url; 39 use tool_lpmigrate\framework_processor; 40 41 /** 42 * Migrate frameworks results class. 43 * 44 * @package tool_lpmigrate 45 * @copyright 2016 Frédéric Massart - FMCorz.net 46 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 47 */ 48 class migrate_framework_results implements renderable, templatable { 49 50 /** @var context The current page context. */ 51 protected $pagecontext; 52 /** @var framework_processor The processor. */ 53 protected $processor; 54 /** @var array $unmappedfrom Competencies from unmapped. */ 55 protected array $unmappedfrom = []; 56 /** @var array $unmappedto competencies to unmapped. */ 57 protected array $unmappedto = []; 58 /* @var competency_framework|null $frameworkfrom Framework from. */ 59 protected $frameworkfrom = null; 60 /* @var competency_framework|null $frameworkto Framework to. */ 61 protected $frameworkto = null; 62 63 /** 64 * Construct. 65 * 66 * @param context $pagecontext The current page context. 67 * @param framework_processor $processor The processor. 68 * @param competency_framework $frameworkfrom Framework from. 69 * @param competency_framework $frameworkto Framework to. 70 * @param array $unmappedfrom Competencies from unmapped. 71 * @param array $unmappedto Competencies to unmapped. 72 */ 73 public function __construct(context $pagecontext, framework_processor $processor, competency_framework $frameworkfrom, 74 competency_framework $frameworkto, array $unmappedfrom = array(), array $unmappedto = array()) { 75 if (!$processor->has_run()) { 76 throw new \coding_exception('The processor has not run.'); 77 } 78 $this->pagecontext = $pagecontext; 79 $this->processor = $processor; 80 $this->unmappedfrom = $unmappedfrom; 81 $this->unmappedto = $unmappedto; 82 $this->frameworkfrom = $frameworkfrom; 83 $this->frameworkto = $frameworkto; 84 } 85 86 /** 87 * Export the data. 88 * 89 * @param renderer_base $output 90 * @return stdClass 91 */ 92 public function export_for_template(\renderer_base $output) { 93 global $DB; 94 $data = new stdClass(); 95 96 $missingmappings = $this->processor->get_missing_mappings(); 97 98 $data->pagecontextid = $this->pagecontext->id; 99 $data->expectedccmigrations = $this->processor->get_expected_course_competency_migrations(); 100 $data->expectedmcmigrations = $this->processor->get_expected_module_competency_migrations(); 101 $data->ccmigrationscount = $this->processor->get_course_competency_migrations(); 102 $data->mcmigrationscount = $this->processor->get_module_competency_migrations(); 103 $data->ccremovalscount = $this->processor->get_course_competency_removals(); 104 $data->mcremovalscount = $this->processor->get_module_competency_removals(); 105 106 $data->unmappedfrom = array(); 107 $data->unmappedto = array(); 108 109 $exporter = new competency_framework_exporter($this->frameworkfrom); 110 $data->frameworkfrom = $exporter->export($output); 111 $exporter = new competency_framework_exporter($this->frameworkto); 112 $data->frameworkto = $exporter->export($output); 113 114 $fromcontext = $this->frameworkfrom->get_context(); 115 $tocontext = $this->frameworkto->get_context(); 116 117 $compcontext = null; 118 foreach ($this->unmappedfrom as $comp) { 119 $exporter = new competency_exporter($comp, array('context' => $fromcontext)); 120 $data->unmappedfrom[] = $exporter->export($output); 121 } 122 123 foreach ($this->unmappedto as $comp) { 124 $exporter = new competency_exporter($comp, array('context' => $tocontext)); 125 $data->unmappedto[] = $exporter->export($output); 126 } 127 128 $data->coursesfound = $this->processor->get_courses_found_count(); 129 $data->cmsfound = $this->processor->get_cms_found_count(); 130 $data->mappingsmissingcount = count($missingmappings); 131 $data->hasunmappedto = count($data->unmappedto) > 0; 132 $data->hasunmappedfrom = count($data->unmappedfrom) > 0; 133 $warnings = $this->processor->get_warnings(); 134 $data->warnings = array(); 135 $data->warningcount = count($warnings); 136 $errors = $this->processor->get_errors(); 137 $data->errors = array(); 138 $data->errorcount = count($errors); 139 140 foreach ($warnings as $warning) { 141 $cmcontext = !empty($warning['cmid']) ? context_module::instance($warning['cmid']) : null; 142 $coursecontext = context_course::instance($warning['courseid']); 143 $warning['cm'] = $cmcontext ? $cmcontext->get_context_name() : null; 144 $warning['course'] = $coursecontext->get_context_name(); 145 $warning['competency'] = $DB->get_field(competency::TABLE, 'idnumber', array('id' => $warning['competencyid'])); 146 $data->warnings[] = $warning; 147 } 148 149 foreach ($errors as $error) { 150 $cmcontext = !empty($error['cmid']) ? context_module::instance($error['cmid']) : null; 151 $coursecontext = context_course::instance($error['courseid']); 152 $error['cm'] = $cmcontext ? $cmcontext->get_context_name() : null; 153 $error['course'] = $coursecontext->get_context_name(); 154 $error['competency'] = $DB->get_field(competency::TABLE, 'idnumber', array('id' => $error['competencyid'])); 155 $data->errors[] = $error; 156 } 157 158 $data->pluginbaseurl = (new moodle_url('/admin/tool/lpmigrate'))->out(false); 159 $data->frameworksurl = url::frameworks($this->pagecontext->id)->out(false); 160 161 return $data; 162 } 163 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body