���ѧۧݧ�ӧ�� �ާ֧ߧ֧էا֧� - ���֧էѧܧ�ڧ��ӧѧ�� - /home3/cpr76684/public_html/datasource.tar
���ѧ٧ѧ�
cohorts_test.php 0000644 00000013573 15151252414 0010006 0 ustar 00 <?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_cohort\reportbuilder\datasource; use core_reportbuilder_generator; use core_reportbuilder_testcase; use core_reportbuilder\manager; use core_reportbuilder\local\filters\user; use core_user; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once("{$CFG->dirroot}/reportbuilder/tests/helpers.php"); /** * Unit tests for cohorts datasource * * @package core_cohort * @covers \core_cohort\reportbuilder\datasource\cohorts * @copyright 2021 Paul Holden <paulh@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class cohorts_test extends core_reportbuilder_testcase { /** * Test cohorts datasource */ public function test_cohorts_datasource(): void { $this->resetAfterTest(); // Test subject. $cohort = $this->getDataGenerator()->create_cohort([ 'name' => 'Legends', 'idnumber' => 'C101', 'description' => 'Cohort for the legends', ]); $user = $this->getDataGenerator()->create_user(['firstname' => 'Lionel', 'lastname' => 'Richards']); cohort_add_member($cohort->id, $user->id); /** @var core_reportbuilder_generator $generator */ $generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder'); $report = $generator->create_report(['name' => 'Cohorts', 'source' => cohorts::class]); // Add user fullname column to the report. $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:fullname']); $content = $this->get_custom_report_content($report->get('id')); $this->assertCount(1, $content); $contentrow = array_values(reset($content)); $this->assertEquals([ 'Legends', // Name. 'System', // Context. 'C101', // ID number. '<div class="text_to_html">Cohort for the legends</div>', // Description. 'Lionel Richards', // User. ], $contentrow); } /** * Data provider for {@see test_cohorts_datasource_user_select} * * @return array[] */ public function cohorts_datasource_user_select_provider(): array { return [ ['user01', 'Cohort01'], ['user02', 'Cohort02'], ]; } /** * Test cohorts datasource, while adding the user select condition * * @param string $username * @param string $expectedcohort * * @dataProvider cohorts_datasource_user_select_provider */ public function test_cohorts_datasource_user_select(string $username, string $expectedcohort): void { $this->resetAfterTest(); // First cohort/user member. $cohort01 = $this->getDataGenerator()->create_cohort(['name' => 'Cohort01']); $user01 = $this->getDataGenerator()->create_user(['username' => 'user01']); cohort_add_member($cohort01->id, $user01->id); // Second cohort/user member. $cohort02 = $this->getDataGenerator()->create_cohort(['name' => 'Cohort02']); $user02 = $this->getDataGenerator()->create_user(['username' => 'user02']); cohort_add_member($cohort02->id, $user02->id); /** @var core_reportbuilder_generator $generator */ $generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder'); $report = $generator->create_report(['name' => 'User cohorts', 'source' => cohorts::class, 'default' => 0]); // Add cohort name and user fullname columns. $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'cohort:name']); $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:username']); // Add condition to limit report data to current user. $condition = $generator->create_condition(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:userselect']); manager::get_report_from_persistent($report)->set_condition_values([ $condition->get('uniqueidentifier') . '_operator' => user::USER_CURRENT, ]); // Switch user, request report. $currentuser = core_user::get_user_by_username($username); $this->setUser($currentuser); $content = $this->get_custom_report_content($report->get('id')); $this->assertCount(1, $content); $contentrow = array_values(reset($content)); $this->assertEquals([$expectedcohort, $username], $contentrow); } /** * Stress test datasource * * In order to execute this test PHPUNIT_LONGTEST should be defined as true in phpunit.xml or directly in config.php */ public function test_stress_datasource(): void { if (!PHPUNIT_LONGTEST) { $this->markTestSkipped('PHPUNIT_LONGTEST is not defined'); } $this->resetAfterTest(); $cohort = $this->getDataGenerator()->create_cohort(); $user = $this->getDataGenerator()->create_user(); cohort_add_member($cohort->id, $user->id); $this->datasource_stress_test_columns(cohorts::class); $this->datasource_stress_test_columns_aggregation(cohorts::class); $this->datasource_stress_test_conditions(cohorts::class, 'cohort:name'); } } notes_test.php 0000644 00000024473 15152025176 0007462 0 ustar 00 <?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_notes\reportbuilder\datasource; use core_collator; use core_notes_generator; use core_reportbuilder_generator; use core_reportbuilder_testcase; use core_reportbuilder\local\filters\{date, select, text}; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once("{$CFG->dirroot}/reportbuilder/tests/helpers.php"); /** * Unit tests for notes datasource * * @package core_notes * @covers \core_notes\reportbuilder\datasource\notes * @copyright 2022 Paul Holden <paulh@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class notes_test extends core_reportbuilder_testcase { /** * Load required test libraries */ public static function setUpBeforeClass(): void { global $CFG; require_once("{$CFG->dirroot}/notes/lib.php"); } /** * Test default datasource */ public function test_datasource_default(): void { $this->resetAfterTest(); /** @var core_notes_generator $notesgenerator */ $notesgenerator = $this->getDataGenerator()->get_plugin_generator('core_notes'); $course = $this->getDataGenerator()->create_course(); $usercoursenote = $this->getDataGenerator()->create_and_enrol($course); $notesgenerator->create_instance(['courseid' => $course->id, 'userid' => $usercoursenote->id, 'content' => 'Course', 'publishstate' => NOTES_STATE_PUBLIC]); $userpersonalnote = $this->getDataGenerator()->create_user(); $notesgenerator->create_instance(['courseid' => $course->id, 'userid' => $userpersonalnote->id, 'content' => 'Personal', 'publishstate' => NOTES_STATE_DRAFT]); $usersitenote = $this->getDataGenerator()->create_user(); $notesgenerator->create_instance(['courseid' => $course->id, 'userid' => $usersitenote->id, 'content' => 'Site', 'publishstate' => NOTES_STATE_SITE]); /** @var core_reportbuilder_generator $generator */ $generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder'); $report = $generator->create_report(['name' => 'Notes', 'source' => notes::class, 'default' => 1]); $content = $this->get_custom_report_content($report->get('id')); $this->assertCount(3, $content); // Consistent order (course, personal, site), just in case. core_collator::asort_array_of_arrays_by_key($content, 'c1_publishstate'); $content = array_values($content); // Default columns are recipient, publishstate, course, note. $this->assertEquals([ [fullname($usercoursenote), 'Course notes', $course->fullname, 'Course'], [fullname($userpersonalnote), 'Personal notes', '', 'Personal'], [fullname($usersitenote), 'Site notes', '', 'Site'], ], array_map('array_values', $content)); } /** * Test datasource columns that aren't added by default */ public function test_datasource_non_default_columns(): void { global $DB; $this->resetAfterTest(); $recipient = $this->getDataGenerator()->create_user(); $author = $this->getDataGenerator()->create_user(); $this->setUser($author); /** @var core_notes_generator $notesgenerator */ $notesgenerator = $this->getDataGenerator()->get_plugin_generator('core_notes'); $note = $notesgenerator->create_instance(['courseid' => SITEID, 'publishstate' => NOTES_STATE_SITE, 'content' => 'Cool', 'userid' => $recipient->id, ]); // Manually update the created/modified date of the note. $note->created = 1654038000; $note->lastmodified = $note->created + HOURSECS; $DB->update_record('post', $note); /** @var core_reportbuilder_generator $generator */ $generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder'); $report = $generator->create_report(['name' => 'Notes', 'source' => notes::class, 'default' => 0]); $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'note:content']); $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'note:timecreated']); $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'note:timemodified']); // Ensure we can add data from both user entities. $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'recipient:fullname']); $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'author:fullname']); $content = $this->get_custom_report_content($report->get('id')); $this->assertCount(1, $content); $this->assertEquals([ 'Cool', userdate($note->created), userdate($note->lastmodified), fullname($recipient), fullname($author), ], array_values($content[0])); } /** * Data provider for {@see test_datasource_filters} * * @return array[] */ public function datasource_filters_provider(): array { return [ 'Filter content' => ['content', 'Cool', 'note:content', [ 'note:content_operator' => text::IS_EQUAL_TO, 'note:content_value' => 'Cool', ], true], 'Filter content (no match)' => ['content', 'Cool', 'note:content', [ 'note:content_operator' => text::DOES_NOT_CONTAIN, 'note:content_value' => 'Cool', ], false], 'Filter publish state' => ['publishstate', 'site', 'note:publishstate', [ 'note:publishstate_operator' => select::EQUAL_TO, 'note:publishstate_value' => 'site', ], true], 'Filter publish state (no match)' => ['publishstate', 'site', 'note:publishstate', [ 'note:publishstate_operator' => select::EQUAL_TO, 'note:publishstate_value' => 'public', ], false], 'Filter time created' => ['created', 1654038000, 'note:timecreated', [ 'note:timecreated_operator' => date::DATE_RANGE, 'note:timecreated_from' => 1622502000, ], true], 'Filter time created (no match)' => ['created', 1654038000, 'note:timecreated', [ 'note:timecreated_operator' => date::DATE_RANGE, 'note:timecreated_to' => 1622502000, ], false], 'Filter time modified' => ['lastmodified', 1654038000, 'note:timemodified', [ 'note:timemodified_operator' => date::DATE_RANGE, 'note:timemodified_from' => 1622502000, ], true], 'Filter time modified (no match)' => ['lastmodified', 1654038000, 'note:timemodified', [ 'note:timemodified_operator' => date::DATE_RANGE, 'note:timemodified_to' => 1622502000, ], false], ]; } /** * Test datasource filters * * @param string $field * @param mixed $value * @param string $filtername * @param array $filtervalues * @param bool $expectmatch * * @dataProvider datasource_filters_provider */ public function test_datasource_filters( string $field, $value, string $filtername, array $filtervalues, bool $expectmatch ): void { global $DB; $this->resetAfterTest(); $recipient = $this->getDataGenerator()->create_user(); /** @var core_notes_generator $notesgenerator */ $notesgenerator = $this->getDataGenerator()->get_plugin_generator('core_notes'); // Create default note, then manually override one of it's properties to use for filtering. $note = $notesgenerator->create_instance(['courseid' => SITEID, 'userid' => $recipient->id]); $DB->set_field('post', $field, $value, ['id' => $note->id]); /** @var core_reportbuilder_generator $generator */ $generator = $this->getDataGenerator()->get_plugin_generator('core_reportbuilder'); // Create report containing single recipient column, and given filter. $report = $generator->create_report(['name' => 'Notes', 'source' => notes::class, 'default' => 0]); $generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'recipient:fullname']); // Add filter, set it's values. $generator->create_filter(['reportid' => $report->get('id'), 'uniqueidentifier' => $filtername]); $content = $this->get_custom_report_content($report->get('id'), 0, $filtervalues); if ($expectmatch) { $this->assertCount(1, $content); $this->assertEquals(fullname($recipient), reset($content[0])); } else { $this->assertEmpty($content); } } /** * Stress test datasource * * In order to execute this test PHPUNIT_LONGTEST should be defined as true in phpunit.xml or directly in config.php */ public function test_stress_datasource(): void { if (!PHPUNIT_LONGTEST) { $this->markTestSkipped('PHPUNIT_LONGTEST is not defined'); } $this->resetAfterTest(); $recipient = $this->getDataGenerator()->create_user(); /** @var core_notes_generator $notesgenerator */ $notesgenerator = $this->getDataGenerator()->get_plugin_generator('core_notes'); $notesgenerator->create_instance(['courseid' => SITEID, 'userid' => $recipient->id]); $this->datasource_stress_test_columns(notes::class); $this->datasource_stress_test_columns_aggregation(notes::class); $this->datasource_stress_test_conditions(notes::class, 'note:content'); } } cohorts.php 0000644 00000007101 15152154603 0006737 0 ustar 00 <?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_cohort\reportbuilder\datasource; use core_cohort\reportbuilder\local\entities\{cohort, cohort_member}; use core_reportbuilder\datasource; use core_reportbuilder\local\entities\user; /** * Cohorts datasource * * @package core_cohort * @copyright 2021 Paul Holden <paulh@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class cohorts extends datasource { /** * Return user friendly name of the datasource * * @return string */ public static function get_name(): string { return get_string('cohorts', 'core_cohort'); } /** * Initialise report */ protected function initialise(): void { $cohortentity = new cohort(); $cohorttablealias = $cohortentity->get_table_alias('cohort'); $this->set_main_table('cohort', $cohorttablealias); $this->add_entity($cohortentity); // Join the cohort member entity to the cohort entity. $cohortmemberentity = new cohort_member(); $cohortmembertablealias = $cohortmemberentity->get_table_alias('cohort_members'); $this->add_entity($cohortmemberentity ->add_join("LEFT JOIN {cohort_members} {$cohortmembertablealias} ON {$cohortmembertablealias}.cohortid = {$cohorttablealias}.id") ); // Join the user entity to the cohort member entity. $userentity = new user(); $usertablealias = $userentity->get_table_alias('user'); $this->add_entity($userentity ->add_joins($cohortmemberentity->get_joins()) ->add_join("LEFT JOIN {user} {$usertablealias} ON {$usertablealias}.id = {$cohortmembertablealias}.userid") ); // Add all columns/filters/conditions from entities to be available in custom reports. $this->add_all_from_entities(); } /** * Return the columns that will be added to the report as part of default setup * * @return string[] */ public function get_default_columns(): array { return [ 'cohort:name', 'cohort:context', 'cohort:idnumber', 'cohort:description', ]; } /** * Return the filters that will be added to the report once is created * * @return string[] */ public function get_default_filters(): array { return ['cohort:context', 'cohort:name']; } /** * Return the conditions that will be added to the report once is created * * @return string[] */ public function get_default_conditions(): array { return []; } /** * Return the default sorting that will be added to the report once it is created * * @return array|int[] */ public function get_default_column_sorting(): array { return [ 'cohort:name' => SORT_ASC, ]; } } tags.php 0000644 00000007154 15152577144 0006235 0 ustar 00 <?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_tag\reportbuilder\datasource; use lang_string; use core_reportbuilder\datasource; use core_reportbuilder\local\entities\user; use core_tag\reportbuilder\local\entities\{collection, tag, instance}; /** * Tags datasource * * @package core_tag * @copyright 2022 Paul Holden <paulh@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class tags extends datasource { /** * Return user friendly name of the report source * * @return string */ public static function get_name(): string { return get_string('tags', 'core_tag'); } /** * Initialise report */ protected function initialise(): void { $collectionentity = new collection(); $collectionalias = $collectionentity->get_table_alias('tag_coll'); $this->set_main_table('tag_coll', $collectionalias); $this->add_entity($collectionentity); // Join tag entity to collection. $tagentity = new tag(); $tagalias = $tagentity->get_table_alias('tag'); $this->add_entity($tagentity ->add_join("LEFT JOIN {tag} {$tagalias} ON {$tagalias}.tagcollid = {$collectionalias}.id") ); // Join instance entity to tag. $instanceentity = new instance(); $instancealias = $instanceentity->get_table_alias('tag_instance'); $this->add_entity($instanceentity ->add_joins($tagentity->get_joins()) ->add_join("LEFT JOIN {tag_instance} {$instancealias} ON {$instancealias}.tagid = {$tagalias}.id") ); // Join user entity to represent the tag author. $userentity = (new user()) ->set_entity_title(new lang_string('tagauthor', 'core_tag')); $useralias = $userentity->get_table_alias('user'); $this->add_entity($userentity ->add_joins($tagentity->get_joins()) ->add_join("LEFT JOIN {user} {$useralias} ON {$useralias}.id = {$tagalias}.userid") ); // Add report elements from each of the entities we added to the report. $this->add_all_from_entities(); } /** * Return the columns that will be added to the report upon creation * * @return string[] */ public function get_default_columns(): array { return [ 'collection:name', 'tag:namewithlink', 'tag:standard', 'instance:context', ]; } /** * Return the filters that will be added to the report upon creation * * @return string[] */ public function get_default_filters(): array { return [ 'tag:name', 'tag:standard', ]; } /** * Return the conditions that will be added to the report upon creation * * @return string[] */ public function get_default_conditions(): array { return [ 'collection:name', ]; } } notes.php 0000644 00000010213 15152647032 0006407 0 ustar 00 <?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_notes\reportbuilder\datasource; use lang_string; use core_reportbuilder\datasource; use core_reportbuilder\local\entities\{course, user}; use core_notes\reportbuilder\local\entities\note; defined('MOODLE_INTERNAL') || die; global $CFG; require_once("{$CFG->dirroot}/notes/lib.php"); /** * Notes datasource * * @package core_notes * @copyright 2022 Paul Holden <paulh@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class notes extends datasource { /** * Return user friendly name of the report source * * @return string */ public static function get_name(): string { return get_string('notes', 'core_notes'); } /** * Initialise report */ protected function initialise(): void { $noteentity = new note(); $postalias = $noteentity->get_table_alias('post'); $this->set_main_table('post', $postalias); $this->add_base_condition_simple("{$postalias}.module", 'notes'); $this->add_entity($noteentity); // Join the user entity to represent the note recipient. $recipiententity = (new user()) ->set_entity_name('recipient') ->set_entity_title(new lang_string('recipient', 'core_notes')); $recipientalias = $recipiententity->get_table_alias('user'); $this->add_entity($recipiententity->add_join(" LEFT JOIN {user} {$recipientalias} ON {$recipientalias}.id = {$postalias}.userid") ); // Join the user entity to represent the note author. Override all entity table aliases to avoid clash with first instance. $authorentity = (new user()) ->set_entity_name('author') ->set_entity_title(new lang_string('author', 'core_notes')) ->set_table_aliases([ 'user' => 'au', 'context' => 'auctx', ]); $this->add_entity($authorentity->add_join(" LEFT JOIN {user} au ON au.id = {$postalias}.usermodified") ); // Join the course entity for course notes. $courseentity = new course(); $coursealias = $courseentity->get_table_alias('course'); $this->add_entity($courseentity->add_join(" LEFT JOIN {course} {$coursealias} ON {$coursealias}.id = {$postalias}.courseid AND {$postalias}.publishstate = '" . NOTES_STATE_PUBLIC . "'") ); // Add report elements from each of the entities we added to the report. $this->add_all_from_entities(); } /** * Return the columns that will be added to the report upon creation * * @return string[] */ public function get_default_columns(): array { return [ 'recipient:fullname', 'note:publishstate', 'course:fullname', 'note:content', ]; } /** * Return the filters that will be added to the report upon creation * * @return string[] */ public function get_default_filters(): array { return [ 'recipient:fullname', ]; } /** * Return the conditions that will be added to the report upon creation * * @return string[] */ public function get_default_conditions(): array { return [ 'note:publishstate', 'course:fullname', 'recipient:fullname', ]; } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | ���֧ߧ֧�ѧ�ڧ� ����ѧߧڧ��: 0 |
proxy
|
phpinfo
|
���ѧ����ۧܧ�