-
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.
- Loading branch information
Showing
10 changed files
with
416 additions
and
57 deletions.
There are no files selected for viewing
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
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
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,62 @@ | ||
<?php | ||
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>. | ||
|
||
namespace tool_enrolprofile; | ||
|
||
use core\persistent; | ||
|
||
/** | ||
* Preset persistent. | ||
* | ||
* @package tool_enrolprofile | ||
* @copyright 2024 Dmitrii Metelkin <[email protected]> | ||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class preset extends persistent { | ||
|
||
/** | ||
* Table. | ||
*/ | ||
const TABLE = 'tool_enrolprofile_presets'; | ||
|
||
/** | ||
* Return the definition of the properties of this model. | ||
* | ||
* @return array | ||
*/ | ||
protected static function define_properties() { | ||
return [ | ||
'name' => [ | ||
'type' => PARAM_TEXT, | ||
], | ||
'categories' => [ | ||
'type' => PARAM_TEXT, | ||
'default' => null, | ||
'null' => NULL_ALLOWED, | ||
], | ||
'courses' => [ | ||
'type' => PARAM_TEXT, | ||
'default' => null, | ||
'null' => NULL_ALLOWED, | ||
], | ||
'tags' => [ | ||
'type' => PARAM_TEXT, | ||
'default' => null, | ||
'null' => NULL_ALLOWED, | ||
], | ||
]; | ||
} | ||
} |
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,149 @@ | ||
<?php | ||
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>. | ||
|
||
namespace tool_enrolprofile\reportbuilder\local\entities; | ||
|
||
use core_reportbuilder\local\entities\base; | ||
use core_reportbuilder\local\report\column; | ||
use lang_string; | ||
use tool_dynamic_cohorts\rule; | ||
use tool_enrolprofile\helper; | ||
|
||
/** | ||
* Report builder entity for presets. | ||
* | ||
* @package tool_enrolprofile | ||
* @copyright 2024 Dmitrii Metelkin <[email protected]> | ||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class preset_entity extends base { | ||
|
||
/** | ||
* Returns the default table aliases. | ||
* @return array | ||
*/ | ||
protected function get_default_tables(): array { | ||
return [ | ||
'tool_enrolprofile_presets', | ||
]; | ||
} | ||
|
||
/** | ||
* Returns the default table name. | ||
* @return \lang_string | ||
*/ | ||
protected function get_default_entity_title(): lang_string { | ||
return new lang_string('preset_entity', 'tool_enrolprofile_presets'); | ||
} | ||
|
||
/** | ||
* Initialises the entity. | ||
* @return \core_reportbuilder\local\entities\base | ||
*/ | ||
public function initialise(): base { | ||
foreach ($this->get_all_columns() as $column) { | ||
$this->add_column($column); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Returns list of available columns. | ||
* | ||
* @return column[] | ||
*/ | ||
protected function get_all_columns(): array { | ||
global $DB; | ||
|
||
$alias = $this->get_table_alias('tool_enrolprofile_presets'); | ||
$categories = helper::get_categories(); | ||
$courses = helper::get_courses(); | ||
$tags = helper::get_course_tags(); | ||
|
||
$columns[] = (new column( | ||
'id', | ||
new lang_string('preset_entity.id', 'tool_enrolprofile_presets'), | ||
$this->get_entity_name() | ||
)) | ||
->add_joins($this->get_joins()) | ||
->set_type(column::TYPE_INTEGER) | ||
->add_field("{$alias}.id") | ||
->set_is_sortable(true); | ||
|
||
$columns[] = (new column( | ||
'name', | ||
new lang_string('preset_entity.name', 'tool_enrolprofile_presets'), | ||
$this->get_entity_name() | ||
)) | ||
->add_joins($this->get_joins()) | ||
->set_type(column::TYPE_TEXT) | ||
->add_field("{$alias}.name") | ||
->add_field("{$alias}.id") | ||
->set_is_sortable(true) | ||
->add_callback(function ($value, $row) { | ||
return $value; | ||
}); | ||
|
||
$columns[] = (new column( | ||
'categories', | ||
new lang_string('preset_entity.categories', 'tool_enrolprofile_presets'), | ||
$this->get_entity_name() | ||
)) | ||
->add_joins($this->get_joins()) | ||
->set_type(column::TYPE_TEXT) | ||
->add_field("{$alias}.categories") | ||
->set_is_sortable(false) | ||
->add_callback(function ($value, $row) use ($categories) { | ||
$catnames = []; | ||
$categoryids = explode(',', $value); | ||
foreach ($categoryids as $categoryid) { | ||
$catnames[] = $categories[$categoryid]->name; | ||
} | ||
|
||
return implode(', ', $catnames); | ||
}); | ||
|
||
$columns[] = (new column( | ||
'courses', | ||
new lang_string('preset_entity.courses', 'tool_enrolprofile_presets'), | ||
$this->get_entity_name() | ||
)) | ||
->add_joins($this->get_joins()) | ||
->set_type(column::TYPE_TEXT) | ||
->add_field("{$alias}.courses") | ||
->set_is_sortable(false) | ||
->add_callback(function ($value, $row) { | ||
return $value; | ||
}); | ||
|
||
$columns[] = (new column( | ||
'tags', | ||
new lang_string('preset_entity.tags', 'tool_enrolprofile_presets'), | ||
$this->get_entity_name() | ||
)) | ||
->add_joins($this->get_joins()) | ||
->set_type(column::TYPE_TEXT) | ||
->add_field("{$alias}.tags") | ||
->set_is_sortable(false) | ||
->add_callback(function ($value, $row) { | ||
return $value; | ||
}); | ||
|
||
|
||
return $columns; | ||
} | ||
} |
Oops, something went wrong.