Skip to content

Commit

Permalink
Merge branch 'MDL-74497-master' of https://github.com/dravek/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed May 18, 2022
2 parents c3f2753 + 5e68da7 commit fa48ab3
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 30 deletions.
16 changes: 2 additions & 14 deletions cohort/classes/reportbuilder/datasource/cohorts.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,8 @@ protected function initialise(): void {

$this->add_entity($userentity->add_joins([$cohortmemberjoin, $userjoin]));

// Add all columns from entities to be available in custom reports.
$this->add_columns_from_entity($cohortentity->get_entity_name());
$this->add_columns_from_entity($cohortmemberentity->get_entity_name());
$this->add_columns_from_entity($userentity->get_entity_name());

// Add all filters from entities to be available in custom reports.
$this->add_filters_from_entity($cohortentity->get_entity_name());
$this->add_filters_from_entity($cohortmemberentity->get_entity_name());
$this->add_filters_from_entity($userentity->get_entity_name());

// Add all conditions from entities to be available in custom reports.
$this->add_conditions_from_entity($cohortentity->get_entity_name());
$this->add_conditions_from_entity($cohortmemberentity->get_entity_name());
$this->add_conditions_from_entity($userentity->get_entity_name());
// Add all columns/filters/conditions from entities to be available in custom reports.
$this->add_all_from_entities();
}

/**
Expand Down
13 changes: 2 additions & 11 deletions course/classes/reportbuilder/datasource/courses.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,8 @@ protected function initialise(): void {
->add_join("JOIN {course_categories} {$coursecattablealias}
ON {$coursecattablealias}.id = {$coursetablealias}.category"));

// Add all columns from entities to be available in custom reports.
$this->add_columns_from_entity($coursecatentity->get_entity_name());
$this->add_columns_from_entity($courseentity->get_entity_name());

// Add all filters from entities to be available in custom reports.
$this->add_filters_from_entity($coursecatentity->get_entity_name());
$this->add_filters_from_entity($courseentity->get_entity_name());

// Add all conditions from entities to be available in custom reports.
$this->add_conditions_from_entity($coursecatentity->get_entity_name());
$this->add_conditions_from_entity($courseentity->get_entity_name());
// Add all columns/filters/conditions from entities to be available in custom reports.
$this->add_all_from_entities();
}

/**
Expand Down
20 changes: 20 additions & 0 deletions reportbuilder/classes/datasource.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,24 @@ public function get_active_conditions(): array {

return $conditions;
}

/**
* Adds all columns/filters/conditions from the given entity to the report at once
*
* @param string $entityname
*/
final protected function add_all_from_entity(string $entityname): void {
$this->add_columns_from_entity($entityname);
$this->add_filters_from_entity($entityname);
$this->add_conditions_from_entity($entityname);
}

/**
* Adds all columns/filters/conditions from all the entities added to the report at once
*/
final protected function add_all_from_entities(): void {
foreach ($this->get_entities() as $entity) {
$this->add_all_from_entity($entity->get_entity_name());
}
}
}
9 changes: 9 additions & 0 deletions reportbuilder/classes/local/report/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,15 @@ final protected function get_entity(string $name): entity_base {
return $this->entities[$name];
}

/**
* Returns the list of all the entities added to the report
*
* @return entity_base[]
*/
final protected function get_entities(): array {
return $this->entities;
}

/**
* Define a new entity for the report
*
Expand Down
5 changes: 4 additions & 1 deletion reportbuilder/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ Information provided here is intended especially for developers.

=== 4.1 ===
* 'set_default_per_page' and 'get_default_per_page' methods have been added to \local\report\base class
to manage the default displayed rows per page.
to manage the default displayed rows per page.
* Added two new methods in the datasource class:
- add_all_from_entity() to add all columns/filters/conditions from the given entity to the report at once
- add_all_from_entities() to add all columns/filters/conditions from all the entities added to the report at once
6 changes: 2 additions & 4 deletions user/classes/reportbuilder/datasource/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,11 @@ protected function initialise(): void {
$userparamguest => $CFG->siteguest,
]);

// Add all columns from entities to be available in custom reports.
$this->add_entity($userentity);

// Add all columns/filters/conditions from entities to be available in custom reports.
$userentityname = $userentity->get_entity_name();
$this->add_columns_from_entity($userentityname);
$this->add_filters_from_entity($userentityname);
$this->add_conditions_from_entity($userentityname);
$this->add_all_from_entity($userentityname);
}

/**
Expand Down

0 comments on commit fa48ab3

Please sign in to comment.