Moodle plugin, allowing collaborative annotations in PDF files
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

149 lines
5.9 KiB

  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. * @package mod_pdfannotator
  18. * @author Ahmad Obeid (ahmad.obeid@rwth-aachen.de)
  19. * @copyright 2018 Ahmad Obeid (see README.md)
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. */
  22. require_once('../../config.php');
  23. require_once('locallib.php');
  24. $id = required_param('id', PARAM_INT); // Course ID.
  25. // Ensure that the course specified is valid.
  26. if (!$course = $DB->get_record('course', array('id' => $id))) {
  27. print_error('Course ID is incorrect');
  28. }
  29. require_course_login($course, true);
  30. $PAGE->set_pagelayout('incourse');
  31. $params = array(
  32. 'context' => context_course::instance($course->id)
  33. );
  34. $context = $params['context'];
  35. $event = \mod_pdfannotator\event\course_module_instance_list_viewed::create($params);
  36. $event->add_record_snapshot('course', $course);
  37. $event->trigger();
  38. $strpdfannotator = get_string('modulename', 'pdfannotator');
  39. $strpdfannotators = get_string('modulenameplural', 'pdfannotator');
  40. $strsectionname = get_string('sectionname', 'format_'.$course->format);
  41. $strname = get_string('name');
  42. $strintro = get_string('moduleintro');
  43. $strlastmodified = get_string('lastmodified');
  44. $strsubscribe = get_string('subscribe', 'pdfannotator');
  45. $strunsubscribe = get_string('unsubscribe', 'pdfannotator');
  46. $strsubscribed = get_string('subscribed', 'pdfannotator');
  47. $stryes = get_string('yes');
  48. $strno = get_string('no');
  49. $PAGE->set_url('/mod/pdfannotator/index.php', array('id' => $course->id));
  50. $PAGE->set_title($course->shortname.': '.$strpdfannotators);
  51. $PAGE->set_heading($course->fullname);
  52. $PAGE->navbar->add($strpdfannotators);
  53. echo $OUTPUT->header();
  54. echo $OUTPUT->heading($strpdfannotators);
  55. if (!$pdfannotators = get_all_instances_in_course('pdfannotator', $course)) {
  56. notice(get_string('thereareno', 'moodle', $strpdfannotators), "$CFG->wwwroot/course/view.php?id=$course->id");
  57. exit;
  58. }
  59. $usesections = course_format_uses_sections($course->format);
  60. $table = new html_table();
  61. $table->attributes['class'] = 'generaltable mod_index';
  62. if ($usesections) {
  63. $table->head = array ($strsectionname, $strname, $strlastmodified, $strintro);
  64. $table->align = array ('center', '', 'left', 'left');
  65. } else {
  66. $table->head = array ($strlastmodified, $strname, $strintro);
  67. $table->align = array ('left', 'left', 'left');
  68. }
  69. $modinfo = get_fast_modinfo($course);
  70. $currentsection = '';
  71. foreach ($pdfannotators as $pdfannotator) {
  72. $cm = $modinfo->cms[$pdfannotator->coursemodule];
  73. $infor = pdfannotator_get_number_of_new_activities($pdfannotator->id);
  74. if ($usesections) {
  75. $printsection = '';
  76. if ($pdfannotator->section !== $currentsection) {
  77. if ($pdfannotator->section) {
  78. $printsection = get_section_name($course, $pdfannotator->section);
  79. }
  80. if ($currentsection !== '') {
  81. $table->data[] = 'hr';
  82. }
  83. $currentsection = $pdfannotator->section;
  84. }
  85. } else {
  86. $printsection = '<span class="smallinfo">'.userdate($pdfannotator->timemodified)."</span>";
  87. }
  88. $extra = empty($cm->extra) ? '' : $cm->extra;
  89. $icon = '<img src="'.$cm->get_icon_url().'" class="activityicon" alt="'.$cm->get_module_type_name().'" /> ';
  90. $visible = $pdfannotator->visible;
  91. $class = $visible ? '' : 'class="dimmed"'; // Hidden modules are dimmed.
  92. $newinfo = " ";
  93. $actions = array();
  94. // Settings if user have capabilty.
  95. $manageurl = new \moodle_url('/course/mod.php', array('sesskey' => \sesskey()));
  96. // Edit.
  97. $hascapability = has_capability('mod/pdfannotator:administrateuserinput', $context);
  98. if ($hascapability) {
  99. $actions['edit'] = array(
  100. 'url' => new \moodle_url('/course/modedit.php', array('update' => $cm->id)),
  101. 'icon' => new \pix_icon('t/edit', new \lang_string('edit')),
  102. 'string' => new \lang_string('edit')
  103. );
  104. // Show/Hide.
  105. if ($visible) {
  106. $actions['hide'] = array(
  107. 'url' => new \moodle_url($manageurl, array('hide' => $cm->id)),
  108. 'icon' => new \pix_icon('t/hide', new \lang_string('hide')),
  109. 'string' => new \lang_string('hide'));
  110. } else {
  111. $actions['show'] = array(
  112. 'url' => new \moodle_url($manageurl, array('show' => $cm->id)),
  113. 'icon' => new \pix_icon('t/show', new \lang_string('show')),
  114. 'string' => new \lang_string('show')
  115. );
  116. }
  117. }
  118. $setting = pdfannotator_render_listitem_actions($actions);
  119. $lastmodified = pdfannotator_get_datetime_of_last_modification($pdfannotator->id);
  120. if ($infor > 0) {
  121. $newinfo = "<img src=\"pix/new.png\">($infor)</img>";
  122. } else if ($lastmodified >= strtotime("-1 day")) {
  123. $newinfo = "<img src=\"pix/new.gif\"></img>";
  124. }
  125. $table->data[] = array (
  126. $printsection,
  127. "<div style=\"float:left\"><a $class $extra href=\"view.php?id=$cm->id\">".$icon.format_string($pdfannotator->name)
  128. .$newinfo."</a></div><div style=\"float:right\">".$setting."</div>" , userdate($lastmodified),
  129. format_module_intro('pdfannotator', $pdfannotator, $cm->id));
  130. }
  131. echo html_writer::table($table);
  132. echo $OUTPUT->footer();