index.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Display information about all the colab modules in the requested course.
  18. *
  19. * @package colab
  20. * @copyright 2020 Your Name <you@example.com>
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. require(__DIR__.'/../../config.php');
  24. require_once(__DIR__.'/lib.php');
  25. $id = required_param('id', PARAM_INT);
  26. $course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
  27. require_course_login($course);
  28. $coursecontext = context_course::instance($course->id);
  29. $event = \mod_colab\event\course_module_instance_list_viewed::create(array(
  30. 'context' => $modulecontext
  31. ));
  32. $event->add_record_snapshot('course', $course);
  33. $event->trigger();
  34. $PAGE->set_url('/mod/colab/index.php', array('id' => $id));
  35. $PAGE->set_title(format_string($course->fullname));
  36. $PAGE->set_heading(format_string($course->fullname));
  37. $PAGE->set_context($coursecontext);
  38. echo $OUTPUT->header();
  39. $modulenameplural = get_string('modulenameplural', 'colab');
  40. echo $OUTPUT->heading($modulenameplural);
  41. $colabs = get_all_instances_in_course('colab', $course);
  42. if (empty($colabs)) {
  43. notice(get_string('nonewmodules', 'colab'), new moodle_url('/course/view.php', array('id' => $course->id)));
  44. }
  45. $table = new html_table();
  46. $table->attributes['class'] = 'generaltable mod_index';
  47. if ($course->format == 'weeks') {
  48. $table->head = array(get_string('week'), get_string('name'));
  49. $table->align = array('center', 'left');
  50. } else if ($course->format == 'topics') {
  51. $table->head = array(get_string('topic'), get_string('name'));
  52. $table->align = array('center', 'left', 'left', 'left');
  53. } else {
  54. $table->head = array(get_string('name'));
  55. $table->align = array('left', 'left', 'left');
  56. }
  57. foreach ($colabs as $colab) {
  58. if (!$colab->visible) {
  59. $link = html_writer::link(
  60. new moodle_url('/mod/colab/view.php', array('id' => $colab->coursemodule)),
  61. format_string($colab->name, true),
  62. array('class' => 'dimmed'));
  63. } else {
  64. $link = html_writer::link(
  65. new moodle_url('/mod/colab/view.php', array('id' => $colab->coursemodule)),
  66. format_string($colab->name, true));
  67. }
  68. if ($course->format == 'weeks' or $course->format == 'topics') {
  69. $table->data[] = array($colab->section, $link);
  70. } else {
  71. $table->data[] = array($link);
  72. }
  73. }
  74. echo html_writer::table($table);
  75. echo $OUTPUT->footer();