Differences Between: [Versions 401 and 403] [Versions 402 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_tag\reportbuilder\datasource; 20 21 use lang_string; 22 use core\reportbuilder\local\entities\context; 23 use core_reportbuilder\datasource; 24 use core_reportbuilder\local\entities\user; 25 use core_tag\reportbuilder\local\entities\{collection, tag, instance}; 26 27 /** 28 * Tags datasource 29 * 30 * @package core_tag 31 * @copyright 2022 Paul Holden <paulh@moodle.com> 32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 33 */ 34 class tags extends datasource { 35 36 /** 37 * Return user friendly name of the report source 38 * 39 * @return string 40 */ 41 public static function get_name(): string { 42 return get_string('tags', 'core_tag'); 43 } 44 45 /** 46 * Initialise report 47 */ 48 protected function initialise(): void { 49 $collectionentity = new collection(); 50 $collectionalias = $collectionentity->get_table_alias('tag_coll'); 51 52 $this->set_main_table('tag_coll', $collectionalias); 53 $this->add_entity($collectionentity); 54 55 // Join tag entity to collection. 56 $tagentity = new tag(); 57 $tagalias = $tagentity->get_table_alias('tag'); 58 $this->add_entity($tagentity 59 ->add_join("LEFT JOIN {tag} {$tagalias} ON {$tagalias}.tagcollid = {$collectionalias}.id") 60 ); 61 62 // Join instance entity to tag. 63 $instanceentity = new instance(); 64 $instancealias = $instanceentity->get_table_alias('tag_instance'); 65 $this->add_entity($instanceentity 66 ->add_joins($tagentity->get_joins()) 67 ->add_join("LEFT JOIN {tag_instance} {$instancealias} ON {$instancealias}.tagid = {$tagalias}.id") 68 ); 69 70 // Join the context entity. 71 $contextentity = new context(); 72 $contextalias = $contextentity->get_table_alias('context'); 73 $this->add_entity($contextentity 74 ->add_joins($instanceentity->get_joins()) 75 ->add_join("LEFT JOIN {context} {$contextalias} ON {$contextalias}.id = {$instancealias}.contextid") 76 ); 77 78 // Join user entity to represent the tag author. 79 $userentity = (new user()) 80 ->set_entity_title(new lang_string('tagauthor', 'core_tag')); 81 $useralias = $userentity->get_table_alias('user'); 82 $this->add_entity($userentity 83 ->add_joins($tagentity->get_joins()) 84 ->add_join("LEFT JOIN {user} {$useralias} ON {$useralias}.id = {$tagalias}.userid") 85 ); 86 87 // Add report elements from each of the entities we added to the report. 88 $this->add_all_from_entities(); 89 } 90 91 /** 92 * Return the columns that will be added to the report upon creation 93 * 94 * @return string[] 95 */ 96 public function get_default_columns(): array { 97 return [ 98 'collection:name', 99 'tag:namewithlink', 100 'tag:standard', 101 'context:name', 102 ]; 103 } 104 105 /** 106 * Return the column sorting that will be added to the report upon creation 107 * 108 * @return int[] 109 */ 110 public function get_default_column_sorting(): array { 111 return [ 112 'collection:name' => SORT_ASC, 113 'tag:namewithlink' => SORT_ASC, 114 ]; 115 } 116 117 /** 118 * Return the filters that will be added to the report upon creation 119 * 120 * @return string[] 121 */ 122 public function get_default_filters(): array { 123 return [ 124 'tag:name', 125 'tag:standard', 126 ]; 127 } 128 129 /** 130 * Return the conditions that will be added to the report upon creation 131 * 132 * @return string[] 133 */ 134 public function get_default_conditions(): array { 135 return [ 136 'collection:name', 137 ]; 138 } 139 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body