See Release Notes
Long Term Support Release
Differences Between: [Versions 401 and 402] [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 declare(strict_types=1); 18 19 namespace core_blog\reportbuilder\datasource; 20 21 use lang_string; 22 use core_reportbuilder\datasource; 23 use core_reportbuilder\local\entities\{course, user}; 24 use core_blog\reportbuilder\local\entities\blog; 25 use core_tag\reportbuilder\local\entities\tag; 26 27 /** 28 * Blogs datasource 29 * 30 * @package core_blog 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 blogs 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('blogs', 'core_blog'); 43 } 44 45 /** 46 * Initialise report 47 */ 48 protected function initialise(): void { 49 $blogentity = new blog(); 50 51 $postalias = $blogentity->get_table_alias('post'); 52 $this->set_main_table('post', $postalias); 53 $this->add_base_condition_simple("{$postalias}.module", 'blog'); 54 55 $this->add_entity($blogentity); 56 57 // Join the tag entity. 58 $tagentity = (new tag()) 59 ->set_entity_title(new lang_string('blogtags', 'core_blog')) 60 ->set_table_alias('tag', $blogentity->get_table_alias('tag')); 61 $this->add_entity($tagentity 62 ->add_joins($blogentity->get_tag_joins())); 63 64 // Join the user entity to represent the blog author. 65 $userentity = new user(); 66 $useralias = $userentity->get_table_alias('user'); 67 $this->add_entity($userentity 68 ->add_join("LEFT JOIN {user} {$useralias} ON {$useralias}.id = {$postalias}.userid")); 69 70 // Join the course entity for course blogs. 71 $courseentity = new course(); 72 $coursealias = $courseentity->get_table_alias('course'); 73 $this->add_entity($courseentity 74 ->add_join("LEFT JOIN {course} {$coursealias} ON {$coursealias}.id = {$postalias}.courseid")); 75 76 // Add report elements from each of the entities we added to the report. 77 $this->add_all_from_entity($blogentity->get_entity_name()); 78 79 // Add specific tag entity elements. 80 $this->add_columns_from_entity($tagentity->get_entity_name(), ['name', 'namewithlink']); 81 $this->add_filter($tagentity->get_filter('name')); 82 $this->add_condition($tagentity->get_condition('name')); 83 84 $this->add_all_from_entity($userentity->get_entity_name()); 85 $this->add_all_from_entity($courseentity->get_entity_name()); 86 } 87 88 /** 89 * Return the columns that will be added to the report upon creation 90 * 91 * @return string[] 92 */ 93 public function get_default_columns(): array { 94 return [ 95 'user:fullname', 96 'course:fullname', 97 'blog:title', 98 'blog:timecreated', 99 ]; 100 } 101 102 /** 103 * Return the filters that will be added to the report upon creation 104 * 105 * @return string[] 106 */ 107 public function get_default_filters(): array { 108 return [ 109 'user:fullname', 110 'blog:title', 111 'blog:timecreated', 112 ]; 113 } 114 115 /** 116 * Return the conditions that will be added to the report upon creation 117 * 118 * @return string[] 119 */ 120 public function get_default_conditions(): array { 121 return [ 122 'blog:publishstate', 123 ]; 124 } 125 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body