view.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. * Prints an instance of colab.
  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. // Course_module ID, or
  26. $id = optional_param('id', 0, PARAM_INT);
  27. // ... module instance id.
  28. $c = optional_param('c', 0, PARAM_INT);
  29. if ($id) {
  30. $cm = get_coursemodule_from_id('colab', $id, 0, false, MUST_EXIST);
  31. $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
  32. $moduleinstance = $DB->get_record('colab', array('id' => $cm->instance), '*', MUST_EXIST);
  33. } else if ($c) {
  34. $moduleinstance = $DB->get_record('colab', array('id' => $n), '*', MUST_EXIST);
  35. $course = $DB->get_record('course', array('id' => $moduleinstance->course), '*', MUST_EXIST);
  36. $cm = get_coursemodule_from_instance('colab', $moduleinstance->id, $course->id, false, MUST_EXIST);
  37. } else {
  38. print_error(get_string('missingidandcmid', colab));
  39. }
  40. require_login($course, true, $cm);
  41. $modulecontext = context_module::instance($cm->id);
  42. $event = \mod_colab\event\course_module_viewed::create(array(
  43. 'objectid' => $moduleinstance->id,
  44. 'context' => $modulecontext
  45. ));
  46. $event->add_record_snapshot('course', $course);
  47. $event->add_record_snapshot('colab', $moduleinstance);
  48. $event->trigger();
  49. $PAGE->set_url('/mod/colab/view.php', array('id' => $cm->id));
  50. $PAGE->set_title(format_string($moduleinstance->name));
  51. $PAGE->set_heading(format_string($course->fullname));
  52. $PAGE->set_context($modulecontext);
  53. echo $OUTPUT->header();
  54. echo $OUTPUT->footer();