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.
 
 
 
 
 

698 lines
24 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. * @copyright 2018 CiL RWTH Aachen (see README.md)
  19. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  20. */
  21. defined('MOODLE_INTERNAL') || die;
  22. /**
  23. * List of features supported in pdfannotator module
  24. * @param string $feature FEATURE_xx constant for requested feature
  25. * @return mixed True if module supports feature, false if not, null if doesn't know
  26. */
  27. function pdfannotator_supports($feature) {
  28. switch($feature) {
  29. case FEATURE_GROUPS:
  30. case FEATURE_GROUPINGS:
  31. case FEATURE_MOD_INTRO:
  32. case FEATURE_COMPLETION_TRACKS_VIEWS:
  33. case FEATURE_BACKUP_MOODLE2:
  34. case FEATURE_SHOW_DESCRIPTION:
  35. return true;
  36. default:
  37. return null;
  38. }
  39. }
  40. /**
  41. * Function currently unused.
  42. *
  43. * @return string
  44. */
  45. function mod_pdfannotator_before_standard_html_head() {
  46. }
  47. /**
  48. * Returns all other caps used in module
  49. * @return array
  50. */
  51. function pdfannotator_get_extra_capabilities() {
  52. return array('moodle/site:accessallgroups');
  53. }
  54. /**
  55. * This function is used by the reset_course_userdata function in moodlelib.
  56. * @param $data the data submitted from the reset course.
  57. * @return array status array
  58. */
  59. function pdfannotator_reset_userdata($data) {
  60. return array();
  61. }
  62. /**
  63. * List the actions that correspond to a view of this module.
  64. * This is used by the participation report.
  65. *
  66. * Note: This is not used by new logging system. Event with
  67. * crud = 'r' and edulevel = LEVEL_PARTICIPATING will
  68. * be considered as view action.
  69. *
  70. * @return array
  71. */
  72. function pdfannotator_get_view_actions() {
  73. return array('view', 'view all');
  74. }
  75. /**
  76. * List the actions that correspond to a post of this module.
  77. * This is used by the participation report.
  78. *
  79. * Note: This is not used by new logging system. Event with
  80. * crud = ('c' || 'u' || 'd') and edulevel = LEVEL_PARTICIPATING
  81. * will be considered as post action.
  82. *
  83. * @return array
  84. */
  85. function pdfannotator_get_post_actions() {
  86. return array('update', 'add');
  87. }
  88. /**
  89. * Add pdfannotator instance.
  90. * @param object $data
  91. * @param mod_pdfannotator_mod_form $mform
  92. * @return int new pdfannotator instance id
  93. */
  94. function pdfannotator_add_instance($data, $mform) {
  95. global $CFG, $DB;
  96. require_once("$CFG->libdir/resourcelib.php");
  97. require_once("$CFG->dirroot/mod/pdfannotator/locallib.php");
  98. $cmid = $data->coursemodule;
  99. $data->timemodified = time();
  100. pdfannotator_set_display_options($data);
  101. $data->id = $DB->insert_record('pdfannotator', $data);
  102. // We need to use context now, so we need to make sure all needed info is already in db.
  103. $DB->set_field('course_modules', 'instance', $data->id, array('id' => $cmid));
  104. pdfannotator_set_mainfile($data);
  105. $completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null;
  106. \core_completion\api::update_completion_date_event($cmid, 'pdfannotator', $data->id, $completiontimeexpected);
  107. return $data->id;
  108. }
  109. /**
  110. * Update pdfannotator instance.
  111. * @param object $data
  112. * @param object $mform
  113. * @return bool true
  114. */
  115. function pdfannotator_update_instance($data, $mform) {
  116. global $CFG, $DB;
  117. require_once("$CFG->libdir/resourcelib.php");
  118. require_once("$CFG->dirroot/mod/pdfannotator/locallib.php");
  119. $data->timemodified = time();
  120. $data->id = $data->instance;
  121. $data->revision++;
  122. pdfannotator_set_display_options($data); // Can be deleted or extended.
  123. $DB->update_record('pdfannotator', $data);
  124. pdfannotator_set_mainfile($data);
  125. $completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null;
  126. \core_completion\api::update_completion_date_event($data->coursemodule, 'pdfannotator', $data->id, $completiontimeexpected);
  127. return true;
  128. }
  129. /**
  130. * Updates display options based on form input.
  131. *
  132. * Shared code used by pdfannotator_add_instance and pdfannotator_update_instance.
  133. * keep it, if you want defind more disply options
  134. * @param object $data Data object
  135. */
  136. function pdfannotator_set_display_options($data) {
  137. $displayoptions = array();
  138. $displayoptions['printintro'] = (int) !empty($data->printintro);
  139. $data->displayoptions = serialize($displayoptions);
  140. }
  141. /**
  142. * Delete pdfannotator instance.
  143. * @param int $id in mdl_pdfannotator
  144. * @return bool true
  145. */
  146. function pdfannotator_delete_instance($id) {
  147. global $DB;
  148. if (!$pdfannotator = $DB->get_record('pdfannotator', array('id' => $id))) {
  149. return false;
  150. }
  151. $cm = get_coursemodule_from_instance('pdfannotator', $id);
  152. \core_completion\api::update_completion_date_event($cm->id, 'pdfannotator', $id, null);
  153. // Note: all context files are deleted automatically.
  154. // 1.a) Get all annotations of the annotator.
  155. if (!$annotations = $DB->get_records('pdfannotator_annotations', ['pdfannotatorid' => $id])) {
  156. return false;
  157. }
  158. // 1.b) For every annotation delete all subscriptions attached to it.
  159. foreach ($annotations as $annotation) {
  160. if (!$DB->delete_records('pdfannotator_subscriptions', ['annotationid' => $annotation->id]) == 1) {
  161. return false;
  162. }
  163. }
  164. // 1.c) Then delete the annotations from the annotations table.
  165. if (!$DB->delete_records('pdfannotator_annotations', ['pdfannotatorid' => $id]) == 1) {
  166. return false;
  167. }
  168. // 2.a) Get all comments in this annotator.
  169. if (!$comments = $DB->get_records('pdfannotator_comments', ['pdfannotatorid' => $id])) {
  170. return false;
  171. }
  172. // 2.b) Delete all votes in this annotator.
  173. foreach ($comments as $comment) {
  174. if (!$DB->delete_records('pdfannotator_votes', ['commentid' => $comment->id]) == 1) {
  175. return false;
  176. }
  177. }
  178. // 2.c) Delete all comments in this annotator.
  179. if (!$DB->delete_records('pdfannotator_comments', ['pdfannotatorid' => $id]) == 1) {
  180. return false;
  181. }
  182. // 3. Deleting all the reports.
  183. if (!$DB->delete_records('pdfannotator_reports', ['pdfannotatorid' => $id])) {
  184. return false;
  185. }
  186. // 4. Delete all archived comments.
  187. if (!$DB->delete_records('pdfannotator_commentsarchive', ['pdfannotatorid' => $id]) == 1) {
  188. return false;
  189. }
  190. // 5. Delete the annotator itself.
  191. if (!$DB->delete_records('pdfannotator', array('id' => $id)) == 1) {
  192. return false;
  193. }
  194. return true;
  195. }
  196. /**
  197. * Given a course_module object, this function returns any
  198. * "extra" information that may be needed when printing
  199. * this activity in a course listing.
  200. *
  201. * See {@link get_array_of_activities()} in course/lib.php
  202. *
  203. * @param stdClass $coursemodule
  204. * @return cached_cm_info info
  205. */
  206. function pdfannotator_get_coursemodule_info($coursemodule) {
  207. global $CFG, $DB;
  208. require_once("$CFG->libdir/filelib.php");
  209. require_once("$CFG->dirroot/mod/pdfannotator/locallib.php");
  210. require_once($CFG->libdir . '/completionlib.php');
  211. $context = context_module::instance($coursemodule->id);
  212. if (!$pdfannotator = $DB->get_record('pdfannotator', array('id' => $coursemodule->instance),
  213. 'id, name, course, timemodified, timecreated, intro, introformat')) {
  214. return null;
  215. }
  216. $info = new cached_cm_info();
  217. $info->name = $pdfannotator->name;
  218. if ($coursemodule->showdescription) {
  219. // Convert intro to html. Do not filter cached version, filters run at display time.
  220. $info->content = format_module_intro('pdfannotator', $pdfannotator, $coursemodule->id, false);
  221. }
  222. // See if there is at least one file.
  223. $fs = get_file_storage();
  224. $files = $fs->get_area_files($context->id, 'mod_pdfannotator', 'content', 0, 'sortorder DESC, id ASC', false, 0, 0, 1);
  225. if (count($files) >= 1) {
  226. $mainfile = reset($files);
  227. $pdfannotator->mainfile = $mainfile->get_filename();
  228. }
  229. // If any optional extra details are turned on, store in custom data,
  230. // add some file details as well to be used later by pdfannotator_get_optional_details() without retriving.
  231. // Do not store filedetails if this is a reference - they will still need to be retrieved every time.
  232. return $info;
  233. }
  234. /**
  235. * Called when viewing course page. Shows extra details after the link if
  236. * enabled.
  237. *
  238. * @param cm_info $cm Course module information
  239. */
  240. function pdfannotator_cm_info_view(cm_info $cm) {
  241. global $CFG;
  242. require_once($CFG->dirroot . '/mod/pdfannotator/locallib.php');
  243. $cm->set_after_link(' ' . html_writer::tag('span', '', // Use this to show details.
  244. array('class' => 'pdfannotatorlinkdetails')));
  245. }
  246. /**
  247. * Lists all browsable file areas
  248. *
  249. * @package mod_pdfannotator
  250. * @category files
  251. * @param stdClass $course course object
  252. * @param stdClass $cm course module object
  253. * @param stdClass $context context object
  254. * @return array
  255. */
  256. function pdfannotator_get_file_areas($course, $cm, $context) {
  257. $areas = array();
  258. $areas['content'] = get_string('pdfannotatorcontent', 'pdfannotator');
  259. return $areas;
  260. }
  261. /**
  262. * File browsing support for pdfannotator module content area.
  263. *
  264. * @package mod_pdfannotator
  265. * @category files
  266. * @param stdClass $browser file browser instance
  267. * @param stdClass $areas file areas
  268. * @param stdClass $course course object
  269. * @param stdClass $cm course module object
  270. * @param stdClass $context context object
  271. * @param string $filearea file area
  272. * @param int $itemid item ID
  273. * @param string $filepath file path
  274. * @param string $filename file name
  275. * @return file_info instance or null if not found
  276. */
  277. function pdfannotator_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) {
  278. global $CFG;
  279. if (!has_capability('moodle/course:managefiles', $context)) {
  280. // Students can not peak here!
  281. return null;
  282. }
  283. $fs = get_file_storage();
  284. if ($filearea === 'content') {
  285. $filepath = is_null($filepath) ? '/' : $filepath;
  286. $filename = is_null($filename) ? '.' : $filename;
  287. $urlbase = $CFG->wwwroot . '/pluginfile.php';
  288. if (!$storedfile = $fs->get_file($context->id, 'mod_pdfannotator', 'content', 0, $filepath, $filename)) {
  289. if ($filepath === '/' and $filename === '.') {
  290. $storedfile = new virtual_root_file($context->id, 'mod_pdfannotator', 'content', 0);
  291. } else {
  292. // Not found.
  293. return null;
  294. }
  295. }
  296. require_once("$CFG->dirroot/mod/pdfannotator/locallib.php");
  297. return new pdfannotator_content_file_info($browser, $context, $storedfile, $urlbase,
  298. $areas[$filearea], true, true, true, false);
  299. }
  300. // Note: pdfannotator_intro handled in file_browser automatically.
  301. return null;
  302. }
  303. /**
  304. * Serves the pdfannotator files.
  305. *
  306. * @package mod_pdfannotator
  307. * @category files
  308. * @param stdClass $course course object
  309. * @param stdClass $cm course module object
  310. * @param stdClass $context context object
  311. * @param string $filearea file area
  312. * @param array $args extra arguments
  313. * @param bool $forcedownload whether or not force download
  314. * @param array $options additional options affecting the file serving
  315. * @return bool false if file not found, does not return if found - just send the file
  316. */
  317. function pdfannotator_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
  318. global $CFG, $DB;
  319. require_once("$CFG->libdir/resourcelib.php");
  320. if ($context->contextlevel != CONTEXT_MODULE) {
  321. return false;
  322. }
  323. require_course_login($course, true, $cm);
  324. if (!has_capability('mod/pdfannotator:view', $context)) {
  325. return false;
  326. }
  327. if ($filearea !== 'content') {
  328. // Intro is handled automatically in pluginfile.php.
  329. return false;
  330. }
  331. array_shift($args); // Ignore revision - designed to prevent caching problems only.
  332. $fs = get_file_storage();
  333. $relativepath = implode('/', $args);
  334. $fullpath = rtrim("/$context->id/mod_pdfannotator/$filearea/0/$relativepath", '/');
  335. do {
  336. if (!$file = $fs->get_file_by_hash(sha1($fullpath))) {
  337. if ($fs->get_file_by_hash(sha1("$fullpath/."))) {
  338. if ($file = $fs->get_file_by_hash(sha1("$fullpath/index.htm"))) {
  339. break;
  340. }
  341. if ($file = $fs->get_file_by_hash(sha1("$fullpath/index.html"))) {
  342. break;
  343. }
  344. if ($file = $fs->get_file_by_hash(sha1("$fullpath/Default.htm"))) {
  345. break;
  346. }
  347. }
  348. $pdfannotator = $DB->get_record('pdfannotator', array('id' => $cm->instance), 'id, legacyfiles', MUST_EXIST);
  349. if ($pdfannotator->legacyfiles != RESOURCELIB_LEGACYFILES_ACTIVE) {
  350. return false;
  351. }
  352. if (!$file = resourcelib_try_file_migration('/' . $relativepath, $cm->id, $cm->course,
  353. 'mod_pdfannotator', 'content', 0)) {
  354. return false;
  355. }
  356. // File migrate - update flag.
  357. $pdfannotator->legacyfileslast = time();
  358. $DB->update_record('pdfannotator', $pdfannotator);
  359. }
  360. } while (false);
  361. // Should we apply filters?
  362. $filter = 0;
  363. // Finally send the file.
  364. send_stored_file($file, null, $filter, $forcedownload, $options);
  365. }
  366. /**
  367. * Return a list of page types
  368. * @param string $pagetype current page type
  369. * @param stdClass $parentcontext Block's parent context
  370. * @param stdClass $currentcontext Current context of block
  371. */
  372. function pdfannotator_page_type_list($pagetype, $parentcontext, $currentcontext) {
  373. $modulepagetype = array('mod-pdfannotator-*' => get_string('page-mod-pdfannotator-x', 'pdfannotator'));
  374. return $modulepagetype;
  375. }
  376. /**
  377. * Export file pdfannotator contents
  378. *
  379. * @return array of file content
  380. */
  381. function pdfannotator_export_contents($cm, $baseurl) {
  382. global $CFG, $DB;
  383. $contents = array();
  384. $context = context_module::instance($cm->id);
  385. $pdfannotator = $DB->get_record('pdfannotator', array('id' => $cm->instance), '*', MUST_EXIST);
  386. if ($pdfannotator->useprint == 1) {
  387. $fs = get_file_storage();
  388. $files = $fs->get_area_files($context->id, 'mod_pdfannotator', 'content', 0, 'sortorder DESC, id ASC', false);
  389. $fileinfo = reset($files);
  390. $file = array();
  391. $file['type'] = 'file';
  392. $file['filename'] = $fileinfo->get_filename();
  393. $file['filepath'] = $fileinfo->get_filepath();
  394. $file['filesize'] = $fileinfo->get_filesize();
  395. $file['mimetype'] = 'pdf';
  396. $file['fileurl'] = moodle_url::make_webservice_pluginfile_url(
  397. $context->id, 'mod_pdfannotator', 'content', '1', $fileinfo->get_filepath(),
  398. $fileinfo->get_filename())->out(false);
  399. $file['timecreated'] = $fileinfo->get_timecreated();
  400. $file['timemodified'] = $fileinfo->get_timemodified();
  401. $file['sortorder'] = $fileinfo->get_sortorder();
  402. $file['userid'] = $fileinfo->get_userid();
  403. $file['author'] = $fileinfo->get_author();
  404. $file['license'] = $fileinfo->get_license();
  405. $file['mimetype'] = $fileinfo->get_mimetype();
  406. $file['isexternalfile'] = $fileinfo->is_external_file();
  407. if ($file['isexternalfile']) {
  408. $file['repositorytype'] = $fileinfo->get_repository_type();
  409. }
  410. $contents[] = $file;
  411. }
  412. return $contents;
  413. }
  414. /**
  415. * Mark the activity completed (if required) and trigger the course_module_viewed event.
  416. *
  417. * @param stdClass $pdfannotator pdfannotator object
  418. * @param stdClass $course course object
  419. * @param stdClass $cm course module object
  420. * @param stdClass $context context object
  421. * @since Moodle 3.0
  422. */
  423. function pdfannotator_view($pdfannotator, $course, $cm, $context) {
  424. // Trigger course_module_viewed event.
  425. $params = array(
  426. 'context' => $context,
  427. 'objectid' => $pdfannotator->id
  428. );
  429. $event = \mod_pdfannotator\event\course_module_viewed::create($params);
  430. $event->add_record_snapshot('course_modules', $cm);
  431. $event->add_record_snapshot('course', $course);
  432. $event->add_record_snapshot('pdfannotator', $pdfannotator);
  433. $event->trigger();
  434. // Completion.
  435. $completion = new completion_info($course);
  436. $completion->set_module_viewed($cm);
  437. }
  438. /**
  439. * Check if the module has any update that affects the current user since a given time.
  440. *
  441. * @param cm_info $cm course module data
  442. * @param int $from the time to check updates from
  443. * @param array $filter if we need to check only specific updates
  444. * @return stdClass an object with the different type of areas indicating if they were updated or not
  445. * @since Moodle 3.2
  446. */
  447. function pdfannotator_check_updates_since(cm_info $cm, $from, $filter = array()) {
  448. $updates = course_check_module_updates_since($cm, $from, array('content'), $filter);
  449. return $updates;
  450. }
  451. /**
  452. * This function receives a calendar event and returns the action associated with it, or null if there is none.
  453. *
  454. * This is used by block_myoverview in order to display the event appropriately. If null is returned then the event
  455. * is not displayed on the block.
  456. *
  457. * @param calendar_event $event
  458. * @param \core_calendar\action_factory $factory
  459. * @return \core_calendar\local\event\entities\action_interface|null
  460. */
  461. function mod_pdfannotator_core_calendar_provide_event_action(calendar_event $event, \core_calendar\action_factory $factory) {
  462. $cm = get_fast_modinfo($event->courseid)->instances['pdfannotator'][$event->instance];
  463. $completion = new \completion_info($cm->get_course());
  464. $completiondata = $completion->get_data($cm, false);
  465. if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
  466. return null;
  467. }
  468. return $factory->create_instance(
  469. get_string('view'), new \moodle_url('/mod/pdfannotator/view.php', ['id' => $cm->id]), 1, true
  470. );
  471. }
  472. /**
  473. * Returns all annotations comments since a given time in specified annotator.
  474. *
  475. * @todo Document this functions args
  476. * @global object
  477. * @global object
  478. * @global object
  479. * @global object
  480. */
  481. function pdfannotator_get_recent_mod_activity(&$activities, &$index, $timestart, $courseid, $cmid, $userid = 0, $groupid = 0) {
  482. global $CFG, $COURSE, $USER, $DB;
  483. if ($COURSE->id == $courseid) {
  484. $course = $COURSE;
  485. } else {
  486. $course = $DB->get_record('course', array('id' => $courseid));
  487. }
  488. $modinfo = get_fast_modinfo($course);
  489. $cm = $modinfo->cms[$cmid];
  490. $params = array($timestart, $cm->instance);
  491. if ($userid) {
  492. $userselect = "AND u.id = ? AND c.visibility='public'";
  493. $params[] = $userid;
  494. } else {
  495. $userselect = "";
  496. }
  497. if ($groupid) {
  498. $groupselect = "AND d.groupid = ?";
  499. $params[] = $groupid;
  500. } else {
  501. $groupselect = "";
  502. }
  503. $allnames = get_all_user_name_fields(true, 'u');
  504. if (!$posts = $DB->get_records_sql(
  505. "SELECT p.*,c.id, c.userid AS duserid, c.visibility, c.content, c.timecreated, c.annotationid, c.isquestion,
  506. $allnames, u.email, u.picture, u.imagealt, u.email, a.page
  507. FROM {pdfannotator} p
  508. JOIN {pdfannotator_annotations} a ON a.pdfannotatorid=p.id
  509. JOIN {pdfannotator_comments} c ON c.annotationid = a.id
  510. JOIN {user} u ON u.id = a.userid
  511. WHERE c.timecreated > ? AND p.id = ?
  512. $userselect AND c.isdeleted=0
  513. ORDER BY p.id ASC ", $params)) { // Order by initial posting date.
  514. return;
  515. }
  516. $printposts = array();
  517. foreach ($posts as $post) {
  518. $printposts[] = $post;
  519. }
  520. if (!$printposts) {
  521. return;
  522. }
  523. $aname = format_string($cm->name, true);
  524. foreach ($printposts as $post) {
  525. $tmpactivity = new stdClass();
  526. $tmpactivity->type = 'pdfannotator';
  527. $tmpactivity->cmid = $cm->id;
  528. $tmpactivity->name = $aname;
  529. $tmpactivity->sectionnum = $cm->sectionnum;
  530. $tmpactivity->timestamp = $post->timecreated;
  531. $tmpactivity->content = new stdClass();
  532. $tmpactivity->content->id = $post->annotationid;
  533. $tmpactivity->content->commid = $post->id;
  534. $tmpactivity->content->isquestion = $post->isquestion;
  535. $tmpactivity->content->discussion = format_string($post->content);
  536. $tmpactivity->content->page = $post->page;
  537. $tmpactivity->visible = $post->visibility;
  538. $tmpactivity->user = new stdClass();
  539. $additionalfields = explode(',', user_picture::fields());
  540. $tmpactivity->user = username_load_fields_from_object($tmpactivity->user, $post, null, $additionalfields);
  541. $tmpactivity->user->id = $post->duserid;
  542. $activities[$index++] = $tmpactivity;
  543. }
  544. return;
  545. }
  546. /**
  547. * Outputs the pdfannotator post indicated by $activity.
  548. *
  549. * @param object $activity the activity object the annotator resides in
  550. * @param int $courseid the id of the course the annotator resides in
  551. * @param bool $detail not used, but required for compatibilty with other modules
  552. * @param int $modnames not used, but required for compatibilty with other modules
  553. * @param bool $viewfullnames not used, but required for compatibilty with other modules
  554. */
  555. function pdfannotator_print_recent_mod_activity($activity, $courseid, $detail, $modnames, $viewfullnames) {
  556. global $OUTPUT;
  557. $content = $activity->content;
  558. $class = 'discussion';
  559. $tableoptions = [
  560. 'border-top' => '0',
  561. 'cellpadding' => '3',
  562. 'cellspacing' => '0',
  563. 'class' => ''
  564. ];
  565. $output = html_writer::start_tag('table', $tableoptions);
  566. $output .= html_writer::start_tag('tr');
  567. $authorhidden = ($activity->visible == 'public') ? 0 : 1;
  568. // Show user picture if author should not be hidden.
  569. $pictureoptions = [
  570. 'courseid' => $courseid
  571. ];
  572. if (!$authorhidden) {
  573. $picture = $OUTPUT->user_picture($activity->user, $pictureoptions);
  574. } else {
  575. $pic = $OUTPUT->image_url('/u/f2');
  576. $picture = '<img src="'.$pic.'" class="userpicture" alt="'.get_string('anonymous', 'pdfannotator').
  577. '" width="35" height="35">';
  578. }
  579. $output .= html_writer::tag('td', $picture, ['class' => 'userpicture', 'valign' => 'top']);
  580. // Discussion title and author.
  581. $output .= html_writer::start_tag('td', ['class' => $class]);
  582. $class = 'title';
  583. $output .= html_writer::start_div($class);
  584. if ($detail) {
  585. $aname = s($activity->name);
  586. $output .= $OUTPUT->image_icon('icon', $aname, $activity->type);
  587. }
  588. $isquestion = ($content->isquestion) ? '<img src="' . $OUTPUT->image_url('t/message')
  589. . '" alt="' . get_string('question', 'pdfannotator')
  590. . '" title="' . get_string('question', 'pdfannotator') . '"> ' : '';
  591. $discussionurl = new moodle_url('/mod/pdfannotator/view.php',
  592. ['id' => $activity->cmid, 'page' => $content->page, 'annoid' => $content->id, 'commid' => $content->commid]);
  593. $output .= html_writer::link($discussionurl, ($isquestion . $content->discussion));
  594. $output .= html_writer::end_div();
  595. $timestamp = userdate($activity->timestamp);
  596. if ($authorhidden) {
  597. $by = new stdClass();
  598. $by->name = get_string('anonymous', 'pdfannotator');
  599. $by->date = $timestamp;
  600. $authornamedate = get_string('bynameondate', 'pdfannotator', $by);
  601. } else {
  602. $fullname = fullname($activity->user, $viewfullnames);
  603. $userurl = new moodle_url('/user/view.php');
  604. $userurl->params(['id' => $activity->user->id, 'course' => $courseid]);
  605. $by = new stdClass();
  606. $by->name = html_writer::link($userurl, $fullname);
  607. $by->date = $timestamp;
  608. $authornamedate = get_string('bynameondate', 'pdfannotator', $by);
  609. }
  610. $output .= html_writer::div($authornamedate, 'user');
  611. $output .= html_writer::end_tag('td');
  612. $output .= html_writer::end_tag('tr');
  613. $output .= html_writer::end_tag('table');
  614. echo $output;
  615. }