diff --git a/.upgradenotes/MDL-82503-2024081605135370.yml b/.upgradenotes/MDL-82503-2024081605135370.yml new file mode 100644 index 00000000000..00b00b2bfc5 --- /dev/null +++ b/.upgradenotes/MDL-82503-2024081605135370.yml @@ -0,0 +1,7 @@ +issueNumber: MDL-82503 +notes: + core_badges: + - message: >- + The course_badges systemreport has been deprecated and merged with the + badges systemreport. Please, use the badges systemreport instead. + type: deprecated diff --git a/.upgradenotes/MDL-82503-2024081605172847.yml b/.upgradenotes/MDL-82503-2024081605172847.yml new file mode 100644 index 00000000000..4eb3439ce89 --- /dev/null +++ b/.upgradenotes/MDL-82503-2024081605172847.yml @@ -0,0 +1,7 @@ +issueNumber: MDL-82503 +notes: + core_badges: + - message: >- + The $showmanage parameter in the core_badges\output\standard_action_bar + constructor has been deprecated and should not be used anymore. + type: deprecated diff --git a/.upgradenotes/MDL-82503-2024081605182874.yml b/.upgradenotes/MDL-82503-2024081605182874.yml new file mode 100644 index 00000000000..87ebd369899 --- /dev/null +++ b/.upgradenotes/MDL-82503-2024081605182874.yml @@ -0,0 +1,7 @@ +issueNumber: MDL-82503 +notes: + core_badges: + - message: >- + The badges/view.php page has been deprecated and merged with + badges/index.php. Please, use badges/index.php instead. + type: deprecated diff --git a/backup/moodle2/backup_course_task.class.php b/backup/moodle2/backup_course_task.class.php index 784b7eeac88..83162080a61 100644 --- a/backup/moodle2/backup_course_task.class.php +++ b/backup/moodle2/backup_course_task.class.php @@ -165,7 +165,7 @@ class backup_course_task extends backup_task { // A few other key course links. $content = self::encode_links_helper($content, 'GRADEINDEXBYID', '/grade/index.php?id='); $content = self::encode_links_helper($content, 'GRADEREPORTINDEXBYID', '/grade/report/index.php?id='); - $content = self::encode_links_helper($content, 'BADGESVIEWBYID', '/badges/view.php?type=2&id='); + $content = self::encode_links_helper($content, 'BADGESVIEWBYID', '/badges/index.php?type=2&id='); $content = self::encode_links_helper($content, 'USERINDEXVIEWBYID', '/user/index.php?id='); $content = self::encode_links_helper($content, 'PLUGINFILEBYCONTEXT', '/pluginfile.php/'); $content = self::encode_links_helper($content, 'PLUGINFILEBYCONTEXTURLENCODED', '/pluginfile.php/', true); diff --git a/backup/moodle2/restore_course_task.class.php b/backup/moodle2/restore_course_task.class.php index b34987e0879..46629222f6a 100644 --- a/backup/moodle2/restore_course_task.class.php +++ b/backup/moodle2/restore_course_task.class.php @@ -164,7 +164,7 @@ class restore_course_task extends restore_task { // A few other key course links. $rules[] = new restore_decode_rule('GRADEINDEXBYID', '/grade/index.php?id=$1', 'course'); $rules[] = new restore_decode_rule('GRADEREPORTINDEXBYID', '/grade/report/index.php?id=$1', 'course'); - $rules[] = new restore_decode_rule('BADGESVIEWBYID', '/badges/view.php?type=2&id=$1', 'course'); + $rules[] = new restore_decode_rule('BADGESVIEWBYID', '/badges/index.php?type=2&id=$1', 'course'); $rules[] = new restore_decode_rule('USERINDEXVIEWBYID', '/user/index.php?id=$1', 'course'); $rules[] = new restore_decode_rule('PLUGINFILEBYCONTEXT', '/pluginfile.php/$1', 'context'); $rules[] = new restore_decode_rule('PLUGINFILEBYCONTEXTURLENCODED', '/pluginfile.php/$1', 'context', true); diff --git a/backup/util/helper/tests/backup_encode_content_test.php b/backup/util/helper/tests/backup_encode_content_test.php index f4145efdd64..eac9f44c0a9 100644 --- a/backup/util/helper/tests/backup_encode_content_test.php +++ b/backup/util/helper/tests/backup_encode_content_test.php @@ -54,7 +54,7 @@ class backup_encode_content_test extends \basic_testcase { $httpsroot . '/course/view.php?id=123, ' . $httpsroot . '/grade/index.php?id=123, ' . $httpsroot . '/grade/report/index.php?id=123, ' . - $httpsroot . '/badges/view.php?type=2&id=123, ' . + $httpsroot . '/badges/index.php?type=2&id=123, ' . $httpsroot . '/user/index.php?id=123, ' . $httpsroot . '/pluginfile.php/123 and ' . urlencode($httpsroot . '/pluginfile.php/123') . '.' @@ -70,7 +70,7 @@ class backup_encode_content_test extends \basic_testcase { $httpsroot . '/course/view.php?id=123, ' . $httproot . '/grade/index.php?id=123, ' . $httproot . '/grade/report/index.php?id=123, ' . - $httproot . '/badges/view.php?type=2&id=123, ' . + $httproot . '/badges/index.php?type=2&id=123, ' . $httproot . '/user/index.php?id=123, ' . $httproot . '/pluginfile.php/123 and ' . urlencode($httproot . '/pluginfile.php/123') . '.' diff --git a/backup/util/ui/tests/behat/import_course.feature b/backup/util/ui/tests/behat/import_course.feature index f0e6c8d5400..5f849f5b711 100644 --- a/backup/util/ui/tests/behat/import_course.feature +++ b/backup/util/ui/tests/behat/import_course.feature @@ -69,7 +69,7 @@ Feature: Import course's contents into another course | Unpublished course badge | editingteacher | When I import "Course 1" course into "Course 2" course using this options: | Settings | Include badges | 1 | - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration Then I should see "Published course badge" And I should see "Unpublished course badge" And I should see "Unpublished without criteria course badge" diff --git a/backup/util/ui/tests/behat/restore_moodle2_courses.feature b/backup/util/ui/tests/behat/restore_moodle2_courses.feature index 62539cca092..7da17b0abfc 100644 --- a/backup/util/ui/tests/behat/restore_moodle2_courses.feature +++ b/backup/util/ui/tests/behat/restore_moodle2_courses.feature @@ -285,7 +285,7 @@ Feature: Restore Moodle 2 course backups | Confirmation | Filename | test_backup.mbz | When I restore "test_backup.mbz" backup into a new course using this options: | Settings | Include badges | 1 | - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration Then I should see "Published course badge" And I should see "Unpublished course badge" And I should see "Unpublished without criteria course badge" diff --git a/badges/award.php b/badges/award.php index b503ac19234..7b71559c2b2 100644 --- a/badges/award.php +++ b/badges/award.php @@ -84,7 +84,12 @@ if (!$badge->is_active()) { $returnurl = new moodle_url('recipients.php', array('id' => $badge->id)); $returnlink = html_writer::link($returnurl, $strrecipients); -$actionbar = new \core_badges\output\standard_action_bar($PAGE, $badge->type, false, false, $returnurl); +$actionbar = new \core_badges\output\standard_action_bar( + page: $PAGE, + type: $badge->type, + showaddbadge: false, + backurl: $returnurl +); $output = $PAGE->get_renderer('core', 'badges'); $tertiarynav = $output->render_tertiary_navigation($actionbar); diff --git a/badges/classes/output/manage_badge_action_bar.php b/badges/classes/output/manage_badge_action_bar.php index f2864796ad5..a887bffe903 100644 --- a/badges/classes/output/manage_badge_action_bar.php +++ b/badges/classes/output/manage_badge_action_bar.php @@ -67,7 +67,10 @@ class manage_badge_action_bar extends base_action_bar { $params['id'] = $this->page->context->instanceid; } $elements['button'] = new single_button(new moodle_url('/badges/index.php', $params), get_string('back'), 'get'); - $elements['urlselect'] = new url_select($this->generate_badge_navigation(), $this->page->url->out(false), null); + $badgenav = $this->generate_badge_navigation(); + if ($badgenav) { + $elements['urlselect'] = new url_select($badgenav, $this->page->url->out(false), null); + } foreach ($elements as $key => $element) { $elements[$key] = $element->export_for_template($output); } @@ -132,6 +135,7 @@ class manage_badge_action_bar extends base_action_bar { */ protected function generate_badge_navigation(): array { global $DB; + $params = ['id' => $this->badge->id]; $options = []; $construct = $this->get_badge_administration_mapping_construct(); @@ -168,6 +172,10 @@ class manage_badge_action_bar extends base_action_bar { $url = new moodle_url($checks['url'], $params + ($checks['additionalparams'] ?? [])); $options[get_string($stringidentifier, 'core_badges', $content)] = $url->out(false); } + if (count($options) <= 1) { + return []; + } + return array_flip($options); } } diff --git a/badges/classes/output/standard_action_bar.php b/badges/classes/output/standard_action_bar.php index 619eb7719bd..3011d20b803 100644 --- a/badges/classes/output/standard_action_bar.php +++ b/badges/classes/output/standard_action_bar.php @@ -29,29 +29,29 @@ use single_button; * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class standard_action_bar extends base_action_bar { - /** @var bool $showmanage Whether or not to show the manage badges button. */ - protected $showmanage; - - /** @var bool $showaddbadge Whether or not to show the add badges button. */ - protected $showaddbadge; - - /** @var moodle_url $backurl BackURL to be used when the back button is required. */ - protected $backurl; - /** - * standard_action_bar constructor + * The constructor. * - * @param moodle_page $page The page object - * @param int $type The type of badge we are operating with - * @param bool $showmanage Whether or not to show the manage badges button - * @param bool $showaddbadge Whether or not to show the add badges button - * @param moodle_url|null $backurl The backurl to be used */ - public function __construct(moodle_page $page, int $type, bool $showmanage = true, - $showaddbadge = true, ?moodle_url $backurl = null) { + public function __construct( + moodle_page $page, + int $type, + /** @var null|bool $showmanage This parameter has been deprecated since 4.5 and should not be used anymore. */ + ?bool $showmanage = null, + /** @var bool $showaddbadge Whether or not to show the add badges button. */ + protected bool $showaddbadge = true, + /** @var moodle_url $backurl BackURL to be used when the back button is required. */ + protected ?moodle_url $backurl = null, + ) { parent::__construct($page, $type); - $this->showmanage = $showmanage; + if ($showmanage !== null) { + debugging( + 'The showmanage argument has been deprecated. Please remove it from your method calls.', + DEBUG_DEVELOPER, + ); + } + $this->showaddbadge = $showaddbadge; $this->backurl = $backurl; } @@ -82,11 +82,6 @@ class standard_action_bar extends base_action_bar { $params['id'] = $this->page->context->instanceid; } - if ($this->showmanage) { - $buttons[] = new single_button(new moodle_url('/badges/index.php', $params), - get_string('managebadges', 'core_badges'), 'get'); - } - if ($this->showaddbadge && has_capability('moodle/badges:createbadge', $this->page->context)) { $editparams = ['action' => 'new']; if (array_key_exists('id', $params)) { diff --git a/badges/classes/reportbuilder/local/systemreports/badges.php b/badges/classes/reportbuilder/local/systemreports/badges.php index 01d0a8753fb..9c1c4f0af00 100644 --- a/badges/classes/reportbuilder/local/systemreports/badges.php +++ b/badges/classes/reportbuilder/local/systemreports/badges.php @@ -20,6 +20,7 @@ namespace core_badges\reportbuilder\local\systemreports; use core\context\{course, system}; use core_badges\reportbuilder\local\entities\badge; +use core_badges\reportbuilder\local\entities\badge_issued; use core_reportbuilder\local\helpers\database; use core_reportbuilder\local\report\{action, column}; use core_reportbuilder\system_report; @@ -50,6 +51,8 @@ class badges extends system_report { * Initialise report, we need to set the main table, load our entities and set columns/filters */ protected function initialise(): void { + global $USER; + // Our main entity, it contains all of the column definitions that we need. $badgeentity = new badge(); $entityalias = $badgeentity->get_table_alias('badge'); @@ -69,14 +72,29 @@ class badges extends system_report { [$paramtype => $type, $paramcourseid => $context->instanceid]); } + if (!$this->can_view_draft_badges()) { + $this->add_base_condition_sql("({$entityalias}.status = " . BADGE_STATUS_ACTIVE . + " OR {$entityalias}.status = " . BADGE_STATUS_ACTIVE_LOCKED . ")"); + } + // Any columns required by actions should be defined here to ensure they're always available. $this->add_base_fields("{$entityalias}.id, {$entityalias}.type, {$entityalias}.courseid, {$entityalias}.status"); + $badgeissuedentity = new badge_issued(); + $badgeissuedalias = $badgeissuedentity->get_table_alias('badge_issued'); + $this->add_entity($badgeissuedentity + ->add_join("LEFT JOIN {badge_issued} {$badgeissuedalias} + ON {$entityalias}.id = {$badgeissuedalias}.badgeid AND {$badgeissuedalias}.userid = ".$USER->id) + ); + + $this->add_base_fields("{$badgeissuedalias}.uniquehash"); + // Now we can call our helper methods to add the content we want to include in the report. - $this->add_columns(); + $this->add_columns($badgeissuedalias); $this->add_filters(); $this->add_actions(); + // Set initial sorting by name. $this->set_initial_sort_column('badge:namewithlink', SORT_ASC); $this->set_default_no_results_notice(new lang_string('nomatchingbadges', 'core_badges')); @@ -91,6 +109,7 @@ class badges extends system_report { */ protected function can_view(): bool { return has_any_capability([ + 'moodle/badges:viewbadges', 'moodle/badges:viewawarded', 'moodle/badges:createbadge', 'moodle/badges:awardbadge', @@ -105,47 +124,76 @@ class badges extends system_report { * * They are provided by the entities we previously added in the {@see initialise} method, referencing each by their * unique identifier. If custom columns are needed just for this report, they can be defined here. + * + * @param string $badgeissuedalias */ - protected function add_columns(): void { - $badgeentity = $this->get_entity('badge'); - - $this->add_columns_from_entities([ + public function add_columns(string $badgeissuedalias): void { + $columns = [ 'badge:image', 'badge:namewithlink', - 'badge:version', 'badge:status', 'badge:criteria', - ]); + ]; - // Issued badges column. - $tempbadgealias = database::generate_alias(); - $badgeentityalias = $badgeentity->get_table_alias('badge'); - $this->add_column((new column( - 'issued', - new lang_string('awards', 'core_badges'), - $badgeentity->get_entity_name() - )) - ->add_joins($this->get_joins()) - ->set_type(column::TYPE_INTEGER) - ->add_field("(SELECT COUNT({$tempbadgealias}.userid) - FROM {badge_issued} {$tempbadgealias} - INNER JOIN {user} u - ON {$tempbadgealias}.userid = u.id - WHERE {$tempbadgealias}.badgeid = {$badgeentityalias}.id AND u.deleted = 0)", 'issued') - ->set_is_sortable(true) - ->set_callback(function(int $count): string { - if (!has_capability('moodle/badges:viewawarded', $this->get_context())) { - return (string) $count; - } - - return html_writer::link(new moodle_url('/badges/recipients.php', ['id' => $this->badgeid]), $count); - })); + $canviewdraftbadges = $this->can_view_draft_badges(); + if (!$canviewdraftbadges) { + // Remove status and recipients column. + unset($columns[2]); + } + $this->add_columns_from_entities($columns); // Remove title from image column. $this->get_column('badge:image')->set_title(null); // Change title from namewithlink column. $this->get_column('badge:namewithlink')->set_title(new lang_string('name')); + + // Recipients column. + if ($canviewdraftbadges) { + $badgeentity = $this->get_entity('badge'); + $tempbadgealias = database::generate_alias(); + $badgeentityalias = $badgeentity->get_table_alias('badge'); + $this->add_column((new column( + 'issued', + new lang_string('awards', 'core_badges'), + $badgeentity->get_entity_name() + )) + ->add_joins($this->get_joins()) + ->set_type(column::TYPE_INTEGER) + ->add_field("(SELECT COUNT({$tempbadgealias}.userid) + FROM {badge_issued} {$tempbadgealias} + INNER JOIN {user} u + ON {$tempbadgealias}.userid = u.id + WHERE {$tempbadgealias}.badgeid = {$badgeentityalias}.id AND u.deleted = 0)", 'issued') + ->set_is_sortable(true) + ->set_callback(function(int $count): string { + if (!has_capability('moodle/badges:viewawarded', $this->get_context())) { + return (string) $count; + } + + return html_writer::link(new moodle_url('/badges/recipients.php', ['id' => $this->badgeid]), $count); + })); + } + + // Add the date the badge was issued at the end of the report. + $this->add_column_from_entity('badge_issued:issued'); + $this->get_column('badge_issued:issued') + ->set_title(new lang_string('awardedtoyou', 'core_badges')) + ->add_fields("{$badgeissuedalias}.uniquehash") + ->set_callback(static function(?int $value, stdClass $row) { + global $OUTPUT; + + if (!$value) { + return ''; + } + $format = get_string('strftimedatefullshort', 'core_langconfig'); + $date = $value ? userdate($value, $format) : ''; + $badgeurl = new moodle_url('/badges/badge.php', ['hash' => $row->uniquehash]); + $icon = new pix_icon('i/valid', get_string('dateearned', 'badges', $date)); + return $OUTPUT->action_icon($badgeurl, $icon, null, null, true); + }); + + $this->set_initial_sort_column('badge:namewithlink', SORT_ASC); } /** @@ -155,12 +203,19 @@ class badges extends system_report { * unique identifier */ protected function add_filters(): void { - $this->add_filters_from_entities([ + $filters = [ 'badge:name', 'badge:version', 'badge:status', 'badge:expiry', - ]); + 'badge_issued:issued', + ]; + if (!$this->can_view_draft_badges()) { + // Remove version and status filters. + unset($filters[1]); + unset($filters[2]); + } + $this->add_filters_from_entities($filters); } /** @@ -295,6 +350,22 @@ class badges extends system_report { } } + /** + * Check whether the user can view unpublished badges. + * + * @return bool True if the user can edit badges, false otherwise. + */ + private function can_view_draft_badges(): bool { + return has_any_capability([ + 'moodle/badges:viewawarded', + 'moodle/badges:createbadge', + 'moodle/badges:awardbadge', + 'moodle/badges:configurecriteria', + 'moodle/badges:configuremessages', + 'moodle/badges:configuredetails', + 'moodle/badges:deletebadge'], $this->get_context()); + } + /** * Store the ID of the badge within each row * diff --git a/badges/classes/reportbuilder/local/systemreports/course_badges.php b/badges/classes/reportbuilder/local/systemreports/course_badges.php index f415e287b66..5a28d6b04db 100644 --- a/badges/classes/reportbuilder/local/systemreports/course_badges.php +++ b/badges/classes/reportbuilder/local/systemreports/course_badges.php @@ -37,13 +37,19 @@ require_once("{$CFG->libdir}/badgeslib.php"); * @package core_badges * @copyright 2023 David Carrillo * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @deprecated since 4.5. Use badges system_report instead. + * @todo MDL-82383 This class will be deleted in Moodle 6.0. */ class course_badges extends system_report { /** * Initialise report, we need to set the main table, load our entities and set columns/filters + * + * @deprecated since 4.5. Use badges system_report instead. */ + #[\core\attribute\deprecated('course_badges::initialise', since: '4.5', mdl: 'MDL-82503')] protected function initialise(): void { + \core\deprecation::emit_deprecation_if_present([$this, __FUNCTION__]); global $USER; // Our main entity, it contains all of the column definitions that we need. $badgeentity = new badge(); @@ -84,8 +90,11 @@ class course_badges extends system_report { * Validates access to view this report * * @return bool + * @deprecated since 4.5. Use badges system_report instead. */ + #[\core\attribute\deprecated('course_badges::can_view', since: '4.5', mdl: 'MDL-82503')] protected function can_view(): bool { + \core\deprecation::emit_deprecation_if_present([$this, __FUNCTION__]); return has_capability('moodle/badges:viewbadges', $this->get_context()); } @@ -94,8 +103,13 @@ class course_badges extends system_report { * * They are provided by the entities we previously added in the {@see initialise} method, referencing each by their * unique identifier. If custom columns are needed just for this report, they can be defined here. + * + * @param string $badgeissuedalias + * @deprecated since 4.5. Use badges system_report instead. */ + #[\core\attribute\deprecated('course_badges::add_columns', since: '4.5', mdl: 'MDL-82503')] protected function add_columns(): void { + \core\deprecation::emit_deprecation_if_present([$this, __FUNCTION__]); $badgeissuedalias = $this->get_entity('badge_issued')->get_table_alias('badge_issued'); $this->add_columns_from_entities([ @@ -128,8 +142,12 @@ class course_badges extends system_report { * * They are all provided by the entities we previously added in the {@see initialise} method, referencing each by their * unique identifier + * + * @deprecated since 4.5. Use badges system_report instead. */ + #[\core\attribute\deprecated('course_badges::add_filters', since: '4.5', mdl: 'MDL-82503')] protected function add_filters(): void { + \core\deprecation::emit_deprecation_if_present([$this, __FUNCTION__]); $this->add_filters_from_entities([ 'badge:name', 'badge_issued:issued', diff --git a/badges/index.php b/badges/index.php index c3a3b77eac4..3bb0fbae4f6 100644 --- a/badges/index.php +++ b/badges/index.php @@ -48,13 +48,16 @@ if (empty($CFG->badges_allowcoursebadges) && ($type == BADGE_TYPE_COURSE)) { throw new \moodle_exception('coursebadgesdisabled', 'badges'); } +if ($type == BADGE_TYPE_COURSE && !$courseid) { + throw new \moodle_exception('courseidnotfound'); +} + $urlparams = ['type' => $type]; if ($course = $DB->get_record('course', ['id' => $courseid])) { $urlparams['id'] = $course->id; } -$hdr = get_string('managebadges', 'badges'); $returnurl = new moodle_url('/badges/index.php', $urlparams); $PAGE->set_url($returnurl); $PAGE->add_body_class('limitedwidth'); @@ -64,31 +67,34 @@ if ($type == BADGE_TYPE_SITE) { $PAGE->set_context(context_system::instance()); $PAGE->set_pagelayout('admin'); $PAGE->set_heading(get_string('administrationsite')); - navigation_node::override_active_url(new moodle_url('/badges/index.php', array('type' => BADGE_TYPE_SITE)), true); + navigation_node::override_active_url(new moodle_url('/badges/index.php', ['type' => BADGE_TYPE_SITE]), true); + $eventotherparams = ['badgetype' => BADGE_TYPE_SITE]; } else { require_login($course); $coursecontext = context_course::instance($course->id); $title = get_string('coursebadges', 'badges'); $PAGE->set_context($coursecontext); $PAGE->set_pagelayout('incourse'); - $PAGE->set_heading(format_string($course->fullname, true, array('context' => $coursecontext))); + $PAGE->set_heading(format_string($course->fullname, true, ['context' => $coursecontext])); navigation_node::override_active_url( - new moodle_url('/badges/index.php', array('type' => BADGE_TYPE_COURSE, 'id' => $course->id)) + new moodle_url('/badges/index.php', ['type' => BADGE_TYPE_COURSE, 'id' => $course->id]) ); + $eventotherparams = ['badgetype' => BADGE_TYPE_COURSE, 'courseid' => $course->id]; } -if (!has_any_capability(array( +if (!has_any_capability([ + 'moodle/badges:viewbadges', 'moodle/badges:viewawarded', 'moodle/badges:createbadge', 'moodle/badges:awardbadge', 'moodle/badges:configurecriteria', 'moodle/badges:configuremessages', 'moodle/badges:configuredetails', - 'moodle/badges:deletebadge'), $PAGE->context)) { + 'moodle/badges:deletebadge'], $PAGE->context)) { redirect($CFG->wwwroot); } -$PAGE->set_title($hdr); +$PAGE->set_title($title); /** @var core_badges_renderer $output */ $output = $PAGE->get_renderer('core', 'badges'); @@ -102,14 +108,14 @@ if ($delete || $archive) { // Archive this badge? echo $output->heading(get_string('archivebadge', 'badges', $badge->name)); $archivebutton = $output->single_button( - new moodle_url($PAGE->url, array('archive' => $badge->id, 'confirm' => 1)), + new moodle_url($PAGE->url, ['archive' => $badge->id, 'confirm' => 1]), get_string('archiveconfirm', 'badges')); echo $output->box(get_string('archivehelp', 'badges') . $archivebutton, 'generalbox'); // Delete this badge? echo $output->heading(get_string('delbadge', 'badges', $badge->name)); $deletebutton = $output->single_button( - new moodle_url($PAGE->url, array('delete' => $badge->id, 'confirm' => 1)), + new moodle_url($PAGE->url, ['delete' => $badge->id, 'confirm' => 1]), get_string('delconfirm', 'badges')); echo $output->box(get_string('deletehelp', 'badges') . $deletebutton, 'generalbox'); @@ -140,20 +146,28 @@ if ($deactivate && has_capability('moodle/badges:configuredetails', $PAGE->conte } echo $OUTPUT->header(); -$backurl = $type == BADGE_TYPE_SITE ? null : new moodle_url('/badges/view.php', ['type' => $type, 'id' => $courseid]); -$actionbar = new \core_badges\output\standard_action_bar($PAGE, $type, false, true, $backurl); -echo $output->render_tertiary_navigation($actionbar); +echo $OUTPUT->container_start('badges-heading'); if ($type == BADGE_TYPE_SITE) { - echo $OUTPUT->heading_with_help($hdr, 'sitebadges', 'badges'); + echo $OUTPUT->heading_with_help($title, 'sitebadges', 'badges'); } else { - echo $OUTPUT->heading($hdr); + echo $OUTPUT->heading($title); } +$actionbar = new \core_badges\output\standard_action_bar( + page: $PAGE, + type: $type, + showaddbadge: true, +); +echo $output->render_tertiary_navigation($actionbar); +echo $OUTPUT->container_end(); echo $OUTPUT->box('', 'notifyproblem hide', 'check_connection'); if ($course && $course->startdate > time()) { - echo $OUTPUT->box(get_string('error:notifycoursedate', 'badges'), 'generalbox notifyproblem'); + echo $OUTPUT->notification( + get_string('error:notifycoursedate', 'badges', userdate($course->startdate)), + 'warning' + ); } if ($msg !== '') { @@ -161,8 +175,13 @@ if ($msg !== '') { } $report = system_report_factory::create(badges::class, $PAGE->context); -echo $report->output(); +echo $report->output(); $PAGE->requires->js_call_amd('core_badges/actions', 'init'); +// Trigger event, badge listing viewed. +$eventparams = ['context' => $PAGE->context, 'other' => $eventotherparams]; +$event = \core\event\badge_listing_viewed::create($eventparams); +$event->trigger(); + echo $OUTPUT->footer(); diff --git a/badges/tests/behat/add_badge.feature b/badges/tests/behat/add_badge.feature index 785b44c1180..5791f056e2b 100644 --- a/badges/tests/behat/add_badge.feature +++ b/badges/tests/behat/add_badge.feature @@ -67,8 +67,8 @@ Feature: Add badges to the system | Image caption | Test caption image | And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" - And I navigate to "Badges > Manage badges" in site administration - And I press "Add a new badge" + And I wait until the page is ready + And I navigate to "Badges > Add a new badge" in site administration And I set the following fields to these values: | Name | Test Badge 2 | | Version | v2 | @@ -82,6 +82,7 @@ Feature: Add badges to the system And I should see "This badge does not have any related badges." And I press "Add related badge" And I follow "Related badges" + And I wait until the page is ready And I follow "Related badges" And I set the field "relatedbadgeids[]" to "Test Badge 1 (version: v1, language: French, Site badges)" When I press "Save changes" @@ -168,13 +169,12 @@ Feature: Add badges to the system And I am on homepage When I click on "Site pages" "list_item" in the "Navigation" "block" And I click on "Site badges" "link" in the "Navigation" "block" - Then I should see "Manage badges" - And I should see "Add a new badge" + Then I should see "Add a new badge" @javascript @_file_upload Scenario: Edit a site badge Given the following "core_badges > Badge" exists: - | name | Site badge | + | name | Testing site badge | | status | inactive | | version | 1 | | language | ca | @@ -184,11 +184,11 @@ Feature: Add badges to the system | imagecaption | My caption image | | issuercontact | testuser@example.com | And the following "core_badges > Criterias" exist: - | badge | role | - | Site badge | editingteacher | + | badge | role | + | Testing site badge | editingteacher | And I navigate to "Badges > Manage badges" in site administration - When I press "Edit" action in the "Site badge" report row - And I should see "Site badge" + When I press "Edit" action in the "Testing site badge" report row + And I should see "Testing site badge" And the field "Issuer contact" matches value "testuser@example.com" And I set the following fields to these values: | Name | Test badge with 'apostrophe' and other friends (<>&@#) | @@ -203,7 +203,7 @@ Feature: Add badges to the system And I select "Overview" from the "jump" singleselect And I expand all fieldsets Then I should see "Test badge with 'apostrophe' and other friends (&@#)" - And I should not see "Site badge" + And I should not see "Testing site badge" And I should see "secondversion" And I should not see "firstversion" And I should see "Math" @@ -218,42 +218,3 @@ Feature: Add badges to the system | badges_defaultissuername | Test Badge Site | And I navigate to "Badges > Add a new badge" in site administration And the field "Issuer name" matches value "Test Badge Site" - - Scenario: Cancel button behaviour when creating badges - Given the following "course" exists: - | fullname | Course 1 | - | shortname | C1 | - And the following "core_badges > Badge" exists: - | name | Site Badge 1 | - | description | Site badge 1 description | - | image | badges/tests/behat/badge.png | - | status | 0 | - | type | 1 | - And the following "core_badges > Badge" exists: - | name | Course Badge 1 | - | course | C1 | - | description | Course badge 1 description | - | image | badges/tests/behat/badge.png | - | status | 0 | - | type | 2 | - # Site badge: cancel when creating. - When I navigate to "Badges > Add a new badge" in site administration - And I click on "Cancel" "button" - Then I should see "Manage badges" - And I should see "Add a new badge" - # Site badge: cancel when editing. - And I press "Edit" action in the "Site Badge 1" report row - And I click on "Cancel" "button" - And I should see "Site badge 1" - And I should not see "Save changes" - # Course badge: cancel when creating. - And I am on the "Course 1" "course" page - And I navigate to "Badges > Manage badges > Add a new badge" in current page administration - And I click on "Cancel" "button" - Then I should see "Manage badges" - And I should see "Add a new badge" - # Course badge: cancel when editing. - And I press "Edit" action in the "Course Badge 1" report row - And I click on "Cancel" "button" - And I should see "Course badge 1" - And I should not see "Save changes" diff --git a/badges/tests/behat/award_badge.feature b/badges/tests/behat/award_badge.feature index d6c2c8498e1..57c4f0423a2 100644 --- a/badges/tests/behat/award_badge.feature +++ b/badges/tests/behat/award_badge.feature @@ -37,7 +37,7 @@ Feature: Award badges | badge | Course Badge 1 | | role | editingteacher | And I am on the "Course 1" "course" page logged in as "teacher1" - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration And I follow "Course Badge 2" And I select "Criteria" from the "jump" singleselect # Set "course badge 1" as criteria for Badge 2. @@ -47,7 +47,7 @@ Feature: Award badges And I press "Enable access" And I click on "Enable" "button" in the "Confirm" "dialogue" And I am on "Course 1" course homepage - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration And I follow "Course Badge 1" And I select "Recipients (0)" from the "jump" singleselect And I press "Award badge" @@ -55,7 +55,7 @@ Feature: Award badges And I set the field "potentialrecipients[]" to "Student 1 (student1@example.com)" When I press "Award badge" And I am on "Course 1" course homepage - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration And I follow "Course Badge 1" And I select "Recipients (1)" from the "jump" singleselect Then I should see "Recipients (1)" @@ -70,16 +70,26 @@ Feature: Award badges When I follow "Badges" Then I should see "Course Badge 1" And I should see "Course Badge 2" - And I should not see "Manage badges" And I should not see "Add a new badge" + # Student 1 should have both badges in the course too. + And I am on "Course 1" course homepage + And I navigate to "Badges" in current page administration + And I should see "Course Badge 1" + And I should see "Course Badge 2" + And I should not see "Course badge 1 description" + And I should not see "Course badge 2 description" + And I should not see "Recipients" + And I should not see "Badge status" + And I follow "Course Badge 1" + And I should see "Course badge 1 description" + And I should not see "Course badge 2 description" And I log out # Teacher 1 should have access to manage/create badges in the Badges navigation section. When I log in as "teacher1" And I am on "Course 1" course homepage - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration Then I should see "Course Badge 1" And I should see "Course Badge 2" - And I should see "Manage badges" And I should see "Add a new badge" # Teacher 1 should NOT have access to manage/create site badges in the Site badges section. When I am on homepage @@ -91,7 +101,6 @@ Feature: Award badges And I click on "Site pages" "list_item" in the "Navigation" "block" And I click on "Site badges" "link" in the "Navigation" "block" Then I should see "There are no matching badges available for users to earn" - And I should not see "Manage badges" And I should not see "Add a new badge" @javascript @@ -127,6 +136,7 @@ Feature: Award badges And I press "Update profile" And I follow "Profile" in the user menu Then I should see "Profile Badge" + And I should not see "There are no matching badges available for users to earn" @javascript Scenario: Award site badge @@ -169,7 +179,7 @@ Feature: Award badges | badge | Course Badge | | role | editingteacher | And I am on the "Course 1" "course" page logged in as "teacher1" - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration And I follow "Course Badge" And I select "Recipients (0)" from the "jump" singleselect And I press "Award badge" @@ -178,7 +188,7 @@ Feature: Award badges And I set the field "potentialrecipients[]" to "Student 1 (student1@example.com)" When I press "Award badge" And I am on "Course 1" course homepage - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration And I follow "Course Badge" Then I should see "Recipients (2)" And I log out @@ -198,7 +208,7 @@ Feature: Award badges | status | 0 | | type | 2 | And I am on the "Course 1" "course" page logged in as "teacher1" - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration And I follow "Course Badge" And I select "Criteria" from the "jump" singleselect And I set the field "type" to "Activity completion" @@ -240,7 +250,7 @@ Feature: Award badges And I set the field "Assignment - Music history" to "1" And I press "Save changes" And I am on "Course 1" course homepage - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration And I follow "Course Badge" And I select "Criteria" from the "jump" singleselect And I set the field "type" to "Course completion" @@ -280,7 +290,7 @@ Feature: Award badges | badge | Course Badge 1 | | role | editingteacher | And I am on the "Course 1" "course" page logged in as "teacher1" - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration And I follow "Course Badge 1" And I select "Recipients (0)" from the "jump" singleselect And I press "Award badge" @@ -288,7 +298,7 @@ Feature: Award badges And I set the field "potentialrecipients[]" to "Student 1 (student1@example.com)" When I press "Award badge" And I am on "Course 1" course homepage - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration And I follow "Course Badge 1" And I select "Recipients (1)" from the "jump" singleselect Then I should see "Recipients (1)" @@ -300,7 +310,7 @@ Feature: Award badges | image | badges/tests/behat/badge.png | | status | 0 | | type | 2 | - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration And I follow "Course Badge 2" And I select "Criteria" from the "jump" singleselect And I set the field "type" to "Manual issue by role" @@ -317,7 +327,7 @@ Feature: Award badges And I set the field "potentialrecipients[]" to "Student 2 (student2@example.com)" When I press "Award badge" And I am on "Course 1" course homepage - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration And I follow "Course Badge 2" And I select "Recipients (1)" from the "jump" singleselect Then I should see "Recipients (1)" @@ -350,7 +360,7 @@ Feature: Award badges | badge | Course Badge | | role | editingteacher | And I am on the "Course 1" "course" page logged in as "teacher1" - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration And I follow "Course Badge" And I select "Recipients (0)" from the "jump" singleselect And I press "Award badge" @@ -359,7 +369,7 @@ Feature: Award badges And I set the field "potentialrecipients[]" to "Student 1 (student1@example.com)" When I press "Award badge" And I am on "Course 1" course homepage - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration And I follow "Course Badge" Then I should see "Recipients (2)" And I select "Recipients (2)" from the "jump" singleselect @@ -369,6 +379,6 @@ Feature: Award badges And I set the field "existingrecipients[]" to "Student 1 (student1@example.com)" When I press "Revoke badge" And I am on "Course 1" course homepage - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration And I follow "Course Badge" Then I should see "Recipients (0)" diff --git a/badges/tests/behat/award_badge_groups.feature b/badges/tests/behat/award_badge_groups.feature index 798787636eb..0deb7911801 100644 --- a/badges/tests/behat/award_badge_groups.feature +++ b/badges/tests/behat/award_badge_groups.feature @@ -38,7 +38,7 @@ Feature: Award badges with separate groups | status | 0 | | type | 2 | And I am on the "Course 1" "course" page logged in as "teacher1" - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration And I follow "Course Badge" And I select "Criteria" from the "jump" singleselect And I set the field "type" to "Manual issue by role" @@ -55,7 +55,7 @@ Feature: Award badges with separate groups Scenario: Award course badge as non-editing teacher with only one group When I log in as "teacher2" And I am on "Course 1" course homepage - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration And I follow "Course Badge" And I press "Award badge" And I set the field "role" to "Non-editing teacher" @@ -68,7 +68,7 @@ Feature: Award badges with separate groups And I set the field "potentialrecipients[]" to "Student 2 (student2@example.com)" And I press "Award badge" And I am on "Course 1" course homepage - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration And I follow "Course Badge" And I should see "Recipients (1)" And I log out @@ -89,7 +89,7 @@ Feature: Award badges with separate groups And I log out When I log in as "teacher2" And I am on "Course 1" course homepage - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration And I follow "Course Badge" And I press "Award badge" And I set the field "role" to "Non-editing teacher" @@ -114,7 +114,7 @@ Feature: Award badges with separate groups And I log out When I log in as "teacher2" And I am on "Course 1" course homepage - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration And I follow "Course Badge" And I press "Award badge" # Teacher 2 shouldn't be able to go further @@ -123,7 +123,7 @@ Feature: Award badges with separate groups @javascript Scenario: Editing teacher can award badge to members of separate groups Given I am on the "Course 1" course page logged in as teacher1 - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration And I follow "Course Badge" And I press "Award badge" When I set the field "role" to "Teacher" @@ -155,7 +155,7 @@ Feature: Award badges with separate groups And I set the field "Group mode" to "Visible groups" And I press "Save and display" When I am on the "Course 1" course page logged in as - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration And I follow "Course Badge" And I press "Award badge" And I set the field "role" to "" @@ -196,7 +196,7 @@ Feature: Award badges with separate groups And I set the field "Group mode" to "No groups" And I press "Save and display" When I am on the "Course 1" course page logged in as - And I navigate to "Badges > Manage badges" in current page administration + And I navigate to "Badges" in current page administration And I follow "Course Badge" And I press "Award badge" And I set the field "role" to "" diff --git a/badges/tests/behat/badge_navigation.feature b/badges/tests/behat/badge_navigation.feature index 7d80f81a42d..c2dff101ec1 100644 --- a/badges/tests/behat/badge_navigation.feature +++ b/badges/tests/behat/badge_navigation.feature @@ -46,28 +46,14 @@ Feature: Test tertiary navigation as various users Given I log in as "" And I am on "Course 1" course homepage When I navigate to "Badges" in current page administration - Then "Manage badges" "button" should exist - And "Add a new badge" "button" + Then "Add a new badge" "button" And I should see "" is active in secondary navigation - And I click on "Manage badges" "button" - And "Manage badges" "button" should not exist - And "Back" "button" should exist - And "Add a new badge" "button" - And I should see "" is active in secondary navigation - And I click on "Back" "button" And "Back" "button" should not exist - And "Manage badges" "button" should exist - And "Add a new badge" "button" - And I should see "" is active in secondary navigation - And I click on "Manage badges" "button" And I click on "Testing course badge" "link" - And "Manage badges" "button" should not exist And "Add a new badge" "button" should not exist And "Back" "button" should exist And I should see "" is active in secondary navigation And I click on "Back" "button" - And "Back" "button" should exist - And "Manage badges" "button" should not exist And "Add a new badge" "button" And I should see "" is active in secondary navigation @@ -84,7 +70,6 @@ Feature: Test tertiary navigation as various users # Enable one badge. When I am on the "C1" "Course" page logged in as "admin" And I navigate to "Badges" in current page administration - And I click on "Manage badges" "button" And I press "Enable access" action in the "Testing course badge" report row And I click on "Enable" "button" in the "Confirm" "dialogue" And I log out @@ -93,24 +78,20 @@ Feature: Test tertiary navigation as various users Then "Badges" "link" should exist in current page administration And I navigate to "Badges" in current page administration And "Back" "button" should not exist - And "Manage badges" "button" should not exist And "Add a new badge" "button" should not exist And I should see "Badges" is active in secondary navigation Scenario: Check navigation as an admin in a site context Given I log in as "admin" When I navigate to "Badges > Manage badges" in site administration - Then "Manage badges" "button" should not exist - And "Add a new badge" "button" should exist + Then "Add a new badge" "button" should exist And I should see "General" is active in secondary navigation And I click on "Testing site badge" "link" - And "Manage badges" "button" should not exist And "Add a new badge" "button" should not exist And "Back" "button" should exist And I should see "General" is active in secondary navigation And I click on "Back" "button" And "Back" "button" should not exist - And "Manage badges" "button" should not exist And "Add a new badge" "button" should exist Scenario Outline: Check secondary navigation highlights after tertiary nav jumps in site admin @@ -135,7 +116,6 @@ Feature: Test tertiary navigation as various users Given I log in as "admin" And I am on "Course 1" course homepage And I navigate to "Badges" in current page administration - And I click on "Manage badges" "button" And I click on "Testing course badge" "link" When I select "