diff --git a/badges/action.php b/badges/action.php
index a3bdb568bed..c2a152db320 100644
--- a/badges/action.php
+++ b/badges/action.php
@@ -42,11 +42,14 @@ $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type));
if ($badge->type == BADGE_TYPE_COURSE) {
require_login($badge->courseid);
+ $course = get_course($badge->courseid);
+ $heading = format_string($course->fullname, true, ['context' => $context]);
$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
$PAGE->set_pagelayout('standard');
navigation_node::override_active_url($navurl);
} else {
$PAGE->set_pagelayout('admin');
+ $heading = get_string('administrationsite');
navigation_node::override_active_url($navurl, true);
}
@@ -107,7 +110,7 @@ if ($activate) {
$strheading = get_string('reviewbadge', 'badges');
$PAGE->navbar->add($strheading);
$PAGE->set_title($strheading);
- $PAGE->set_heading($badge->name);
+ $PAGE->set_heading($heading);
echo $OUTPUT->header();
echo $OUTPUT->heading($strheading);
diff --git a/badges/alignment.php b/badges/alignment.php
index cf5b4336582..71c349b43e8 100644
--- a/badges/alignment.php
+++ b/badges/alignment.php
@@ -45,18 +45,21 @@ if ($badge->type == BADGE_TYPE_COURSE) {
print_error('coursebadgesdisabled', 'badges');
}
require_login($badge->courseid);
+ $course = get_course($badge->courseid);
+ $heading = format_string($course->fullname, true, ['context' => $context]);
$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
$PAGE->set_pagelayout('standard');
navigation_node::override_active_url($navurl);
} else {
$PAGE->set_pagelayout('admin');
+ $heading = get_string('administrationsite');
navigation_node::override_active_url($navurl, true);
}
$currenturl = new moodle_url('/badges/alignment.php', array('id' => $badge->id));
$PAGE->set_context($context);
$PAGE->set_url($currenturl);
-$PAGE->set_heading($badge->name);
+$PAGE->set_heading($heading);
$PAGE->set_title($badge->name);
$PAGE->navbar->add($badge->name);
@@ -80,9 +83,10 @@ if ($mform->is_cancelled()) {
}
echo $OUTPUT->header();
+$actionbar = new \core_badges\output\manage_badge_action_bar($badge, $PAGE);
+echo $output->render_tertiary_navigation($actionbar);
echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
echo $output->print_badge_status_box($badge);
-$output->print_badge_tabs($badgeid, $context, 'alignment');
if ($emsg !== '') {
echo $OUTPUT->notification($emsg);
} else if ($msg !== '') {
diff --git a/badges/award.php b/badges/award.php
index 8f8669829f0..99b30f3b442 100644
--- a/badges/award.php
+++ b/badges/award.php
@@ -50,11 +50,14 @@ if ($badge->type == BADGE_TYPE_COURSE) {
print_error('coursebadgesdisabled', 'badges');
}
require_login($badge->courseid);
+ $course = get_course($badge->courseid);
+ $heading = format_string($course->fullname, true, ['context' => $context]);
$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
$PAGE->set_pagelayout('standard');
navigation_node::override_active_url($navurl);
} else {
$PAGE->set_pagelayout('admin');
+ $heading = get_string('administrationsite');
navigation_node::override_active_url($navurl, true);
}
@@ -68,7 +71,7 @@ $PAGE->set_context($context);
$strrecipients = get_string('recipients', 'badges');
$PAGE->navbar->add($badge->name, new moodle_url('overview.php', array('id' => $badge->id)))->add($strrecipients);
$PAGE->set_title($strrecipients);
-$PAGE->set_heading($badge->name);
+$PAGE->set_heading($heading);
if (!$badge->is_active()) {
echo $OUTPUT->header();
@@ -77,15 +80,18 @@ if (!$badge->is_active()) {
die();
}
+$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);
$output = $PAGE->get_renderer('core', 'badges');
+$tertiarynav = $output->render_tertiary_navigation($actionbar);
// Roles that can award this badge.
$acceptedroles = array_keys($badge->criteria[BADGE_CRITERIA_TYPE_MANUAL]->params);
if (empty($acceptedroles)) {
echo $OUTPUT->header();
- $return = html_writer::link(new moodle_url('recipients.php', array('id' => $badge->id)), $strrecipients);
- echo $OUTPUT->notification(get_string('notacceptedrole', 'badges', $return));
+ echo $OUTPUT->notification(get_string('notacceptedrole', 'badges', $returnlink));
echo $OUTPUT->footer();
die();
}
@@ -126,6 +132,7 @@ if (count($acceptedroles) > 1) {
if (!$role) {
$pageurl = new moodle_url('/badges/award.php', array('id' => $badgeid));
echo $OUTPUT->header();
+ echo $tertiarynav;
echo $OUTPUT->box($OUTPUT->single_select(new moodle_url($pageurl), 'role', $select, '', array('' => 'choosedots'),
null, array('label' => get_string('selectaward', 'badges'))));
echo $OUTPUT->footer();
@@ -139,8 +146,7 @@ if (count($acceptedroles) > 1) {
}
} else {
echo $OUTPUT->header();
- $return = html_writer::link(new moodle_url('recipients.php', array('id' => $badge->id)), $strrecipients);
- echo $OUTPUT->notification(get_string('notacceptedrole', 'badges', $return));
+ echo $OUTPUT->notification(get_string('notacceptedrole', 'badges', $returnlink));
echo $OUTPUT->footer();
die();
}
@@ -150,8 +156,7 @@ if (count($acceptedroles) > 1) {
$usersids = array_keys($users);
if (!$isadmin && !in_array($USER->id, $usersids)) {
echo $OUTPUT->header();
- $return = html_writer::link(new moodle_url('recipients.php', array('id' => $badge->id)), $strrecipients);
- echo $OUTPUT->notification(get_string('notacceptedrole', 'badges', $return));
+ echo $OUTPUT->notification(get_string('notacceptedrole', 'badges', $returnlink));
echo $OUTPUT->footer();
die();
} else {
@@ -206,6 +211,7 @@ if ($award && data_submitted() && has_capability('moodle/badges:awardbadge', $co
}
echo $OUTPUT->header();
+echo $tertiarynav;
echo $OUTPUT->heading($strrecipients);
// Print group selector/dropdown menu (find out current groups mode).
diff --git a/badges/classes/output/base_action_bar.php b/badges/classes/output/base_action_bar.php
new file mode 100644
index 00000000000..6b89d331338
--- /dev/null
+++ b/badges/classes/output/base_action_bar.php
@@ -0,0 +1,53 @@
+.
+
+namespace core_badges\output;
+
+use renderable;
+use templatable;
+use moodle_page;
+
+/**
+ * Abstract class for the badges tertiary navigation. The class initialises the page and type class variables.
+ *
+ * @package core_badges
+ * @copyright 2021 Peter Dias
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+abstract class base_action_bar implements renderable, templatable {
+ /** @var moodle_page $page The context we are operating within. */
+ protected $page;
+ /** @var int $type The badge type. */
+ protected $type;
+
+ /**
+ * standard_action_bar constructor.
+ *
+ * @param moodle_page $page
+ * @param int $type
+ */
+ public function __construct(moodle_page $page, int $type) {
+ $this->type = $type;
+ $this->page = $page;
+ }
+
+ /**
+ * The template that this tertiary nav should use.
+ *
+ * @return string
+ */
+ abstract public function get_template(): string;
+}
diff --git a/badges/classes/output/manage_badge_action_bar.php b/badges/classes/output/manage_badge_action_bar.php
new file mode 100644
index 00000000000..5cc712b5237
--- /dev/null
+++ b/badges/classes/output/manage_badge_action_bar.php
@@ -0,0 +1,172 @@
+.
+
+namespace core_badges\output;
+
+use core_badges\badge;
+use moodle_url;
+use renderer_base;
+use single_button;
+use moodle_page;
+use url_select;
+
+/**
+ * Class manage_badge_action_bar - Display the action bar
+ *
+ * @package core_badges
+ * @copyright 2021 Peter Dias
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class manage_badge_action_bar extends base_action_bar {
+ /** @var badge $badge The badge we are managing. */
+ protected $badge;
+
+ /**
+ * manage_badge_action_bar constructor
+ *
+ * @param badge $badge The badge we are viewing
+ * @param moodle_page $page The page object
+ */
+ public function __construct(badge $badge, moodle_page $page) {
+ parent::__construct($page, $badge->type);
+ $this->badge = $badge;
+ }
+
+ /**
+ * The template that this tertiary nav should use.
+ *
+ * @return string
+ */
+ public function get_template(): string {
+ return 'core_badges/manage_badge';
+ }
+
+ /**
+ * Export the action bar
+ *
+ * @param renderer_base $output
+ * @return array
+ */
+ public function export_for_template(renderer_base $output): array {
+ $elements = [];
+ $params = ['type' => $this->type];
+ if ($this->page->context->contextlevel == CONTEXT_COURSE) {
+ $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);
+ foreach ($elements as $key => $element) {
+ $elements[$key] = $element->export_for_template($output);
+ }
+
+ return $elements;
+ }
+
+ /**
+ * Returns a multi dimensional array of the links that should be displayed when creating a badge.
+ * The keys of the array feed into the text shown to the user and content of each element contain the following:
+ * - url URL for the option
+ * - additionalparams Additional params to feed into the url
+ * - capability The capabilities to check that governs visibility
+ * @return array
+ */
+ protected function get_badge_administration_mapping_construct(): array {
+ return [
+ 'boverview' => [
+ 'url' => '/badges/overview.php',
+ 'capability' => ''
+ ],
+ 'bdetails' => [
+ 'url' => '/badges/edit.php',
+ 'additionalparams' => ['action' => 'badge'],
+ 'capability' => 'moodle/badges:configuredetails'
+ ],
+ 'bcriteria' => [
+ 'url' => '/badges/criteria.php',
+ 'capability' => 'moodle/badges:configurecriteria'
+ ],
+ 'bmessage' => [
+ 'url' => '/badges/edit.php',
+ 'additionalparams' => ['action' => 'message'],
+ 'capability' => 'moodle/badges:configuremessages'
+ ],
+ 'bawards' => [
+ 'url' => '/badges/recipients.php',
+ 'additionalparams' => ['sort' => 'dateissued', 'dir' => 'DESC'],
+ 'capability' => 'moodle/badges:viewawarded'
+ ],
+ 'bendorsement' => [
+ 'url' => '/badges/endorsement.php',
+ 'capability' => 'moodle/badges:configuredetails'
+ ],
+ 'brelated' => [
+ 'url' => '/badges/related.php',
+ 'capability' => 'moodle/badges:configuredetails'
+ ],
+ 'balignment' => [
+ 'url' => '/badges/alignment.php',
+ 'capability' => 'moodle/badges:configuredetails'
+ ],
+ ];
+ }
+
+ /**
+ * Generate the options to be displayed when editing a badge. This feeds into a URL select which will be displayed
+ * in the tertiary navigation.
+ *
+ * @return array
+ */
+ protected function generate_badge_navigation(): array {
+ global $DB;
+ $params = ['id' => $this->badge->id];
+ $options = [];
+ $construct = $this->get_badge_administration_mapping_construct();
+ foreach ($construct as $stringidentifier => $checks) {
+ if ($checks['capability'] && !has_capability($checks['capability'], $this->page->context)) {
+ continue;
+ }
+
+ $sql = '';
+ switch ($stringidentifier) {
+ case 'bawards':
+ $sql = "SELECT COUNT(b.userid)
+ FROM {badge_issued} b
+ INNER JOIN {user} u ON b.userid = u.id
+ WHERE b.badgeid = :badgeid AND u.deleted = 0";
+ break;
+ case 'brelated':
+ $sql = "SELECT COUNT(br.badgeid)
+ FROM {badge_related} br
+ WHERE (br.badgeid = :badgeid OR br.relatedbadgeid = :badgeid2)";
+ break;
+ case 'balignment':
+ $sql = "SELECT COUNT(bc.id)
+ FROM {badge_alignment} bc
+ WHERE bc.badgeid = :badgeid";
+ break;
+ }
+
+ $content = null;
+ if ($sql) {
+ $content = $DB->count_records_sql($sql, ['badgeid' => $this->badge->id, 'badgeid2' => $this->badge->id]);
+ }
+
+ $url = new moodle_url($checks['url'], $params + ($checks['additionalparams'] ?? []));
+ $options[get_string($stringidentifier, 'core_badges', $content)] = $url->out(false);
+ }
+ return array_flip($options);
+ }
+}
diff --git a/badges/classes/output/recipients_action_bar.php b/badges/classes/output/recipients_action_bar.php
new file mode 100644
index 00000000000..6720aff31cd
--- /dev/null
+++ b/badges/classes/output/recipients_action_bar.php
@@ -0,0 +1,59 @@
+.
+
+namespace core_badges\output;
+
+use moodle_url;
+use renderer_base;
+use single_button;
+
+/**
+ * Class recipients_action_bar - Display the action bar
+ *
+ * @package core_badges
+ * @copyright 2021 Peter Dias
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class recipients_action_bar extends manage_badge_action_bar {
+ /**
+ * The template that this tertiary nav should use.
+ *
+ * @return string
+ */
+ public function get_template(): string {
+ return 'core_badges/award_badge';
+ }
+
+ /**
+ * Export the action bar
+ *
+ * @param renderer_base $output
+ * @return array
+ */
+ public function export_for_template(renderer_base $output): array {
+ $elements = parent::export_for_template($output);
+
+ // Add button for badge manual award.
+ if ($this->badge->has_manual_award_criteria()
+ && has_capability('moodle/badges:awardbadge', $this->page->context) && $this->badge->is_active()) {
+ $url = new moodle_url('/badges/award.php', ['id' => $this->badge->id]);
+ $button = new single_button($url, get_string('award', 'badges'), 'post', true);
+ $elements['awardbutton'] = $button->export_for_template($output);
+ }
+
+ return $elements;
+ }
+}
diff --git a/badges/classes/output/standard_action_bar.php b/badges/classes/output/standard_action_bar.php
new file mode 100644
index 00000000000..951d91e24cf
--- /dev/null
+++ b/badges/classes/output/standard_action_bar.php
@@ -0,0 +1,101 @@
+.
+
+namespace core_badges\output;
+
+use moodle_page;
+use moodle_url;
+use renderer_base;
+use single_button;
+
+/**
+ * Class standard_action_bar - Display the action bar
+ *
+ * @package core_badges
+ * @copyright 2021 Peter Dias
+ * @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
+ *
+ * @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) {
+ parent::__construct($page, $type);
+
+ $this->showmanage = $showmanage;
+ $this->showaddbadge = $showaddbadge;
+ $this->backurl = $backurl;
+ }
+
+ /**
+ * The template that this tertiary nav should use.
+ *
+ * @return string
+ */
+ public function get_template(): string {
+ return 'core_badges/manage_badges';
+ }
+
+ /**
+ * Export the action bar
+ *
+ * @param renderer_base $output
+ * @return array The buttons to be rendered
+ */
+ public function export_for_template(renderer_base $output): array {
+ $buttons = [];
+ if ($this->backurl) {
+ $buttons[] = new single_button($this->backurl, get_string('back'), 'get');
+ }
+
+ $params = ['type' => $this->type];
+ if ($this->page->context->contextlevel == CONTEXT_COURSE) {
+ $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)) {
+ $buttons[] = new single_button(new moodle_url('/badges/newbadge.php', $params),
+ get_string('newbadge', 'core_badges'), 'post', true);
+ }
+
+ foreach ($buttons as $key => $button) {
+ $buttons[$key] = $button->export_for_template($output);
+ }
+
+ return ['buttons' => $buttons];
+ }
+}
diff --git a/badges/criteria.php b/badges/criteria.php
index 58f9c0bdaf3..72b880b246d 100644
--- a/badges/criteria.php
+++ b/badges/criteria.php
@@ -47,11 +47,14 @@ if ($badge->type == BADGE_TYPE_COURSE) {
print_error('coursebadgesdisabled', 'badges');
}
require_login($badge->courseid);
+ $course = get_course($badge->courseid);
+ $heading = format_string($course->fullname, true, ['context' => $context]);
$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
$PAGE->set_pagelayout('standard');
navigation_node::override_active_url($navurl);
} else {
$PAGE->set_pagelayout('admin');
+ $heading = get_string('administrationsite');
navigation_node::override_active_url($navurl, true);
}
@@ -59,7 +62,7 @@ $currenturl = new moodle_url('/badges/criteria.php', array('id' => $badge->id));
$PAGE->set_context($context);
$PAGE->set_url($currenturl);
-$PAGE->set_heading($badge->name);
+$PAGE->set_heading($heading);
$PAGE->set_title($badge->name);
$PAGE->navbar->add($badge->name, $currenturl);
@@ -80,6 +83,8 @@ if ((($update == BADGE_CRITERIA_AGGREGATION_ALL) || ($update == BADGE_CRITERIA_A
}
echo $OUTPUT->header();
+$actionbar = new \core_badges\output\manage_badge_action_bar($badge, $PAGE);
+echo $output->render_tertiary_navigation($actionbar);
echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
if ($emsg !== '') {
@@ -87,9 +92,7 @@ if ($emsg !== '') {
} else if ($msg !== '') {
echo $OUTPUT->notification(get_string($msg, 'badges'), 'notifysuccess');
}
-
echo $output->print_badge_status_box($badge);
-$output->print_badge_tabs($badgeid, $context, 'criteria');
if (!$badge->is_locked() && !$badge->is_active()) {
echo $output->print_criteria_actions($badge);
diff --git a/badges/criteria_settings.php b/badges/criteria_settings.php
index cd2cb213b97..937c01961f6 100644
--- a/badges/criteria_settings.php
+++ b/badges/criteria_settings.php
@@ -57,18 +57,21 @@ if ($badge->is_active() || $badge->is_locked()) {
if ($badge->type == BADGE_TYPE_COURSE) {
require_login($badge->courseid);
+ $course = get_course($badge->courseid);
+ $heading = format_string($course->fullname, true, ['context' => $context]);
$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
$PAGE->set_pagelayout('standard');
navigation_node::override_active_url($navurl);
} else {
$PAGE->set_pagelayout('admin');
+ $heading = get_string('administrationsite');
navigation_node::override_active_url($navurl, true);
}
$urlparams = array('badgeid' => $badgeid, 'edit' => $edit, 'type' => $type, 'crit' => $crit);
$PAGE->set_context($context);
$PAGE->set_url('/badges/criteria_settings.php', $urlparams);
-$PAGE->set_heading($badge->name);
+$PAGE->set_heading($heading);
$PAGE->set_title($badge->name);
$PAGE->navbar->add($badge->name, new moodle_url('overview.php', array('id' => $badge->id)))->add(get_string('criteria_' . $type, 'badges'));
diff --git a/badges/edit.php b/badges/edit.php
index d52a7c810cd..2a12b09a030 100644
--- a/badges/edit.php
+++ b/badges/edit.php
@@ -52,11 +52,14 @@ if ($badge->type == BADGE_TYPE_COURSE) {
print_error('coursebadgesdisabled', 'badges');
}
require_login($badge->courseid);
+ $course = get_course($badge->courseid);
+ $heading = format_string($course->fullname, true, ['context' => $context]);
$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
$PAGE->set_pagelayout('incourse');
navigation_node::override_active_url($navurl);
} else {
$PAGE->set_pagelayout('admin');
+ $heading = get_string('administrationsite');
navigation_node::override_active_url($navurl, true);
}
@@ -64,7 +67,7 @@ $currenturl = new moodle_url('/badges/edit.php', array('id' => $badge->id, 'acti
$PAGE->set_context($context);
$PAGE->set_url($currenturl);
-$PAGE->set_heading($badge->name);
+$PAGE->set_heading($heading);
$PAGE->set_title($badge->name);
$PAGE->navbar->add($badge->name);
@@ -145,6 +148,9 @@ if ($form->is_cancelled()) {
}
echo $OUTPUT->header();
+$actionbar = new \core_badges\output\manage_badge_action_bar($badge, $PAGE);
+echo $output->render_tertiary_navigation($actionbar);
+
echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
if ($errormsg !== '') {
@@ -153,9 +159,7 @@ if ($errormsg !== '') {
} else if ($statusmsg !== '') {
echo $OUTPUT->notification($statusmsg, 'notifysuccess');
}
-
echo $output->print_badge_status_box($badge);
-$output->print_badge_tabs($badgeid, $context, $action);
$form->display();
diff --git a/badges/endorsement.php b/badges/endorsement.php
index d7b2345d62a..ba9b7396c21 100644
--- a/badges/endorsement.php
+++ b/badges/endorsement.php
@@ -44,18 +44,21 @@ if ($badge->type == BADGE_TYPE_COURSE) {
print_error('coursebadgesdisabled', 'badges');
}
require_login($badge->courseid);
+ $course = get_course($badge->courseid);
+ $heading = format_string($course->fullname, true, ['context' => $context]);
$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
$PAGE->set_pagelayout('standard');
navigation_node::override_active_url($navurl);
} else {
$PAGE->set_pagelayout('admin');
+ $heading = get_string('administrationsite');
navigation_node::override_active_url($navurl, true);
}
$currenturl = new moodle_url('/badges/endorsement.php', array('id' => $badgeid));
$PAGE->set_context($context);
$PAGE->set_url($currenturl);
-$PAGE->set_heading($badge->name);
+$PAGE->set_heading($heading);
$PAGE->set_title($badge->name);
$PAGE->navbar->add($badge->name);
@@ -68,10 +71,12 @@ if ($msg !== '') {
}
echo $OUTPUT->header();
-echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
+$actionbar = new \core_badges\output\manage_badge_action_bar($badge, $PAGE);
+echo $output->render_tertiary_navigation($actionbar);
+
+echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
echo $output->print_badge_status_box($badge);
-$output->print_badge_tabs($badgeid, $context, 'bendorsement');
$form = new endorsement_form($currenturl, array('badge' => $badge));
if ($form->is_cancelled()) {
diff --git a/badges/index.php b/badges/index.php
index 9be96e1e27d..a389ea53baa 100644
--- a/badges/index.php
+++ b/badges/index.php
@@ -78,7 +78,7 @@ if ($type == BADGE_TYPE_SITE) {
$title = get_string('sitebadges', 'badges');
$PAGE->set_context(context_system::instance());
$PAGE->set_pagelayout('admin');
- $PAGE->set_heading($title . ': ' . $hdr);
+ $PAGE->set_heading(get_string('administrationsite'));
navigation_node::override_active_url(new moodle_url('/badges/index.php', array('type' => BADGE_TYPE_SITE)), true);
} else {
require_login($course);
@@ -86,7 +86,7 @@ if ($type == BADGE_TYPE_SITE) {
$title = get_string('coursebadges', 'badges');
$PAGE->set_context($coursecontext);
$PAGE->set_pagelayout('incourse');
- $PAGE->set_heading(format_string($course->fullname, true, array('context' => $coursecontext)) . ': ' . $hdr);
+ $PAGE->set_heading(format_string($course->fullname, true, array('context' => $coursecontext)));
navigation_node::override_active_url(
new moodle_url('/badges/index.php', array('type' => BADGE_TYPE_COURSE, 'id' => $course->id))
);
@@ -152,19 +152,22 @@ 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);
+
if ($type == BADGE_TYPE_SITE) {
- echo $OUTPUT->heading_with_help($PAGE->heading, 'sitebadges', 'badges');
+ echo $OUTPUT->heading_with_help($hdr, 'sitebadges', 'badges');
} else {
- echo $OUTPUT->heading($PAGE->heading);
+ echo $OUTPUT->heading($hdr);
}
+
echo $OUTPUT->box('', 'notifyproblem hide', 'check_connection');
$totalcount = count(badges_get_badges($type, $courseid, '', '' , 0, 0));
$records = badges_get_badges($type, $courseid, $sortby, $sorthow, $page, BADGE_PERPAGE);
if ($totalcount) {
- echo $output->heading(get_string('badgestoearn', 'badges', $totalcount), 4);
-
if ($course && $course->startdate > time()) {
echo $OUTPUT->box(get_string('error:notifycoursedate', 'badges'), 'generalbox notifyproblem');
}
@@ -187,11 +190,6 @@ if ($totalcount) {
echo $output->render($badges);
} else {
echo $output->notification(get_string('nobadges', 'badges'));
-
- if (has_capability('moodle/badges:createbadge', $PAGE->context)) {
- echo $OUTPUT->box($OUTPUT->single_button(new moodle_url('newbadge.php', array('type' => $type, 'id' => $courseid)),
- get_string('newbadge', 'badges')));
- }
}
echo $OUTPUT->footer();
diff --git a/badges/overview.php b/badges/overview.php
index fab163f56c8..52f8949fb45 100644
--- a/badges/overview.php
+++ b/badges/overview.php
@@ -45,11 +45,15 @@ if ($badge->type == BADGE_TYPE_COURSE) {
print_error('coursebadgesdisabled', 'badges');
}
require_login($badge->courseid);
+ $course = get_course($badge->courseid);
+ $heading = format_string($course->fullname, true, ['context' => $context]);
+
$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
$PAGE->set_pagelayout('standard');
navigation_node::override_active_url($navurl);
} else {
$PAGE->set_pagelayout('admin');
+ $heading = get_string('administrationsite');
navigation_node::override_active_url($navurl, true);
}
@@ -57,13 +61,16 @@ $currenturl = new moodle_url('/badges/overview.php', array('id' => $badge->id));
$PAGE->set_context($context);
$PAGE->set_url($currenturl);
-$PAGE->set_heading($badge->name);
+$PAGE->set_heading($heading);
$PAGE->set_title($badge->name);
$PAGE->navbar->add($badge->name);
require_capability('moodle/badges:viewbadges', $context);
echo $OUTPUT->header();
+$output = $PAGE->get_renderer('core', 'badges');
+$actionbar = new \core_badges\output\manage_badge_action_bar($badge, $PAGE);
+echo $output->render_tertiary_navigation($actionbar);
echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
if ($awards == 'cron') {
@@ -71,10 +78,7 @@ if ($awards == 'cron') {
} else if ($awards != 0) {
echo $OUTPUT->notification(get_string('numawardstat', 'badges', $awards), 'notifysuccess');
}
-
-$output = $PAGE->get_renderer('core', 'badges');
echo $output->print_badge_status_box($badge);
-$output->print_badge_tabs($badgeid, $context, 'overview');
echo $output->print_badge_overview($badge, $context);
echo $OUTPUT->footer();
diff --git a/badges/recipients.php b/badges/recipients.php
index 83121cdbb81..623d8e64cf4 100644
--- a/badges/recipients.php
+++ b/badges/recipients.php
@@ -59,33 +59,32 @@ if ($badge->type == BADGE_TYPE_COURSE) {
print_error('coursebadgesdisabled', 'badges');
}
require_login($badge->courseid);
+ $course = get_course($badge->courseid);
+ $heading = format_string($course->fullname, true, ['context' => $context]);
$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
$PAGE->set_pagelayout('standard');
navigation_node::override_active_url($navurl);
} else {
$PAGE->set_pagelayout('admin');
+ $heading = get_string('administrationsite');
navigation_node::override_active_url($navurl, true);
}
$PAGE->set_context($context);
$PAGE->set_url('/badges/recipients.php', array('id' => $badgeid, 'sort' => $sortby, 'dir' => $sorthow));
-$PAGE->set_heading($badge->name);
+$PAGE->set_heading($heading);
$PAGE->set_title($badge->name);
$PAGE->navbar->add($badge->name);
$output = $PAGE->get_renderer('core', 'badges');
echo $output->header();
+
+$actionbar = new \core_badges\output\recipients_action_bar($badge, $PAGE);
+echo $output->render_tertiary_navigation($actionbar);
+
echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
-
echo $output->print_badge_status_box($badge);
-$output->print_badge_tabs($badgeid, $context, 'awards');
-
-// Add button for badge manual award.
-if ($badge->has_manual_award_criteria() && has_capability('moodle/badges:awardbadge', $context) && $badge->is_active()) {
- $url = new moodle_url('/badges/award.php', array('id' => $badge->id));
- echo $OUTPUT->box($OUTPUT->single_button($url, get_string('award', 'badges')), 'clearfix mdl-align');
-}
$userfieldsapi = \core_user\fields::for_name();
$namefields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
diff --git a/badges/related.php b/badges/related.php
index 066b5e95f12..f817cf6af4f 100644
--- a/badges/related.php
+++ b/badges/related.php
@@ -48,18 +48,22 @@ if ($badge->type == BADGE_TYPE_COURSE) {
print_error('coursebadgesdisabled', 'badges');
}
require_login($badge->courseid);
+ $course = get_course($badge->courseid);
+ $heading = format_string($course->fullname, true, ['context' => $context]);
+
$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
$PAGE->set_pagelayout('standard');
navigation_node::override_active_url($navurl);
} else {
$PAGE->set_pagelayout('admin');
+ $heading = get_string('administrationsite');
navigation_node::override_active_url($navurl, true);
}
$currenturl = new moodle_url('/badges/related.php', array('id' => $badge->id));
$PAGE->set_context($context);
$PAGE->set_url($currenturl);
-$PAGE->set_heading($badge->name);
+$PAGE->set_heading($heading);
$PAGE->set_title($badge->name);
$PAGE->navbar->add($badge->name);
$output = $PAGE->get_renderer('core', 'badges');
@@ -78,10 +82,13 @@ if ($mform->is_cancelled()) {
redirect($currenturl);
}
echo $OUTPUT->header();
+
+$actionbar = new \core_badges\output\manage_badge_action_bar($badge, $PAGE);
+echo $output->render_tertiary_navigation($actionbar);
+
echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
echo $output->print_badge_status_box($badge);
-$output->print_badge_tabs($badgeid, $context, 'brelated');
if ($emsg !== '') {
echo $OUTPUT->notification($emsg);
} else if ($msg !== '') {
diff --git a/badges/renderer.php b/badges/renderer.php
index 96e6c2af6a5..80bea0c31b1 100644
--- a/badges/renderer.php
+++ b/badges/renderer.php
@@ -476,13 +476,6 @@ class core_badges_renderer extends plugin_renderer_base {
// New badge button.
$htmlnew = '';
- if (has_capability('moodle/badges:createbadge', $this->page->context)) {
- $n['type'] = $this->page->url->get_param('type');
- $n['id'] = $this->page->url->get_param('id');
- $btn = $this->output->single_button(new moodle_url('newbadge.php', $n), get_string('newbadge', 'badges'));
- $htmlnew = $this->output->box($btn);
- }
-
$htmlpagingbar = $this->render($paging);
$table = new html_table();
$table->attributes['class'] = 'table table-bordered table-striped';
@@ -527,6 +520,8 @@ class core_badges_renderer extends plugin_renderer_base {
/**
* Prints tabs for badge editing.
*
+ * @deprecated since Moodle 4.0
+ * @todo MDL-73426 Final deprecation.
* @param integer $badgeid The badgeid to edit.
* @param context $context The current context.
* @param string $current The currently selected tab.
@@ -534,6 +529,8 @@ class core_badges_renderer extends plugin_renderer_base {
*/
public function print_badge_tabs($badgeid, $context, $current = 'overview') {
global $DB;
+ debugging("print_badge_tabs() is deprecated. " .
+ "This is replaced with the manage_badge_action_bar tertiary navigation.", DEBUG_DEVELOPER);
$badge = new badge($badgeid);
$row = array();
@@ -1131,4 +1128,14 @@ class core_badges_renderer extends plugin_renderer_base {
return $result;
}
+
+ /**
+ * Render the tertiary navigation for the page.
+ *
+ * @param \core_badges\output\base_action_bar $actionbar
+ * @return bool|string
+ */
+ public function render_tertiary_navigation(\core_badges\output\base_action_bar $actionbar) {
+ return $this->render_from_template($actionbar->get_template(), $actionbar->export_for_template($this));
+ }
}
diff --git a/badges/templates/award_badge.mustache b/badges/templates/award_badge.mustache
new file mode 100644
index 00000000000..7e2ab5e50cb
--- /dev/null
+++ b/badges/templates/award_badge.mustache
@@ -0,0 +1,107 @@
+{{!
+ 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 .
+}}
+{{!
+ @template core_badges/award_badge
+ Displays the tertiary nav for the badge recipients page
+
+ Context variables required for this template:
+ * button stdClass - The back button to be rendered
+ * urlselect stdClass - The URL select to be rendered
+ * awardbutton stdClass - The award badge button to be rendered
+
+ Example context (json):
+ {
+ "button": {
+ "id": "buttons_button",
+ "method" : "get",
+ "url" : "#",
+ "primary" : true,
+ "tooltip" : "This is a tooltip",
+ "label" : "Button2",
+ "attributes": [
+ {
+ "name": "data-attribute",
+ "value": "yeah"
+ }
+ ]
+ },
+ "urlselect": {
+ "id": "url_select_test",
+ "action": "https://example.com/post",
+ "formid": "url_select_form",
+ "sesskey": "sesskey",
+ "label": "core/url_select",
+ "helpicon": {
+ "title": "Help with something",
+ "text": "Help with something",
+ "url": "http://example.org/help",
+ "linktext": "",
+ "icon":{
+ "extraclasses": "iconhelp",
+ "attributes": [
+ {"name": "src", "value": "../../../pix/help.svg"},
+ {"name": "alt", "value": "Help icon"}
+ ]
+ }
+ },
+ "showbutton": "Go",
+ "options": [{
+ "name": "Group 1", "isgroup": true, "options":
+ [
+ {"name": "Item 1", "isgroup": false, "value": "1"},
+ {"name": "Item 2", "isgroup": false, "value": "2"}
+ ]},
+ {"name": "Group 2", "isgroup": true, "options":
+ [
+ {"name": "Item 3", "isgroup": false, "value": "3"},
+ {"name": "Item 4", "isgroup": false, "value": "4"}
+ ]}],
+ "disabled": false,
+ "title": "Some cool title"
+ },
+ "awardbutton": {
+ "id" : "id_id",
+ "method" : "get",
+ "url" : "#",
+ "primary" : true,
+ "tooltip" : "This is a tooltip",
+ "label" : "Button2",
+ "attributes": [
+ {
+ "name": "data-attribute",
+ "value": "yeah"
+ }
+ ]
+ }
+ }
+}}
+
+
+ {{#button}}
+
+ {{> core/single_button }}
+
+ {{/button}}
+ {{#urlselect}}
+
+ {{> core/url_select }}
+
+ {{/urlselect}}
+ {{#awardbutton}}
+
+ {{> core/single_button }}
+
+ {{/awardbutton}}
+
+
diff --git a/badges/templates/manage_badge.mustache b/badges/templates/manage_badge.mustache
new file mode 100644
index 00000000000..04803875cc1
--- /dev/null
+++ b/badges/templates/manage_badge.mustache
@@ -0,0 +1,87 @@
+{{!
+ 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 .
+}}
+{{!
+ @template core_badges/manage_badge
+ Displays the tertiary nav for the page managing a particular badge
+
+ Context variables required for this template:
+ * button stdClass - The back button to be rendered
+ * urlselect stdClass - The URL select to be rendered
+
+ Example context (json):
+ {
+ "button": {
+ "id": "buttons_button",
+ "method" : "get",
+ "url" : "#",
+ "primary" : true,
+ "tooltip" : "This is a tooltip",
+ "label" : "Button2",
+ "attributes": [
+ {
+ "name": "data-attribute",
+ "value": "yeah"
+ }
+ ]
+ },
+ "urlselect": {
+ "id": "url_select_test",
+ "action": "https://example.com/post",
+ "formid": "url_select_form",
+ "sesskey": "sesskey",
+ "label": "core/url_select",
+ "helpicon": {
+ "title": "Help with something",
+ "text": "Help with something",
+ "url": "http://example.org/help",
+ "linktext": "",
+ "icon":{
+ "extraclasses": "iconhelp",
+ "attributes": [
+ {"name": "src", "value": "../../../pix/help.svg"},
+ {"name": "alt", "value": "Help icon"}
+ ]
+ }
+ },
+ "showbutton": "Go",
+ "options": [{
+ "name": "Group 1", "isgroup": true, "options":
+ [
+ {"name": "Item 1", "isgroup": false, "value": "1"},
+ {"name": "Item 2", "isgroup": false, "value": "2"}
+ ]},
+ {"name": "Group 2", "isgroup": true, "options":
+ [
+ {"name": "Item 3", "isgroup": false, "value": "3"},
+ {"name": "Item 4", "isgroup": false, "value": "4"}
+ ]}],
+ "disabled": false,
+ "title": "Some cool title"
+ }
+ }
+}}
+
+
+ {{#button}}
+
+ {{> core/single_button }}
+
+ {{/button}}
+ {{#urlselect}}
+
+ {{> core/url_select }}
+
+ {{/urlselect}}
+
+
diff --git a/badges/templates/manage_badges.mustache b/badges/templates/manage_badges.mustache
new file mode 100644
index 00000000000..4fe4c3c56e3
--- /dev/null
+++ b/badges/templates/manage_badges.mustache
@@ -0,0 +1,63 @@
+{{!
+ 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 .
+}}
+{{!
+ @template core_badges/manage_badges
+ Displays the tertiary nav for manage badges page
+
+ Context variables required for this template:
+ * buttons Array - List of buttons to be displayed in the tertiary navigation section
+
+ Example context (json):
+ {
+ "buttons": [
+ {
+ "id": "buttons_button",
+ "method" : "get",
+ "url" : "#",
+ "primary" : true,
+ "tooltip" : "This is a tooltip",
+ "label" : "Button1",
+ "attributes": [
+ {
+ "name": "data-attribute",
+ "value": "yeah"
+ }
+ ]
+ },
+ {
+ "id": "buttons_button_2",
+ "method" : "get",
+ "url" : "#",
+ "primary" : true,
+ "tooltip" : "This is a tooltip",
+ "label" : "Button2",
+ "attributes": [
+ {
+ "name": "data-attribute",
+ "value": "yeah"
+ }
+ ]
+ }
+ ]
+ }
+}}
+
+
+ {{#buttons}}
+
+ {{> core/single_button }}
+
+ {{/buttons}}
+
+
diff --git a/badges/tests/behat/add_badge.feature b/badges/tests/behat/add_badge.feature
index 4c36aff639f..99c906844a2 100644
--- a/badges/tests/behat/add_badge.feature
+++ b/badges/tests/behat/add_badge.feature
@@ -40,12 +40,11 @@ Feature: Add badges to the system
And I should see "Alignments (0)"
And I should not see "Create badge"
And I should not see "Issuer details"
- And I follow "Overview"
+ And I select "Overview" from the "jump" singleselect
And I should see "Issuer details"
And I should see "Test Badge Site"
And I should see "testuser@example.com"
And I navigate to "Badges > Manage badges" in site administration
- And I should see "Number of badges available: 1"
And I should not see "There are no badges available."
@javascript @_file_upload
@@ -62,7 +61,6 @@ Feature: Add badges to the system
And I press "Create badge"
And I wait until the page is ready
And I navigate to "Badges > Manage badges" in site administration
- And I should see "Number of badges available: 1"
And I press "Add a new badge"
And I set the following fields to these values:
| Name | Test Badge 2 |
@@ -73,7 +71,7 @@ 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 follow "Related badges (0)"
+ And I select "Related badges (0)" from the "jump" singleselect
And I should see "This badge does not have any related badges."
And I press "Add related badge"
And I follow "Related badges"
@@ -97,7 +95,7 @@ Feature: Add badges to the system
When I press "Create badge"
Then I should see "Edit details"
And I should see "Endorsement"
- And I follow "Endorsement"
+ And I select "Endorsement" from the "jump" singleselect
And I set the following fields to these values:
| Endorser name | Endorser |
| Email | endorsement@example.com |
@@ -121,7 +119,7 @@ Feature: Add badges to the system
When I press "Create badge"
Then I should see "Test Badge"
And I should see "Endorsement"
- And I follow "Alignments (0)"
+ And I select "Alignments (0)" from the "jump" singleselect
And I should see "This badge does not have any external skills or standards specified."
And I press "Add external skill or standard"
And I set the following fields to these values:
@@ -158,7 +156,6 @@ Feature: Add badges to the system
And I should see "Alignments (0)"
And I should not see "Create badge"
And I navigate to "Badges > Manage badges" in site administration
- And I should see "Number of badges available: 1"
And I should not see "There are no badges available."
# See buttons from the "Site badges" page.
And I am on homepage
@@ -183,14 +180,14 @@ 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"
- When I follow "Edit details"
+ When I select "Edit details" from the "jump" singleselect
And I should see "Test badge with 'apostrophe' and other friends (&@#)"
And I should not see "Issuer details"
And I set the following fields to these values:
| Name | Test badge renamed |
| Version | secondversion |
And I press "Save changes"
- And I follow "Overview"
+ And I select "Overview" from the "jump" singleselect
Then I should not see "Test badge with 'apostrophe' and other friends (&@#)"
And I should not see "firstversion"
And I should see "Test badge renamed"
diff --git a/badges/tests/behat/award_badge.feature b/badges/tests/behat/award_badge.feature
index e780e812982..d9947f6d624 100644
--- a/badges/tests/behat/award_badge.feature
+++ b/badges/tests/behat/award_badge.feature
@@ -63,7 +63,7 @@ Feature: Award badges
And I am on "Course 1" course homepage
And I navigate to "Badges > Manage badges" in current page administration
And I follow "Course Badge 1"
- And I follow "Recipients (0)"
+ And I select "Recipients (0)" from the "jump" singleselect
And I press "Award badge"
# Award course badge 1 to student 1.
And I set the field "potentialrecipients[]" to "Student 1 (student1@example.com)"
@@ -71,7 +71,7 @@ Feature: Award badges
And I am on "Course 1" course homepage
And I navigate to "Badges > Manage badges" in current page administration
And I follow "Course Badge 1"
- And I follow "Recipients (1)"
+ And I select "Recipients (1)" from the "jump" singleselect
Then I should see "Recipients (1)"
And I log out
# Student 1 should have both badges.
@@ -152,7 +152,7 @@ Feature: Award badges
And I press "Save"
And I press "Enable access"
And I press "Continue"
- And I follow "Recipients (0)"
+ And I select "Recipients (0)" from the "jump" singleselect
And I press "Award badge"
And I set the field "potentialrecipients[]" to "Teacher 1 (teacher1@example.com)"
And I press "Award badge"
@@ -181,7 +181,7 @@ Feature: Award badges
And I press "Save"
And I press "Enable access"
And I press "Continue"
- And I follow "Recipients (0)"
+ And I select "Recipients (0)" from the "jump" singleselect
And I press "Award badge"
And I set the field "potentialrecipients[]" to "Student 2 (student2@example.com)"
And I press "Award badge"
@@ -284,7 +284,7 @@ Feature: Award badges
And I press "Save"
And I press "Enable access"
And I press "Continue"
- And I follow "Recipients (0)"
+ And I select "Recipients (0)" from the "jump" singleselect
And I press "Award badge"
# Award course badge 1 to student 1.
And I set the field "potentialrecipients[]" to "Student 1 (student1@example.com)"
@@ -292,7 +292,7 @@ Feature: Award badges
And I am on "Course 1" course homepage
And I navigate to "Badges > Manage badges" in current page administration
And I follow "Course Badge 1"
- And I follow "Recipients (1)"
+ And I select "Recipients (1)" from the "jump" singleselect
Then I should see "Recipients (1)"
# Add course badge 2.
And I am on "Course 1" course homepage
@@ -310,7 +310,7 @@ Feature: Award badges
And I press "Save"
And I press "Enable access"
And I press "Continue"
- And I follow "Recipients (0)"
+ And I select "Recipients (0)" from the "jump" singleselect
And I press "Award badge"
# Award course badge 2 to student 2.
And I set the field "potentialrecipients[]" to "Student 2 (student2@example.com)"
@@ -318,7 +318,7 @@ Feature: Award badges
And I am on "Course 1" course homepage
And I navigate to "Badges > Manage badges" in current page administration
And I follow "Course Badge 2"
- And I follow "Recipients (1)"
+ And I select "Recipients (1)" from the "jump" singleselect
Then I should see "Recipients (1)"
And I log out
And I trigger cron
@@ -351,7 +351,7 @@ Feature: Award badges
And I press "Save"
And I press "Enable access"
And I press "Continue"
- And I follow "Recipients (0)"
+ And I select "Recipients (0)" from the "jump" singleselect
And I press "Award badge"
And I set the field "potentialrecipients[]" to "Student 2 (student2@example.com)"
And I press "Award badge"
@@ -361,7 +361,7 @@ Feature: Award badges
And I navigate to "Badges > Manage badges" in current page administration
And I follow "Course Badge"
Then I should see "Recipients (2)"
- And I follow "Recipients (2)"
+ And I select "Recipients (2)" from the "jump" singleselect
And I press "Award badge"
And I set the field "existingrecipients[]" to "Student 2 (student2@example.com)"
And I press "Revoke badge"
diff --git a/badges/tests/behat/backpack.feature b/badges/tests/behat/backpack.feature
index e2a745165ce..3f584b6d1f0 100644
--- a/badges/tests/behat/backpack.feature
+++ b/badges/tests/behat/backpack.feature
@@ -60,7 +60,7 @@ Feature: Backpack badges
And I press "Save"
And I press "Enable access"
And I press "Continue"
- And I follow "Recipients (0)"
+ And I select "Recipients (0)" from the "jump" singleselect
And I press "Award badge"
And I set the field "potentialrecipients[]" to "Student 1 (student1@example.com)"
And I press "Award badge"
@@ -97,7 +97,7 @@ Feature: Backpack badges
And I press "Save"
And I press "Enable access"
And I press "Continue"
- And I follow "Recipients (0)"
+ And I select "Recipients (0)" from the "jump" singleselect
And I press "Award badge"
And I set the field "potentialrecipients[]" to "Student 1 (student1@example.com)"
And I press "Award badge"
diff --git a/badges/tests/behat/badge_navigation.feature b/badges/tests/behat/badge_navigation.feature
new file mode 100644
index 00000000000..f88a49692b6
--- /dev/null
+++ b/badges/tests/behat/badge_navigation.feature
@@ -0,0 +1,147 @@
+@core @core_badges @_file_upload @javascript
+Feature: Test tertiary navigation as various users
+
+ Background:
+ Given the following "users" exist:
+ | username | firstname | lastname | email |
+ | student1 | Student | 1 | student1@example.com |
+ | teacher | Teacher | 1 | teacher@example.com |
+ | nonediting | Nonediting | 1 | nonediting@example.com |
+ And the following "courses" exist:
+ | fullname | shortname | format | enablecompletion |
+ | Course 1 | C1 | topics | 1 |
+ And the following "course enrolments" exist:
+ | user | course | role |
+ | teacher | C1 | editingteacher |
+ | student1 | C1 | student |
+ | nonediting | C1 | teacher |
+ # Create system badge and define a criterion.
+ And I log in as "admin"
+ And I am on "Course 1" course homepage
+ And I navigate to "Badges > Add a new badge" in current page administration
+ And I set the following fields to these values:
+ | Name | Testing course badge |
+ | Version | 1.1 |
+ | Language | Catalan |
+ | Description | Testing course badge description |
+ | Image author | http://author.example.com |
+ | Image caption | Test caption image |
+ And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
+ And I press "Create badge"
+ And I set the field "type" to "Manual issue by role"
+ And I expand all fieldsets
+ And I set the field "Teacher" to "1"
+ And I press "Save"
+ And I am on site homepage
+ And I navigate to "Badges > Add a new badge" in site administration
+ And I set the following fields to these values:
+ | Name | Testing site badge |
+ | Version | 1.1 |
+ | Language | Catalan |
+ | Description | Testing site badge description |
+ | Image author | http://author.example.com |
+ | Image caption | Test caption image |
+ And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
+ And I press "Create badge"
+ And I set the field "type" to "Manual issue by role"
+ And I expand all fieldsets
+ And I set the field "Teacher" to "1"
+ And I press "Save"
+
+ Scenario Outline: Check navigation as different users in a course context
+ 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"
+ 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
+
+ Examples:
+ | user | createbutton | activetab |
+ | admin | should exist | More |
+ | teacher | should exist | More |
+ | nonediting | should not exist | Badges |
+
+ Scenario: Check navigation as a student
+ Given I log in as "student1"
+ And I am on "Course 1" course homepage
+ When I navigate to "Badges" in current page administration
+ Then "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
+ And I should see "Site administration" 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 "Site administration" 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
+ Given I log in as "admin"
+ And I navigate to "Badges > Manage badges" in site administration
+ And I click on "Testing site badge" "link"
+ When I select "