Differences Between: [Versions 400 and 401] [Versions 400 and 402] [Versions 400 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 declare(strict_types=1); 18 19 namespace core_course\reportbuilder\datasource; 20 21 use core_course\local\entities\course_category; 22 use core_reportbuilder\datasource; 23 use core_reportbuilder\local\entities\course; 24 use core_reportbuilder\local\helpers\database; 25 26 /** 27 * Courses datasource 28 * 29 * @package core_course 30 * @copyright 2021 Paul Holden <paulh@moodle.com> 31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 32 */ 33 class courses extends datasource { 34 35 /** 36 * Return user friendly name of the datasource 37 * 38 * @return string 39 */ 40 public static function get_name(): string { 41 return get_string('courses'); 42 } 43 44 /** 45 * Initialise report 46 */ 47 protected function initialise(): void { 48 $courseentity = new course(); 49 $coursetablealias = $courseentity->get_table_alias('course'); 50 51 // Exclude site course. 52 $paramsiteid = database::generate_param_name(); 53 54 $this->set_main_table('course', $coursetablealias); 55 $this->add_base_condition_sql("{$coursetablealias}.id != :{$paramsiteid}", [$paramsiteid => SITEID]); 56 57 $this->add_entity($courseentity); 58 59 // Join the course category entity. 60 $coursecatentity = new course_category(); 61 $coursecattablealias = $coursecatentity->get_table_alias('course_categories'); 62 $this->add_entity($coursecatentity 63 ->add_join("JOIN {course_categories} {$coursecattablealias} 64 ON {$coursecattablealias}.id = {$coursetablealias}.category")); 65 66 // Add all columns from entities to be available in custom reports. 67 $this->add_columns_from_entity($coursecatentity->get_entity_name()); 68 $this->add_columns_from_entity($courseentity->get_entity_name()); 69 70 // Add all filters from entities to be available in custom reports. 71 $this->add_filters_from_entity($coursecatentity->get_entity_name()); 72 $this->add_filters_from_entity($courseentity->get_entity_name()); 73 74 // Add all conditions from entities to be available in custom reports. 75 $this->add_conditions_from_entity($coursecatentity->get_entity_name()); 76 $this->add_conditions_from_entity($courseentity->get_entity_name()); 77 } 78 79 /** 80 * Return the columns that will be added to the report as part of default setup 81 * 82 * @return string[] 83 */ 84 public function get_default_columns(): array { 85 return [ 86 'course_category:name', 87 'course:shortname', 88 'course:fullname', 89 'course:idnumber', 90 ]; 91 } 92 93 /** 94 * Return the filters that will be added to the report once is created 95 * 96 * @return string[] 97 */ 98 public function get_default_filters(): array { 99 return ['course_category:name', 'course:fullname', 'course:idnumber']; 100 } 101 102 /** 103 * Return the conditions that will be added to the report once is created 104 * 105 * @return string[] 106 */ 107 public function get_default_conditions(): array { 108 return ['course_category:name']; 109 } 110 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body