This commit is contained in:
Ilya Tregubov 2023-09-14 19:46:53 +08:00
commit 5da0cee324
No known key found for this signature in database
GPG Key ID: 0F58186F748E55C1
2 changed files with 21 additions and 29 deletions

View File

@ -163,9 +163,8 @@ class badges extends system_report {
$this->add_action((new action( $this->add_action((new action(
new moodle_url('/badges/action.php', [ new moodle_url('/badges/action.php', [
'id' => ':id', 'id' => ':id',
'sesskey' => sesskey(),
'activate' => true, 'activate' => true,
'return' => (new moodle_url(qualified_me()))->out_as_local_url(false), 'return' => ':return',
]), ]),
new pix_icon('t/show', '', 'core'), new pix_icon('t/show', '', 'core'),
[], [],
@ -173,8 +172,12 @@ class badges extends system_report {
new lang_string('activate', 'badges') new lang_string('activate', 'badges')
))->add_callback(static function(stdclass $row): bool { ))->add_callback(static function(stdclass $row): bool {
$badge = new \core_badges\badge($row->id); $badge = new \core_badges\badge($row->id);
$context = self::get_badge_context((int)$row->type, (int)$row->courseid);
return has_capability('moodle/badges:configuredetails', $context) && // Populate the return URL.
$row->return = (new moodle_url('/badges/index.php',
['type' => $badge->type, 'id' => (int) $badge->courseid]))->out_as_local_url(false);
return has_capability('moodle/badges:configuredetails', $badge->get_context()) &&
$badge->has_criteria() && $badge->has_criteria() &&
($row->status == BADGE_STATUS_INACTIVE || $row->status == BADGE_STATUS_INACTIVE_LOCKED); ($row->status == BADGE_STATUS_INACTIVE || $row->status == BADGE_STATUS_INACTIVE_LOCKED);
@ -194,8 +197,7 @@ class badges extends system_report {
new lang_string('deactivate', 'badges') new lang_string('deactivate', 'badges')
))->add_callback(static function(stdclass $row): bool { ))->add_callback(static function(stdclass $row): bool {
$badge = new \core_badges\badge($row->id); $badge = new \core_badges\badge($row->id);
$context = self::get_badge_context((int)$row->type, (int)$row->courseid); return has_capability('moodle/badges:configuredetails', $badge->get_context()) &&
return has_capability('moodle/badges:configuredetails', $context) &&
$badge->has_criteria() && $badge->has_criteria() &&
$row->status != BADGE_STATUS_INACTIVE && $row->status != BADGE_STATUS_INACTIVE_LOCKED; $row->status != BADGE_STATUS_INACTIVE && $row->status != BADGE_STATUS_INACTIVE_LOCKED;
})); }));
@ -211,9 +213,8 @@ class badges extends system_report {
new lang_string('award', 'badges') new lang_string('award', 'badges')
))->add_callback(static function(stdclass $row): bool { ))->add_callback(static function(stdclass $row): bool {
$badge = new \core_badges\badge($row->id); $badge = new \core_badges\badge($row->id);
$context = self::get_badge_context((int)$row->type, (int)$row->courseid); return has_capability('moodle/badges:awardbadge', $badge->get_context()) &&
return $badge->has_manual_award_criteria() && $badge->has_manual_award_criteria() &&
has_capability('moodle/badges:awardbadge', $context) &&
$badge->is_active(); $badge->is_active();
})); }));

View File

@ -48,7 +48,6 @@ if (empty($CFG->badges_allowcoursebadges) && ($type == BADGE_TYPE_COURSE)) {
throw new \moodle_exception('coursebadgesdisabled', 'badges'); throw new \moodle_exception('coursebadgesdisabled', 'badges');
} }
$err = '';
$urlparams = ['type' => $type]; $urlparams = ['type' => $type];
if ($course = $DB->get_record('course', ['id' => $courseid])) { if ($course = $DB->get_record('course', ['id' => $courseid])) {
@ -150,25 +149,17 @@ if ($type == BADGE_TYPE_SITE) {
echo $OUTPUT->box('', 'notifyproblem hide', 'check_connection'); echo $OUTPUT->box('', 'notifyproblem hide', 'check_connection');
$totalcount = count(badges_get_badges($type, $courseid, '', '' , 0, 0)); if ($course && $course->startdate > time()) {
echo $OUTPUT->box(get_string('error:notifycoursedate', 'badges'), 'generalbox notifyproblem');
if ($totalcount) {
if ($course && $course->startdate > time()) {
echo $OUTPUT->box(get_string('error:notifycoursedate', 'badges'), 'generalbox notifyproblem');
}
if ($err !== '') {
echo $OUTPUT->notification($err, 'notifyproblem');
}
if ($msg !== '') {
echo $OUTPUT->notification(get_string($msg, 'badges'), 'notifysuccess');
}
$report = system_report_factory::create(badges::class, $PAGE->context);
echo $report->output();
} else {
echo $output->notification(get_string('nobadges', 'badges'), 'info');
} }
if ($msg !== '') {
echo $OUTPUT->notification(get_string($msg, 'badges'), 'notifysuccess');
}
$report = system_report_factory::create(badges::class, $PAGE->context);
$report->set_default_no_results_notice(new lang_string('nobadges', 'badges'));
echo $report->output();
echo $OUTPUT->footer(); echo $OUTPUT->footer();