+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class tags extends system_report {
+
+ /**
+ * Report initialisation
+ */
+ protected function initialise(): void {
+ $tag = new tag();
+ $this->add_entity($tag);
+
+ $tagalias = $tag->get_table_alias('tag');
+ $this->set_main_table('tag', $tagalias);
+
+ // Base fields required for various callbacks.
+ $this->add_base_fields("{$tagalias}.id, {$tagalias}.rawname, {$tagalias}.flag, {$tagalias}.tagcollid");
+ $this->set_checkbox_toggleall(static function(stdClass $tag): array {
+ return [$tag->id, get_string('selecttag', 'core_tag', $tag->rawname)];
+ });
+
+ // Limit tags to current collection.
+ $this->add_base_condition_simple("{$tagalias}.tagcollid", $this->get_parameter('collection', 0, PARAM_INT));
+
+ // Join the user entity to represent the tag author.
+ $user = new user();
+ $useralias = $user->get_table_alias('user');
+ $this->add_entity($user->add_join("LEFT JOIN {user} {$useralias} ON {$useralias}.id = {$tagalias}.userid"));
+
+ $this->add_columns($tag);
+ $this->add_filters();
+ $this->add_actions();
+
+ $this->set_downloadable(false);
+ }
+
+ /**
+ * Report access
+ *
+ * @return bool
+ */
+ protected function can_view(): bool {
+ global $CFG;
+
+ return !empty($CFG->usetags) && has_capability('moodle/tag:manage', system::instance());
+ }
+
+ /**
+ * Report columns
+ *
+ * @param tag $tag
+ */
+ public function add_columns(tag $tag): void {
+ $tagentity = $tag->get_entity_name();
+ $tagalias = $tag->get_table_alias('tag');
+
+ // Name (editable).
+ $this->add_column((new column(
+ 'nameeditable',
+ new lang_string('name', 'core_tag'),
+ $tagentity,
+ ))
+ ->add_fields("{$tagalias}.name, {$tagalias}.rawname, {$tagalias}.tagcollid, {$tagalias}.id")
+ ->set_type(column::TYPE_TEXT)
+ ->set_is_sortable(true)
+ ->set_callback(static function(string $name, stdClass $tag): string {
+ global $PAGE;
+ $editable = new tagname($tag);
+ return $editable->render($PAGE->get_renderer('core'));
+ })
+ );
+
+ // User.
+ $this->add_column_from_entity('user:fullnamewithlink');
+
+ // Count (TODO MDL-76392 use native entity aggregation).
+ $this->add_column((new column(
+ 'instancecount',
+ new lang_string('count', 'core_tag'),
+ $tagentity,
+ ))
+ ->add_field("(SELECT COUNT(*) FROM {tag_instance} WHERE tagid = {$tagalias}.id)", 'instancecount')
+ ->set_type(column::TYPE_INTEGER)
+ ->set_is_sortable(true)
+ );
+
+ // Flag (editable).
+ $this->add_column((new column(
+ 'flageditable',
+ new lang_string('flag', 'core_tag'),
+ $tagentity,
+ ))
+ ->add_fields("{$tagalias}.flag, {$tagalias}.id")
+ ->set_type(column::TYPE_BOOLEAN)
+ ->set_is_sortable(true)
+ ->set_callback(static function(bool $flag, stdClass $tag): string {
+ global $PAGE;
+ $editable = new tagflag($tag);
+ return $editable->render($PAGE->get_renderer('core'));
+ })
+ );
+
+ // Time modified.
+ $this->add_column_from_entity('tag:timemodified')
+ ->set_callback(fn($timemodified) => format_time(time() - $timemodified));
+
+ // Standard (editable).
+ $this->add_column((new column(
+ 'standardeditable',
+ new lang_string('standardtag', 'core_tag'),
+ $tagentity,
+ ))
+ ->add_fields("{$tagalias}.isstandard, {$tagalias}.id")
+ ->set_type(column::TYPE_BOOLEAN)
+ ->set_is_sortable(true)
+ ->set_callback(static function(bool $standard, stdClass $tag): string {
+ global $PAGE;
+ $editable = new tagisstandard($tag);
+ return $editable->render($PAGE->get_renderer('core'));
+ })
+ );
+
+ $this->set_initial_sort_column('tag:flageditable', SORT_DESC);
+ }
+
+ /**
+ * Report filters
+ */
+ protected function add_filters(): void {
+ $this->add_filters_from_entities([
+ 'tag:name',
+ 'tag:standard',
+ 'tag:flagged',
+ ]);
+ }
+
+ /**
+ * Report actions
+ */
+ protected function add_actions(): void {
+
+ // Edit.
+ $this->add_action((new action(
+ new moodle_url('/tag/edit.php', [
+ 'id' => ':id',
+ 'returnurl' => ':returnurl',
+ ]),
+ new pix_icon('t/edit', ''),
+ [],
+ false,
+ new lang_string('edit'),
+ ))
+ ->add_callback(static function(stdClass $tag): bool {
+ $tag->returnurl = (new moodle_url('/tag/manage.php', ['tc' => $tag->tagcollid]))->out_as_local_url(false);
+ return true;
+ })
+ );
+
+ // Delete.
+ $this->add_action(new action(
+ new moodle_url('/tag/manage.php', [
+ 'tc' => ':tagcollid',
+ 'tagid' => ':id',
+ 'action' => 'delete',
+ 'sesskey' => sesskey(),
+ ]),
+ new pix_icon('t/delete', ''),
+ [
+ 'class' => 'tagdelete text-danger',
+ ],
+ false,
+ new lang_string('delete'),
+ ));
+ }
+
+ /**
+ * Report row class
+ *
+ * @param stdClass $row
+ * @return string
+ */
+ public function get_row_class(stdClass $row): string {
+ return $row->flag ? 'table-warning' : '';
+ }
+}
diff --git a/tag/manage.php b/tag/manage.php
index e4165a80955..144160f44f7 100644
--- a/tag/manage.php
+++ b/tag/manage.php
@@ -23,36 +23,22 @@
*/
require_once('../config.php');
-require_once($CFG->libdir.'/tablelib.php');
require_once('lib.php');
require_once($CFG->libdir.'/adminlib.php');
-define('SHOW_ALL_PAGE_SIZE', 50000);
-define('DEFAULT_PAGE_SIZE', 30);
+use core\context\system;
+use core_reportbuilder\system_report_factory;
+use core_tag\reportbuilder\local\systemreports\tags;
-$tagschecked = optional_param_array('tagschecked', array(), PARAM_INT);
$tagid = optional_param('tagid', null, PARAM_INT);
$isstandard = optional_param('isstandard', null, PARAM_INT);
$action = optional_param('action', '', PARAM_ALPHA);
-$perpage = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT);
-$page = optional_param('page', 0, PARAM_INT);
$tagcollid = optional_param('tc', 0, PARAM_INT);
-$tagareaid = optional_param('ta', null, PARAM_INT);
-$filter = optional_param('filter', '', PARAM_NOTAGS);
$params = array();
-if ($perpage != DEFAULT_PAGE_SIZE) {
- $params['perpage'] = $perpage;
-}
-if ($page > 0) {
- $params['page'] = $page;
-}
if ($tagcollid) {
$params['tc'] = $tagcollid;
}
-if ($filter !== '') {
- $params['filter'] = $filter;
-}
admin_externalpage_setup('managetags', '', $params, '', array('pagelayout' => 'report'));
@@ -66,7 +52,6 @@ if ($tagid) {
$tagcollid = $tagobject->tagcollid;
}
$tagcoll = core_tag_collection::get_by_id($tagcollid);
-$tagarea = core_tag_area::get_by_id($tagareaid);
$manageurl = new moodle_url('/tag/manage.php');
if ($tagcoll) {
// We are inside a tag collection - add it to the breadcrumb.
@@ -125,6 +110,7 @@ switch($action) {
break;
case 'bulk':
+ $tagschecked = explode(',', optional_param('tagschecked', '', PARAM_SEQUENCE));
if (optional_param('bulkdelete', null, PARAM_RAW) !== null) {
if ($tagschecked) {
require_sesskey();
@@ -206,70 +192,39 @@ if (!$tagcoll) {
}
// Tag collection is specified. Manage tags in this collection.
-echo $OUTPUT->heading(core_tag_collection::display_name($tagcoll));
+echo html_writer::div(
+ $OUTPUT->heading(core_tag_collection::display_name($tagcoll)) .
+ html_writer::tag(
+ 'button',
+ $OUTPUT->pix_icon('t/add', '') . get_string('addotags', 'core_tag'),
+ [
+ 'type' => 'button',
+ 'class' => 'btn btn-primary my-auto',
+ 'data-action' => 'addstandardtag',
+ ],
+ ),
+ 'd-flex justify-content-between mb-2',
+);
-$hiddenfields = [
- (object) ['type' => 'hidden', 'name' => 'tc', 'value' => $tagcollid],
- (object) ['type' => 'hidden', 'name' => 'perpage', 'value' => $perpage]
-];
+// Render the report.
+$report = system_report_factory::create(tags::class, system::instance(), '', '', 0, ['collection' => $tagcoll->id]);
+echo $report->output();
-$otherfields = '';
-if ($filter !== '') {
- $otherfields = html_writer::link(new moodle_url($PAGE->url, ['filter' => null]),
- get_string('resetfilter', 'tag'));
-}
-
-$data = [
- 'action' => new moodle_url('/tag/manage.php'),
- 'hiddenfields' => $hiddenfields,
- 'inputname' => 'filter',
- 'searchstring' => get_string('search'),
- 'query' => s($filter),
- 'extraclasses' => 'mb-2',
- 'otherfields' => $otherfields
-];
-echo $OUTPUT->render_from_template('core/search_input', $data);
-
-// Link to add an standard tags.
-$img = $OUTPUT->pix_icon('t/add', '');
-echo '' .
- html_writer::link('#', $img . get_string('addotags', 'tag'), array('data-action' => 'addstandardtag')) .
- '
';
-
-$table = new core_tag_manage_table($tagcollid);
-echo '';
}
-echo '';
-$totalcount = $table->totalcount;
-if ($perpage == SHOW_ALL_PAGE_SIZE) {
- echo html_writer::start_tag('div', array('id' => 'showall'));
- $params = array('perpage' => DEFAULT_PAGE_SIZE, 'page' => 0);
- $url = new moodle_url($PAGE->url, $params);
- echo html_writer::link($url, get_string('showperpage', '', DEFAULT_PAGE_SIZE));
- echo html_writer::end_tag('div');
-} else if ($totalcount > 0 and $perpage < $totalcount) {
- echo html_writer::start_tag('div', array('id' => 'showall'));
- $params = array('perpage' => SHOW_ALL_PAGE_SIZE, 'page' => 0);
- $url = new moodle_url($PAGE->url, $params);
- echo html_writer::link($url, get_string('showall', '', $totalcount));
- echo html_writer::end_tag('div');
-}
+$PAGE->requires->js_call_amd('core/tag', 'initManagePage');
echo $OUTPUT->footer();
diff --git a/tag/tests/behat/delete_tag.feature b/tag/tests/behat/delete_tag.feature
index 0da6773cbf2..008313aa680 100644
--- a/tag/tests/behat/delete_tag.feature
+++ b/tag/tests/behat/delete_tag.feature
@@ -29,34 +29,17 @@ Feature: Manager is able to delete tags
And I should not see "Dog"
And I log out
- Scenario: Deleting multiple tags with javascript disabled
- When I log in as "manager1"
- And I navigate to "Appearance > Manage tags" in site administration
- And I follow "Default collection"
- And I set the following fields to these values:
- | Select tag Dog | 1 |
- | Select tag Neverusedtag | 1 |
- And I press "Delete selected"
- Then I should see "Tag(s) deleted"
- And I should not see "Dog"
- And I should not see "Neverusedtag"
- And I follow "Cat"
- And I follow "User 1"
- And I should see "Cat"
- And I should not see "Dog"
- And I log out
-
@javascript
Scenario: Deleting a tag with javascript enabled
When I log in as "manager1"
And I navigate to "Appearance > Manage tags" in site administration
And I follow "Default collection"
- And I click on "Delete" "link" in the "Turtle" "table_row"
+ And I press "Delete" action in the "Turtle" report row
Then I should see "Are you sure you want to delete this tag?"
And I click on "Cancel" "button" in the "Delete" "dialogue"
And I should not see "Tag(s) deleted"
And I should see "Turtle"
- And I click on "Delete" "link" in the "Dog" "table_row"
+ And I press "Delete" action in the "Dog" report row
And I should see "Are you sure you want to delete this tag?"
And I press "Yes"
And I should see "Tag(s) deleted"
diff --git a/tag/tests/behat/edit_tag.feature b/tag/tests/behat/edit_tag.feature
index c9408b22be5..84d2ace856a 100644
--- a/tag/tests/behat/edit_tag.feature
+++ b/tag/tests/behat/edit_tag.feature
@@ -120,7 +120,7 @@ Feature: Users can edit tags to add description or rename
When I log in as "manager1"
And I navigate to "Appearance > Manage tags" in site administration
And I follow "Default collection"
- And I click on "Edit this tag" "link" in the "Cat" "table_row"
+ And I press "Edit" action in the "Cat" report row
And I set the following fields to these values:
| Tag name | Kitten |
| Description | Description of tag 1 |
@@ -138,7 +138,7 @@ Feature: Users can edit tags to add description or rename
When I log in as "manager1"
And I navigate to "Appearance > Manage tags" in site administration
And I follow "Default collection"
- And I click on "Edit this tag" "link" in the "Cat" "table_row"
+ And I press "Edit" action in the "Cat" report row
And I set the following fields to these values:
| Tag name | DOG |
And I press "Update"
@@ -146,7 +146,7 @@ Feature: Users can edit tags to add description or rename
And I set the following fields to these values:
| Tag name | Kitten |
And I press "Update"
- And I click on "Edit this tag" "link" in the "Kitten" "table_row"
+ And I press "Edit" action in the "Kitten" report row
And I set the following fields to these values:
| Tag name | KITTEN |
And I press "Update"
@@ -160,10 +160,10 @@ Feature: Users can edit tags to add description or rename
And I follow "Default collection"
# Renaming tag to a valid name
And I set the field "Edit tag name" in the "Cat" "table_row" to "Kitten"
- Then I should not see "Cat"
- And "New name for tag" "field" should not exist
- And I navigate to "Appearance > Manage tags" in site administration
- And I follow "Default collection"
+ Then the following should not exist in the "reportbuilder-table" table:
+ | First name | Tag name |
+ | Admin User | Cat |
+ And I reload the page
And I should see "Kitten"
And I should not see "Cat"
# Renaming tag to an invalid name
@@ -174,22 +174,6 @@ Feature: Users can edit tags to add description or rename
And I should see "Turtle"
And I should see "Dog"
And I should not see "DOG"
- And I navigate to "Appearance > Manage tags" in site administration
- And I follow "Default collection"
- And I should see "Turtle"
- And I should see "Dog"
- And I should not see "DOG"
- # Cancel tag renaming
- And I click on "Edit tag name" "link" in the "Dog" "table_row"
- And I type "Penguin"
- And I press the escape key
- And "New name for tag" "field" should not exist
- And I should see "Turtle"
- And I should not see "Penguin"
- And I navigate to "Appearance > Manage tags" in site administration
- And I follow "Default collection"
- And I should see "Turtle"
- And I should not see "Penguin"
@javascript
Scenario: Combining tags when renaming
@@ -238,18 +222,17 @@ Feature: Users can edit tags to add description or rename
And I should see "Turtle"
And I should not see "Neverusedtag"
+ @javascript
Scenario: Filtering tags
When I log in as "manager1"
And I navigate to "Appearance > Manage tags" in site administration
And I follow "Default collection"
- And I should not see "Reset filter"
- And I set the field "Search" to "t"
- And I press "Search"
- Then the field "Search" matches value "t"
- And I should not see "Dog"
- And I should see "Cat"
- And I should see "Turtle"
- And I follow "Reset filter"
- And I should see "Dog"
- And I should see "Cat"
- And I should see "Turtle"
+ And I click on "Filters" "button"
+ And I set the following fields in the "Tag name" "core_reportbuilder > Filter" to these values:
+ | Tag name operator | Is equal to |
+ | Tag name value | Cat,Dog |
+ And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element"
+ Then I should see "Cat" in the "reportbuilder-table" "table"
+ And I should see "Dog" in the "reportbuilder-table" "table"
+ And I should not see "Turtle" in the "reportbuilder-table" "table"
+ And I should not see "Neverusedtag" in the "reportbuilder-table" "table"
diff --git a/tag/tests/behat/flag_tags.feature b/tag/tests/behat/flag_tags.feature
index bc8348fcf5a..aa062977f3b 100644
--- a/tag/tests/behat/flag_tags.feature
+++ b/tag/tests/behat/flag_tags.feature
@@ -69,25 +69,35 @@ Feature: Users can flag tags and manager can reset flags
And I follow "Default collection"
Then "Sweartag" "link" should appear before "Badtag" "link"
And "Badtag" "link" should appear before "Nicetag" "link"
- And "(2)" "text" should exist in the "//tr[contains(.,'Sweartag')]//td[contains(@class,'col-flag')]" "xpath_element"
- And "(1)" "text" should exist in the "//tr[contains(.,'Badtag')]//td[contains(@class,'col-flag')]" "xpath_element"
- And "(" "text" should not exist in the "//tr[contains(.,'Nicetag')]//td[contains(@class,'col-flag')]" "xpath_element"
- And "(" "text" should not exist in the "//tr[contains(.,'Neverusedtag')]//td[contains(@class,'col-flag')]" "xpath_element"
+ And the following should exist in the "reportbuilder-table" table:
+ | Tag name | Flag |
+ | Sweartag | (2) |
+ | Badtag | (1) |
+ And the following should not exist in the "reportbuilder-table" table:
+ | Tag name | Flag |
+ | Nicetag | ( |
+ | Neverusertag | ( |
And I click on "Reset flag" "link" in the "Sweartag" "table_row"
And I click on "Reset flag" "link" in the "Badtag" "table_row"
And I wait until "//tr[contains(.,'Sweartag')]//a[contains(@title,'Flag as inappropriate')]" "xpath_element" exists
And I click on "Flag as inappropriate" "link" in the "Sweartag" "table_row"
And I click on "Flag as inappropriate" "link" in the "Nicetag" "table_row"
- And "(1)" "text" should exist in the "//tr[contains(.,'Sweartag')]//td[contains(@class,'col-flag')]" "xpath_element"
- And "(1)" "text" should exist in the "//tr[contains(.,'Nicetag')]//td[contains(@class,'col-flag')]" "xpath_element"
- And "(" "text" should not exist in the "//tr[contains(.,'Badtag')]//td[contains(@class,'col-flag')]" "xpath_element"
- And "(" "text" should not exist in the "//tr[contains(.,'Neverusedtag')]//td[contains(@class,'col-flag')]" "xpath_element"
- And I navigate to "Appearance > Manage tags" in site administration
- And I follow "Default collection"
- And "Nicetag" "link" should appear before "Sweartag" "link"
+ And the following should exist in the "reportbuilder-table" table:
+ | Tag name | Flag |
+ | Sweartag | (1) |
+ | Nicetag | (1) |
+ And the following should not exist in the "reportbuilder-table" table:
+ | Tag name | Flag |
+ | Badtag | ( |
+ | Neverusertag | ( |
+ And I reload the page
+ And "Nicetag" "link" should appear before "Neverusedtag" "link"
And "Sweartag" "link" should appear before "Badtag" "link"
- And "(1)" "text" should exist in the "//tr[contains(.,'Sweartag')]//td[contains(@class,'col-flag')]" "xpath_element"
- And "(1)" "text" should exist in the "//tr[contains(.,'Nicetag')]//td[contains(@class,'col-flag')]" "xpath_element"
- And "(" "text" should not exist in the "//tr[contains(.,'Badtag')]//td[contains(@class,'col-flag')]" "xpath_element"
- And "(" "text" should not exist in the "//tr[contains(.,'Neverusedtag')]//td[contains(@class,'col-flag')]" "xpath_element"
- And I log out
+ And the following should exist in the "reportbuilder-table" table:
+ | Tag name | Flag |
+ | Sweartag | (1) |
+ | Nicetag | (1) |
+ And the following should not exist in the "reportbuilder-table" table:
+ | Tag name | Flag |
+ | Badtag | ( |
+ | Neverusertag | ( |
diff --git a/tag/tests/behat/standard_tags.feature b/tag/tests/behat/standard_tags.feature
index dbc7e98bb0f..16c816205ee 100644
--- a/tag/tests/behat/standard_tags.feature
+++ b/tag/tests/behat/standard_tags.feature
@@ -28,7 +28,7 @@ Feature: Manager can add standard tags and change the tag type of existing tags
And "Make standard" "link" should exist in the "Tag1" "table_row"
And "Make standard" "link" should exist in the "Tag2" "table_row"
And "Remove from standard tags" "link" should exist in the "Tag3" "table_row"
- And I follow "Add standard tags"
+ And I click on "Add standard tags" "button"
And I set the field "Enter comma-separated list of new tags" to "Tag1,TAG2,Tag3,Tag4,Tag5"
And I press "Continue"
And I should see "Standard tag(s) added"
@@ -75,12 +75,12 @@ Feature: Manager can add standard tags and change the tag type of existing tags
When I log in as "manager1"
And I navigate to "Appearance > Manage tags" in site administration
And I follow "Default collection"
- And I click on "Edit this tag" "link" in the "Tag1" "table_row"
+ And I press "Edit" action in the "Tag1" report row
And I set the following fields to these values:
| Standard | 1 |
And I press "Update"
Then "Remove from standard tags" "link" should exist in the "Tag1" "table_row"
- And I click on "Edit this tag" "link" in the "Tag1" "table_row"
+ And I press "Edit" action in the "Tag1" report row
And I set the following fields to these values:
| Standard | 0 |
And I press "Update"
diff --git a/tag/upgrade.txt b/tag/upgrade.txt
index 9ff30c0e2b8..b96213e2552 100644
--- a/tag/upgrade.txt
+++ b/tag/upgrade.txt
@@ -5,6 +5,7 @@ here is intended especially for developers.
* New additional property 'viewurl' has been added to the pre-defined structure in tag_item_exporter. This property
represents the URL to view a given tag.
+* The `core_tag_manage_table` class has been deprecated, in favour of new report builder implementation
=== 3.6 ===