Skip to content

Commit

Permalink
Merge branch 'MDL-72826' of git://github.com/paulholden/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Nov 19, 2021
2 parents 2db434e + be11216 commit 357ddca
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 8 deletions.
2 changes: 2 additions & 0 deletions lang/en/reportbuilder.php
Expand Up @@ -189,6 +189,8 @@
$string['timeadded'] = 'Time added';
$string['timecreated'] = 'Time created';
$string['timemodified'] = 'Time modified';
$string['uniquerows'] = 'Show unique rows';
$string['uniquerows_help'] = 'Show only unique rows in the report. Note this setting has no effect if any report columns are being aggregated';
$string['userfullnamewithlink'] = 'Full name with link';
$string['userfullnamewithpicture'] = 'Full name with picture';
$string['userfullnamewithpicturelink'] = 'Full name with picture and link';
Expand Down
1 change: 1 addition & 0 deletions lib/db/install.xml
Expand Up @@ -4386,6 +4386,7 @@
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="source" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="type" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="uniquerows" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="conditiondata" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="settingsdata" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
Expand Down
15 changes: 15 additions & 0 deletions lib/db/upgrade.php
Expand Up @@ -3156,5 +3156,20 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2021111700.00);
}

if ($oldversion < 2021111700.01) {

// Define field uniquerows to be added to reportbuilder_report.
$table = new xmldb_table('reportbuilder_report');
$field = new xmldb_field('uniquerows', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'type');

// Conditionally launch add field uniquerows.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// Main savepoint reached.
upgrade_main_savepoint(true, 2021111700.01);
}

return true;
}
3 changes: 3 additions & 0 deletions reportbuilder/classes/form/report.php
Expand Up @@ -111,6 +111,9 @@ public function definition() {
$mform->setDefault('includedefaultsetup', 1);
$mform->addHelpButton('includedefaultsetup', 'includedefaultsetup', 'core_reportbuilder');
}

$mform->addElement('advcheckbox', 'uniquerows', get_string('uniquerows', 'core_reportbuilder'));
$mform->addHelpButton('uniquerows', 'uniquerows', 'core_reportbuilder');
}

/**
Expand Down
6 changes: 4 additions & 2 deletions reportbuilder/classes/local/helpers/report.php
Expand Up @@ -75,8 +75,10 @@ public static function update_report(stdClass $data): report_model {
throw new invalid_parameter_exception('Invalid report');
}

$report->set('name', trim($data->name))
->update();
$report->set_many([
'name' => trim($data->name),
'uniquerows' => $data->uniquerows,
])->update();

return $report;
}
Expand Down
4 changes: 4 additions & 0 deletions reportbuilder/classes/local/models/report.php
Expand Up @@ -60,6 +60,10 @@ protected static function define_properties(): array {
base::TYPE_SYSTEM_REPORT,
],
],
'uniquerows' => [
'type' => PARAM_BOOL,
'default' => false,
],
'conditiondata' => [
'type' => PARAM_RAW,
'null' => NULL_ALLOWED,
Expand Down
8 changes: 6 additions & 2 deletions reportbuilder/classes/table/custom_report_table.php
Expand Up @@ -62,7 +62,7 @@ public function __construct(string $uniqueid, string $download = '') {

$this->define_baseurl(new moodle_url('/reportbuilder/edit.php', ['id' => $matches['id']]));

// Load the report persistent, and accompanying system report instance.
// Load the report persistent, and accompanying report instance.
$this->persistent = new report($matches['id']);
$this->report = manager::get_report_from_persistent($this->persistent);

Expand Down Expand Up @@ -90,16 +90,20 @@ public function __construct(string $uniqueid, string $download = '') {
$aggregatedcolumns = array_filter($columns, static function(column $column): bool {
return !empty($column->get_aggregation());
});

// Also take account of the report setting to show unique rows (only if no columns are being aggregated).
$hasaggregatedcolumns = !empty($aggregatedcolumns);
$showuniquerows = !$hasaggregatedcolumns && $this->persistent->get('uniquerows');

$columnheaders = [];
$columnsattributes = [];
foreach ($columns as $column) {
$columnheading = $column->get_persistent()->get_formatted_heading($this->report->get_context());
$columnheaders[$column->get_column_alias()] = $columnheading !== '' ? $columnheading : $column->get_title();

// We need to determine for each column whether we should group by it's fields, to support aggregation.
$columnaggregation = $column->get_aggregation();
if ($hasaggregatedcolumns && empty($columnaggregation)) {
if ($showuniquerows || ($hasaggregatedcolumns && empty($columnaggregation))) {
$groupby = array_merge($groupby, $column->get_groupby_sql());
}

Expand Down
28 changes: 25 additions & 3 deletions reportbuilder/tests/behat/columnaggregationeditor.feature
Expand Up @@ -65,9 +65,9 @@ Feature: Manage custom report columns aggregation
Then I should see "Aggregated column 'Last access'"
And I should see "<output>" in the "Richie" "table_row"
Examples:
| aggregation | output |
| Count | 3 |
| Count distinct | 2 |
| aggregation | output |
| Count | 3 |
| Count distinct | 2 |
| Maximum | ##2 days ago##%A, %d %B %Y## |
| Minimum | ##3 days ago##%A, %d %B %Y## |

Expand All @@ -94,3 +94,25 @@ Feature: Manage custom report columns aggregation
| Minimum | No |
| Percentage | 66.7% |
| Sum | 2 |

Scenario: Show unique report rows
Given the following "core_reportbuilder > Reports" exist:
| name | source | default | uniquerows |
| My report | core_user\reportbuilder\datasource\users | 0 | 1 |
And the following "core_reportbuilder > Columns" exist:
| report | uniqueidentifier |
| My report | user:firstname |
| My report | user:lastname |
When I am on the "My report" "reportbuilder > Editor" page logged in as "admin"
Then the following should exist in the "reportbuilder-table" table:
| -1- | -2- |
| Admin | User |
| Ben | Richie |
| Bill | Richie |
# Assert there is no 4th row (duplicate Bill Richie) because we're showing unique rows.
And "//table[@data-region='reportbuilder-table']/tbody/tr[not(@class = 'emptyrow')][4]" "xpath_element" should not exist
And I set the "First name" column aggregation to "Comma separated values"
And the following should exist in the "reportbuilder-table" table:
| -1- | -2- |
| Admin | User |
| Ben, Bill, Bill | Richie |
2 changes: 1 addition & 1 deletion version.php
Expand Up @@ -29,7 +29,7 @@

defined('MOODLE_INTERNAL') || die();

$version = 2021111700.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2021111700.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.0dev+ (Build: 20211116)'; // Human-friendly version name
Expand Down

0 comments on commit 357ddca

Please sign in to comment.