See Release Notes
Long Term Support Release
<?php // This file is part of Moodle - http://moodle.org/ // // Moodle is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. declare(strict_types=1); namespace core_blog\reportbuilder\datasource; use lang_string; use core_reportbuilder\datasource; use core_reportbuilder\local\entities\{course, user}; use core_blog\reportbuilder\local\entities\blog;> use core_files\reportbuilder\local\entities\file; use core_tag\reportbuilder\local\entities\tag; > use core_comment\reportbuilder\local\entities\comment;/** * Blogs datasource * * @package core_blog * @copyright 2022 Paul Holden <paulh@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class blogs extends datasource { /** * Return user friendly name of the report source * * @return string */ public static function get_name(): string { return get_string('blogs', 'core_blog'); } /** * Initialise report */ protected function initialise(): void { $blogentity = new blog(); $postalias = $blogentity->get_table_alias('post'); $this->set_main_table('post', $postalias); $this->add_base_condition_simple("{$postalias}.module", 'blog'); $this->add_entity($blogentity);> // Join the files entity. // Join the tag entity. > $fileentity = (new file()) $tagentity = (new tag()) > ->set_entity_title(new lang_string('blogattachment', 'core_blog')); ->set_entity_title(new lang_string('blogtags', 'core_blog')) > $filesalias = $fileentity->get_table_alias('files'); ->set_table_alias('tag', $blogentity->get_table_alias('tag')); > $this->add_entity($fileentity $this->add_entity($tagentity > ->add_join("LEFT JOIN {files} {$filesalias} ->add_joins($blogentity->get_tag_joins())); > ON {$filesalias}.contextid = " . SYSCONTEXTID . " > AND {$filesalias}.component = 'blog' // Join the user entity to represent the blog author. > AND {$filesalias}.filearea = 'attachment' $userentity = new user(); > AND {$filesalias}.itemid = {$postalias}.id $useralias = $userentity->get_table_alias('user'); > AND {$filesalias}.filename != '.'")); $this->add_entity($userentity >< $userentity = new user(); < $useralias = $userentity->get_table_alias('user'); < $this->add_entity($userentity < ->add_join("LEFT JOIN {user} {$useralias} ON {$useralias}.id = {$postalias}.userid"));> $authorentity = (new user()) > ->set_entity_title(new lang_string('author', 'core_blog')); > $authoralias = $authorentity->get_table_alias('user'); > $this->add_entity($authorentity > ->add_join("LEFT JOIN {user} {$authoralias} ON {$authoralias}.id = {$postalias}.userid"));$coursealias = $courseentity->get_table_alias('course'); $this->add_entity($courseentity ->add_join("LEFT JOIN {course} {$coursealias} ON {$coursealias}.id = {$postalias}.courseid"));> // Join the comment entity (ensure differing alias from that used by course entity). // Add report elements from each of the entities we added to the report. > $commententity = (new comment()) $this->add_all_from_entity($blogentity->get_entity_name()); > ->set_table_alias('comments', 'bcmt'); > $this->add_entity($commententity // Add specific tag entity elements. > ->add_join("LEFT JOIN {comments} bcmt ON bcmt.component = 'blog' AND bcmt.itemid = {$postalias}.id")); $this->add_columns_from_entity($tagentity->get_entity_name(), ['name', 'namewithlink']); > $this->add_filter($tagentity->get_filter('name')); > // Join the user entity to represent the comment author. Override table aliases to avoid clash with first instance. $this->add_condition($tagentity->get_condition('name')); > $commenterentity = (new user()) > ->set_entity_name('commenter') $this->add_all_from_entity($userentity->get_entity_name()); > ->set_entity_title(new lang_string('commenter', 'core_comment')) $this->add_all_from_entity($courseentity->get_entity_name()); > ->set_table_aliases([ } > 'user' => 'cu', > 'context' => 'cuctx', /** > ]); * Return the columns that will be added to the report upon creation > $this->add_entity($commenterentity * > ->add_joins($commententity->get_joins()) * @return string[] > ->add_join("LEFT JOIN {user} cu ON cu.id = bcmt.userid")); */ >< // Add specific tag entity elements.> // Add specific file/tag entity elements. > $this->add_columns_from_entity($fileentity->get_entity_name(), ['name', 'size', 'type', 'timecreated']); > $this->add_filters_from_entity($fileentity->get_entity_name(), ['name', 'size', 'timecreated']); > $this->add_conditions_from_entity($fileentity->get_entity_name(), ['name', 'size', 'timecreated']); >< $this->add_all_from_entity($userentity->get_entity_name());> $this->add_all_from_entity($authorentity->get_entity_name());'user:fullname',> 'course:fullname', > // Add specific comment entity elements. 'blog:title', > $this->add_columns_from_entity($commententity->get_entity_name(), ['content', 'timecreated']); 'blog:timecreated', > $this->add_filter($commententity->get_filter('timecreated')); ]; > $this->add_condition($commententity->get_filter('timecreated')); } > > $this->add_all_from_entity($commenterentity->get_entity_name());/**> ]; * Return the filters that will be added to the report upon creation > } * > * @return string[] > /** */ > * Return the column sorting that will be added to the report upon creation public function get_default_filters(): array { > * return [ > * @return int[] 'user:fullname', > */ 'blog:title', > public function get_default_column_sorting(): array { 'blog:timecreated', > return [ ]; > 'user:fullname' => SORT_ASC, } > 'blog:timecreated' => SORT_ASC,/** * Return the conditions that will be added to the report upon creation * * @return string[] */ public function get_default_conditions(): array { return [ 'blog:publishstate', ]; } }