forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-83426 mod_feedback: Migrate entries table to RB
Co-authored-by: Paul Holden <[email protected]>
- Loading branch information
1 parent
0d5c6d9
commit fa561e8
Showing
6 changed files
with
584 additions
and
35 deletions.
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
mod/feedback/classes/reportbuilder/local/entities/question.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<?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 mod_feedback\reportbuilder\local\entities; | ||
|
||
use lang_string; | ||
use stdClass; | ||
use core_reportbuilder\local\entities\base; | ||
use core_reportbuilder\local\filters\text; | ||
use core_reportbuilder\local\report\{column, filter}; | ||
|
||
/** | ||
* Question entity | ||
* | ||
* @package mod_feedback | ||
* @copyright 2024 Mikel Martín <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class question extends base { | ||
|
||
/** | ||
* Database tables that this entity uses and their default aliases | ||
* | ||
* @return array | ||
*/ | ||
protected function get_default_tables(): array { | ||
return [ | ||
'feedback_item', | ||
]; | ||
} | ||
|
||
/** | ||
* The default title for this entity in the list of columns/conditions/filters in the report builder | ||
* | ||
* @return lang_string | ||
*/ | ||
protected function get_default_entity_title(): lang_string { | ||
return new lang_string('question', 'mod_feedback'); | ||
} | ||
|
||
/** | ||
* Initialise the entity | ||
* | ||
* @return base | ||
*/ | ||
public function initialise(): base { | ||
$columns = $this->get_all_columns(); | ||
foreach ($columns as $column) { | ||
$this->add_column($column); | ||
} | ||
// All the filters defined by the entity can also be used as conditions. | ||
$filters = $this->get_all_filters(); | ||
foreach ($filters as $filter) { | ||
$this | ||
->add_filter($filter) | ||
->add_condition($filter); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Returns list of all available columns | ||
* | ||
* @return column[] | ||
*/ | ||
protected function get_all_columns(): array { | ||
$questionalias = $this->get_table_alias('feedback_item'); | ||
|
||
// Name. | ||
$columnns[] = (new column( | ||
'name', | ||
new lang_string('name'), | ||
$this->get_entity_name() | ||
)) | ||
->add_joins($this->get_joins()) | ||
->set_type(column::TYPE_TEXT) | ||
->add_field("{$questionalias}.label") | ||
->add_field("{$questionalias}.name") | ||
->set_is_sortable(true) | ||
->add_callback(static function(stdClass $row): string { | ||
if (strval($row->label) !== '') { | ||
return get_string( | ||
'nameandlabelformat', | ||
'mod_feedback', | ||
(object)['label' => format_string($row->label), 'name' => $row->name] | ||
); | ||
} | ||
else { | ||
return format_string($row->name); | ||
} | ||
}); | ||
return $columnns; | ||
} | ||
|
||
/** | ||
* Return list of all available filters | ||
* | ||
* @return filter[] | ||
*/ | ||
protected function get_all_filters(): array { | ||
global $DB; | ||
|
||
$questionalias = $this->get_table_alias('feedback_item'); | ||
|
||
// Name filter. | ||
$filters[] = (new filter( | ||
text::class, | ||
'name', | ||
new lang_string('name'), | ||
$this->get_entity_name(), | ||
"{$questionalias}.name" | ||
)) | ||
->add_joins($this->get_joins()); | ||
|
||
return $filters; | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
mod/feedback/classes/reportbuilder/local/entities/question_value.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?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 mod_feedback\reportbuilder\local\entities; | ||
|
||
use lang_string; | ||
use core_reportbuilder\local\entities\base; | ||
use core_reportbuilder\local\filters\text; | ||
use core_reportbuilder\local\report\{column, filter}; | ||
|
||
/** | ||
* Question value entity | ||
* | ||
* @package mod_feedback | ||
* @copyright 2024 Mikel Martín <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class question_value extends base { | ||
|
||
/** | ||
* Database tables that this entity uses and their default aliases | ||
* | ||
* @return array | ||
*/ | ||
protected function get_default_tables(): array { | ||
return [ | ||
'feedback_value', | ||
]; | ||
} | ||
|
||
/** | ||
* The default title for this entity in the list of columns/conditions/filters in the report builder | ||
* | ||
* @return lang_string | ||
*/ | ||
protected function get_default_entity_title(): lang_string { | ||
return new lang_string('questionvalue', 'mod_feedback'); | ||
} | ||
|
||
/** | ||
* Initialise the entity | ||
* | ||
* @return base | ||
*/ | ||
public function initialise(): base { | ||
$columns = $this->get_all_columns(); | ||
foreach ($columns as $column) { | ||
$this->add_column($column); | ||
} | ||
// All the filters defined by the entity can also be used as conditions. | ||
$filters = $this->get_all_filters(); | ||
foreach ($filters as $filter) { | ||
$this | ||
->add_filter($filter) | ||
->add_condition($filter); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Returns list of all available columns | ||
* | ||
* @return column[] | ||
*/ | ||
protected function get_all_columns(): array { | ||
$questionvaluealias = $this->get_table_alias('feedback_value'); | ||
|
||
// Value. | ||
$columnns[] = (new column( | ||
'value', | ||
new lang_string('value', 'mod_feedback'), | ||
$this->get_entity_name() | ||
)) | ||
->add_joins($this->get_joins()) | ||
->set_type(column::TYPE_TEXT) | ||
->add_field("{$questionvaluealias}.value") | ||
->set_is_sortable(true); | ||
|
||
return $columnns; | ||
} | ||
|
||
/** | ||
* Return list of all available filters | ||
* | ||
* @return filter[] | ||
*/ | ||
protected function get_all_filters(): array { | ||
global $DB; | ||
|
||
$questionvaluealias = $this->get_table_alias('feedback_value'); | ||
|
||
// Value filter. | ||
$filters[] = (new filter( | ||
text::class, | ||
'value', | ||
new lang_string('value', 'mod_feedback'), | ||
$this->get_entity_name(), | ||
"{$questionvaluealias}.value" | ||
)) | ||
->add_joins($this->get_joins()); | ||
|
||
return $filters; | ||
} | ||
} |
123 changes: 123 additions & 0 deletions
123
mod/feedback/classes/reportbuilder/local/entities/response.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<?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 mod_feedback\reportbuilder\local\entities; | ||
|
||
use lang_string; | ||
use core_reportbuilder\local\entities\base; | ||
use core_reportbuilder\local\filters\date; | ||
use core_reportbuilder\local\helpers\format; | ||
use core_reportbuilder\local\report\{column, filter}; | ||
|
||
/** | ||
* Response entity | ||
* | ||
* @package mod_feedback | ||
* @copyright 2024 Mikel Martín <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class response extends base { | ||
|
||
/** | ||
* Database tables that this entity uses and their default aliases | ||
* | ||
* @return array | ||
*/ | ||
protected function get_default_tables(): array { | ||
return [ | ||
'feedback_completed', | ||
]; | ||
} | ||
|
||
/** | ||
* The default title for this entity in the list of columns/conditions/filters in the report builder | ||
* | ||
* @return lang_string | ||
*/ | ||
protected function get_default_entity_title(): lang_string { | ||
return new lang_string('responses', 'mod_feedback'); | ||
} | ||
|
||
/** | ||
* Initialise the entity | ||
* | ||
* @return base | ||
*/ | ||
public function initialise(): base { | ||
$columns = $this->get_all_columns(); | ||
foreach ($columns as $column) { | ||
$this->add_column($column); | ||
} | ||
// All the filters defined by the entity can also be used as conditions. | ||
$filters = $this->get_all_filters(); | ||
foreach ($filters as $filter) { | ||
$this | ||
->add_filter($filter) | ||
->add_condition($filter); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Returns list of all available columns | ||
* | ||
* @return column[] | ||
*/ | ||
protected function get_all_columns(): array { | ||
$responsealias = $this->get_table_alias('feedback_completed'); | ||
|
||
// Date column. | ||
$columnns[] = (new column( | ||
'timemodified', | ||
new lang_string('date'), | ||
$this->get_entity_name() | ||
)) | ||
->add_joins($this->get_joins()) | ||
->set_type(column::TYPE_TIMESTAMP) | ||
->add_fields("{$responsealias}.timemodified, {$responsealias}.anonymous_response") | ||
->set_is_sortable(true) | ||
->add_callback([format::class, 'userdate']) | ||
->add_callback(fn($value, $row) => $row->anonymous_response == FEEDBACK_ANONYMOUS_YES ? '' : $value); | ||
|
||
return $columnns; | ||
} | ||
|
||
/** | ||
* Return list of all available filters | ||
* | ||
* @return filter[] | ||
*/ | ||
protected function get_all_filters(): array { | ||
global $DB; | ||
|
||
$responsealias = $this->get_table_alias('feedback_completed'); | ||
|
||
// Date filter. | ||
$filters[] = (new filter( | ||
date::class, | ||
'timemodified', | ||
new lang_string('date'), | ||
$this->get_entity_name(), | ||
"{$responsealias}.timemodified" | ||
)) | ||
->add_joins($this->get_joins()); | ||
|
||
return $filters; | ||
} | ||
} |
Oops, something went wrong.