Skip to content

Commit

Permalink
MBS-8337: Show kanbans in block activity_modules (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
fdagner authored Nov 5, 2024
1 parent e5c41c7 commit 5931b77
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
61 changes: 59 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,63 @@

$id = required_param('id', PARAM_INT);

require_login();
$course = $DB->get_record('course', ['id' => $id], '*', MUST_EXIST);
require_course_login($course);

redirect($CFG->wwwroot . '/mod/kanban/view.php?id=' . $id);
$coursecontext = context_course::instance($course->id);

$PAGE->set_url('/mod/kanban/index.php', ['id' => $id]);
$PAGE->set_title(format_string($course->fullname));
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_context($coursecontext);

echo $OUTPUT->header();

$modulenameplural = get_string('modulenameplural', 'mod_kanban');
echo $OUTPUT->heading($modulenameplural);

$kanbans = get_all_instances_in_course('kanban', $course);
$usesections = course_format_uses_sections($course->format);

$table = new html_table();
$table->attributes['class'] = 'generaltable mod_index';

if ($usesections) {
$table->head = [get_string('sectionname', 'format_' . $course->format), get_string('name')];
$table->align = ['left', 'left'];
} else {
$table->head = [get_string('name')];
$table->align = ['left'];
}

$kanbanfound = false;

foreach ($kanbans as $kanban) {
$context = context_module::instance($kanban->coursemodule, IGNORE_MISSING);
if (!$context || !has_capability('mod/kanban:view', $context)) {
continue;
}

$kanbanfound = true;
$linkcss = null;

if (!$kanban->visible) {
$linkcss = ['class' => 'dimmed'];
}

$link = html_writer::link(new moodle_url('/mod/kanban/view.php', ['id' => $kanban->coursemodule]), $kanban->name, $linkcss);

if ($usesections) {
$table->data[] = [get_section_name($course, $kanban->section), $link];
} else {
$table->data[] = [$link];
}
}

if (!$kanbanfound) {
notice(get_string('nokanbaninstances', 'mod_kanban'), new moodle_url('/course/view.php', ['id' => $course->id]));
} else {
echo html_writer::table($table);
}

echo $OUTPUT->footer();
1 change: 1 addition & 0 deletions lang/en/kanban.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
$string['newcard'] = 'New card';
$string['newcolumn'] = 'New column';
$string['nogroupavailable'] = 'No group available';
$string['nokanbaninstances'] = 'There are no kanban boards in this course or you are not allowed to access them';
$string['nouser'] = 'No user';
$string['nouserboards'] = 'No personal boards';
$string['pluginadministration'] = 'Kanban administration';
Expand Down

0 comments on commit 5931b77

Please sign in to comment.