mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 14:03:52 +01:00
MDL-72588 reportbuilder: define schema/models for report audiences.
This commit is contained in:
parent
2b2897bf10
commit
b2dd94ab8b
@ -124,6 +124,10 @@ $string['newreport'] = 'New report';
|
|||||||
$string['noconditions'] = 'There are no conditions selected';
|
$string['noconditions'] = 'There are no conditions selected';
|
||||||
$string['nofilters'] = 'There are no filters selected';
|
$string['nofilters'] = 'There are no filters selected';
|
||||||
$string['nosortablecolumns'] = 'There are no sortable columns';
|
$string['nosortablecolumns'] = 'There are no sortable columns';
|
||||||
|
$string['privacy:metadata:audience'] = 'Report audience definitions';
|
||||||
|
$string['privacy:metadata:audience:classname'] = 'Class used by the audience';
|
||||||
|
$string['privacy:metadata:audience:usercreated'] = 'The ID of the user who created the audience';
|
||||||
|
$string['privacy:metadata:audience:usermodified'] = 'The ID of the user who last modified the audience';
|
||||||
$string['privacy:metadata:column'] = 'Report column definitions';
|
$string['privacy:metadata:column'] = 'Report column definitions';
|
||||||
$string['privacy:metadata:column:uniqueidentifier'] = 'Unique identifier of the column';
|
$string['privacy:metadata:column:uniqueidentifier'] = 'Unique identifier of the column';
|
||||||
$string['privacy:metadata:column:usercreated'] = 'The ID of the user who created the column';
|
$string['privacy:metadata:column:usercreated'] = 'The ID of the user who created the column';
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<XMLDB PATH="lib/db" VERSION="20211008" COMMENT="XMLDB file for core Moodle tables"
|
<XMLDB PATH="lib/db" VERSION="20211011" COMMENT="XMLDB file for core Moodle tables"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
|
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
|
||||||
>
|
>
|
||||||
@ -4445,5 +4445,23 @@
|
|||||||
<KEY NAME="usermodified" TYPE="foreign" FIELDS="usermodified" REFTABLE="user" REFFIELDS="id"/>
|
<KEY NAME="usermodified" TYPE="foreign" FIELDS="usermodified" REFTABLE="user" REFFIELDS="id"/>
|
||||||
</KEYS>
|
</KEYS>
|
||||||
</TABLE>
|
</TABLE>
|
||||||
|
<TABLE NAME="reportbuilder_audience" COMMENT="Defines report audience">
|
||||||
|
<FIELDS>
|
||||||
|
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||||
|
<FIELD NAME="reportid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
||||||
|
<FIELD NAME="classname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
|
||||||
|
<FIELD NAME="configdata" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
|
||||||
|
<FIELD NAME="usercreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
|
<FIELD NAME="usermodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
|
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
|
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||||
|
</FIELDS>
|
||||||
|
<KEYS>
|
||||||
|
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||||
|
<KEY NAME="reportid" TYPE="foreign" FIELDS="reportid" REFTABLE="reportbuilder_report" REFFIELDS="id"/>
|
||||||
|
<KEY NAME="usercreated" TYPE="foreign" FIELDS="usercreated" REFTABLE="user" REFFIELDS="id"/>
|
||||||
|
<KEY NAME="usermodified" TYPE="foreign" FIELDS="usermodified" REFTABLE="user" REFFIELDS="id"/>
|
||||||
|
</KEYS>
|
||||||
|
</TABLE>
|
||||||
</TABLES>
|
</TABLES>
|
||||||
</XMLDB>
|
</XMLDB>
|
||||||
|
@ -3010,5 +3010,35 @@ function xmldb_main_upgrade($oldversion) {
|
|||||||
upgrade_main_savepoint(true, 2021101900.01);
|
upgrade_main_savepoint(true, 2021101900.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($oldversion < 2021102600.01) {
|
||||||
|
|
||||||
|
// Define table reportbuilder_audience to be created.
|
||||||
|
$table = new xmldb_table('reportbuilder_audience');
|
||||||
|
|
||||||
|
// Adding fields to table reportbuilder_audience.
|
||||||
|
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||||
|
$table->add_field('reportid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
|
||||||
|
$table->add_field('classname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||||||
|
$table->add_field('configdata', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
|
||||||
|
$table->add_field('usercreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||||
|
$table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||||
|
$table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||||
|
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||||
|
|
||||||
|
// Adding keys to table reportbuilder_audience.
|
||||||
|
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
|
||||||
|
$table->add_key('reportid', XMLDB_KEY_FOREIGN, ['reportid'], 'reportbuilder_report', ['id']);
|
||||||
|
$table->add_key('usercreated', XMLDB_KEY_FOREIGN, ['usercreated'], 'user', ['id']);
|
||||||
|
$table->add_key('usermodified', XMLDB_KEY_FOREIGN, ['usermodified'], 'user', ['id']);
|
||||||
|
|
||||||
|
// Conditionally launch create table for reportbuilder_audience.
|
||||||
|
if (!$dbman->table_exists($table)) {
|
||||||
|
$dbman->create_table($table);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main savepoint reached.
|
||||||
|
upgrade_main_savepoint(true, 2021102600.01);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
86
reportbuilder/classes/local/models/audience.php
Normal file
86
reportbuilder/classes/local/models/audience.php
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
<?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_reportbuilder\local\models;
|
||||||
|
|
||||||
|
use lang_string;
|
||||||
|
use core\persistent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Persistent class to represent a report audience
|
||||||
|
*
|
||||||
|
* @package core_reportbuilder
|
||||||
|
* @copyright 2021 David Matamoros <davidmc@moodle.com>
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class audience extends persistent {
|
||||||
|
|
||||||
|
/** @var string Table name */
|
||||||
|
public const TABLE = 'reportbuilder_audience';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the definition of the properties of this model.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected static function define_properties() : array {
|
||||||
|
return [
|
||||||
|
'reportid' => [
|
||||||
|
'type' => PARAM_INT,
|
||||||
|
],
|
||||||
|
'classname' => [
|
||||||
|
'type' => PARAM_TEXT,
|
||||||
|
],
|
||||||
|
'configdata' => [
|
||||||
|
'type' => PARAM_RAW,
|
||||||
|
'default' => '{}',
|
||||||
|
],
|
||||||
|
'usercreated' => [
|
||||||
|
'type' => PARAM_INT,
|
||||||
|
'default' => static function(): int {
|
||||||
|
global $USER;
|
||||||
|
|
||||||
|
return (int) $USER->id;
|
||||||
|
},
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate reportid property
|
||||||
|
*
|
||||||
|
* @param int $reportid
|
||||||
|
* @return bool|lang_string
|
||||||
|
*/
|
||||||
|
protected function validate_reportid(int $reportid) {
|
||||||
|
if (!report::record_exists($reportid)) {
|
||||||
|
return new lang_string('invaliddata', 'error');
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the report this audience belongs to
|
||||||
|
*
|
||||||
|
* @return report
|
||||||
|
*/
|
||||||
|
public function get_report(): report {
|
||||||
|
return new report($this->get('reportid'));
|
||||||
|
}
|
||||||
|
}
|
@ -118,6 +118,11 @@ class report extends persistent {
|
|||||||
foreach (filter::get_records($reportparams) as $filter) {
|
foreach (filter::get_records($reportparams) as $filter) {
|
||||||
$filter->delete();
|
$filter->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Audiences.
|
||||||
|
foreach (audience::get_records($reportparams) as $audience) {
|
||||||
|
$audience->delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,6 +21,7 @@ namespace core_reportbuilder\privacy;
|
|||||||
use core_privacy\local\metadata\collection;
|
use core_privacy\local\metadata\collection;
|
||||||
use core_privacy\local\request\writer;
|
use core_privacy\local\request\writer;
|
||||||
use core_reportbuilder\local\helpers\user_filter_manager;
|
use core_reportbuilder\local\helpers\user_filter_manager;
|
||||||
|
use core_reportbuilder\local\models\audience;
|
||||||
use core_reportbuilder\local\models\column;
|
use core_reportbuilder\local\models\column;
|
||||||
use core_reportbuilder\local\models\report;
|
use core_reportbuilder\local\models\report;
|
||||||
use core_reportbuilder\local\models\filter;
|
use core_reportbuilder\local\models\filter;
|
||||||
@ -61,6 +62,12 @@ class provider implements
|
|||||||
'usermodified' => 'privacy:metadata:filter:usermodified',
|
'usermodified' => 'privacy:metadata:filter:usermodified',
|
||||||
], 'privacy:metadata:filter');
|
], 'privacy:metadata:filter');
|
||||||
|
|
||||||
|
$collection->add_database_table(audience::TABLE, [
|
||||||
|
'classname' => 'privacy:metadata:audience:classname',
|
||||||
|
'usercreated' => 'privacy:metadata:audience:usercreated',
|
||||||
|
'usermodified' => 'privacy:metadata:audience:usermodified',
|
||||||
|
], 'privacy:metadata:audience');
|
||||||
|
|
||||||
$collection->add_user_preference('core_reportbuilder', 'privacy:metadata:preference:reportfilter');
|
$collection->add_user_preference('core_reportbuilder', 'privacy:metadata:preference:reportfilter');
|
||||||
|
|
||||||
return $collection;
|
return $collection;
|
||||||
|
@ -26,6 +26,7 @@ use core_privacy\local\request\writer;
|
|||||||
use core_privacy\tests\provider_testcase;
|
use core_privacy\tests\provider_testcase;
|
||||||
use core_reportbuilder\manager;
|
use core_reportbuilder\manager;
|
||||||
use core_reportbuilder\local\helpers\user_filter_manager;
|
use core_reportbuilder\local\helpers\user_filter_manager;
|
||||||
|
use core_reportbuilder\local\models\audience;
|
||||||
use core_reportbuilder\local\models\column;
|
use core_reportbuilder\local\models\column;
|
||||||
use core_reportbuilder\local\models\filter;
|
use core_reportbuilder\local\models\filter;
|
||||||
use core_reportbuilder\local\models\report;
|
use core_reportbuilder\local\models\report;
|
||||||
@ -47,7 +48,7 @@ class provider_test extends provider_testcase {
|
|||||||
$collection = new collection('core_reportbuilder');
|
$collection = new collection('core_reportbuilder');
|
||||||
$metadata = provider::get_metadata($collection)->get_collection();
|
$metadata = provider::get_metadata($collection)->get_collection();
|
||||||
|
|
||||||
$this->assertCount(4, $metadata);
|
$this->assertCount(5, $metadata);
|
||||||
|
|
||||||
$this->assertInstanceOf(database_table::class, $metadata[0]);
|
$this->assertInstanceOf(database_table::class, $metadata[0]);
|
||||||
$this->assertEquals(report::TABLE, $metadata[0]->get_name());
|
$this->assertEquals(report::TABLE, $metadata[0]->get_name());
|
||||||
@ -58,7 +59,10 @@ class provider_test extends provider_testcase {
|
|||||||
$this->assertInstanceOf(database_table::class, $metadata[2]);
|
$this->assertInstanceOf(database_table::class, $metadata[2]);
|
||||||
$this->assertEquals(filter::TABLE, $metadata[2]->get_name());
|
$this->assertEquals(filter::TABLE, $metadata[2]->get_name());
|
||||||
|
|
||||||
$this->assertInstanceOf(user_preference::class, $metadata[3]);
|
$this->assertInstanceOf(database_table::class, $metadata[3]);
|
||||||
|
$this->assertEquals(audience::TABLE, $metadata[3]->get_name());
|
||||||
|
|
||||||
|
$this->assertInstanceOf(user_preference::class, $metadata[4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
$version = 2021102600.00; // YYYYMMDD = weekly release date of this DEV branch.
|
$version = 2021102600.01; // YYYYMMDD = weekly release date of this DEV branch.
|
||||||
// RR = release increments - 00 in DEV branches.
|
// RR = release increments - 00 in DEV branches.
|
||||||
// .XX = incremental changes.
|
// .XX = incremental changes.
|
||||||
$release = '4.0dev+ (Build: 20211026)'; // Human-friendly version name
|
$release = '4.0dev+ (Build: 20211026)'; // Human-friendly version name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user