Differences Between: [Versions 310 and 402] [Versions 310 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 55 /** 56 * Construct. 57 * 58 * @param context $pagecontext The current page context. 59 * @param framework_processor $processor The processor. 60 * @param competency_framework $frameworkfrom Framework from. 61 * @param competency_framework $frameworkto Framework to. 62 * @param array $unmappedfrom Competencies from unmapped. 63 * @param array $unmappedto Competencies to unmapped. 64 */ 65 public function __construct(context $pagecontext, framework_processor $processor, competency_framework $frameworkfrom, 66 competency_framework $frameworkto, array $unmappedfrom = array(), array $unmappedto = array()) { 67 if (!$processor->has_run()) { 68 throw new \coding_exception('The processor has not run.'); 69 } 70 $this->pagecontext = $pagecontext; 71 $this->processor = $processor; 72 $this->unmappedfrom = $unmappedfrom; 73 $this->unmappedto = $unmappedto; 74 $this->frameworkfrom = $frameworkfrom; 75 $this->frameworkto = $frameworkto; 76 } 77 78 /** 79 * Export the data. 80 * 81 * @param renderer_base $output 82 * @return stdClass 83 */ 84 public function export_for_template(\renderer_base $output) { 85 global $DB; 86 $data = new stdClass(); 87 88 $missingmappings = $this->processor->get_missing_mappings(); 89 90 $data->pagecontextid = $this->pagecontext->id; 91 $data->expectedccmigrations = $this->processor->get_expected_course_competency_migrations(); 92 $data->expectedmcmigrations = $this->processor->get_expected_module_competency_migrations(); 93 $data->ccmigrationscount = $this->processor->get_course_competency_migrations(); 94 $data->mcmigrationscount = $this->processor->get_module_competency_migrations(); 95 $data->ccremovalscount = $this->processor->get_course_competency_removals(); 96 $data->mcremovalscount = $this->processor->get_module_competency_removals(); 97 98 $data->unmappedfrom = array(); 99 $data->unmappedto = array(); 100 101 $exporter = new competency_framework_exporter($this->frameworkfrom); 102 $data->frameworkfrom = $exporter->export($output); 103 $exporter = new competency_framework_exporter($this->frameworkto); 104 $data->frameworkto = $exporter->export($output); 105 106 $fromcontext = $this->frameworkfrom->get_context(); 107 $tocontext = $this->frameworkto->get_context(); 108 109 $compcontext = null; 110 foreach ($this->unmappedfrom as $comp) { 111 $exporter = new competency_exporter($comp, array('context' => $fromcontext)); 112 $data->unmappedfrom[] = $exporter->export($output); 113 } 114 115 foreach ($this->unmappedto as $comp) { 116 $exporter = new competency_exporter($comp, array('context' => $tocontext)); 117 $data->unmappedto[] = $exporter->export($output); 118 } 119 120 $data->coursesfound = $this->processor->get_courses_found_count(); 121 $data->cmsfound = $this->processor->get_cms_found_count(); 122 $data->mappingsmissingcount = count($missingmappings); 123 $data->hasunmappedto = count($data->unmappedto) > 0; 124 $data->hasunmappedfrom = count($data->unmappedfrom) > 0; 125 $warnings = $this->processor->get_warnings(); 126 $data->warnings = array(); 127 $data->warningcount = count($warnings); 128 $errors = $this->processor->get_errors(); 129 $data->errors = array(); 130 $data->errorcount = count($errors); 131 132 foreach ($warnings as $warning) { 133 $cmcontext = !empty($warning['cmid']) ? context_module::instance($warning['cmid']) : null; 134 $coursecontext = context_course::instance($warning['courseid']); 135 $warning['cm'] = $cmcontext ? $cmcontext->get_context_name() : null; 136 $warning['course'] = $coursecontext->get_context_name(); 137 $warning['competency'] = $DB->get_field(competency::TABLE, 'idnumber', array('id' => $warning['competencyid'])); 138 $data->warnings[] = $warning; 139 } 140 141 foreach ($errors as $error) { 142 $cmcontext = !empty($error['cmid']) ? context_module::instance($error['cmid']) : null; 143 $coursecontext = context_course::instance($error['courseid']); 144 $error['cm'] = $cmcontext ? $cmcontext->get_context_name() : null; 145 $error['course'] = $coursecontext->get_context_name(); 146 $error['competency'] = $DB->get_field(competency::TABLE, 'idnumber', array('id' => $error['competencyid'])); 147 $data->errors[] = $error; 148 } 149 150 $data->pluginbaseurl = (new moodle_url('/admin/tool/lpmigrate'))->out(false); 151 $data->frameworksurl = url::frameworks($this->pagecontext->id)->out(false); 152 153 return $data; 154 } 155 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body