MDL-63147 mod_resource: Accept userid in resource event_action
[moodle.git] / mod / resource / lib.php
CommitLineData
28f672b2 1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
2a439ba7 17
28f672b2 18/**
11e41f1a 19 * @package mod_resource
702ab58c
PS
20 * @copyright 2009 Petr Skoda {@link http://skodak.org}
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28f672b2 22 */
23
702ab58c
PS
24defined('MOODLE_INTERNAL') || die;
25
aa54ed7b 26/**
27 * List of features supported in Resource module
28 * @param string $feature FEATURE_xx constant for requested feature
29 * @return mixed True if module supports feature, false if not, null if doesn't know
30 */
31function resource_supports($feature) {
32 switch($feature) {
33 case FEATURE_MOD_ARCHETYPE: return MOD_ARCHETYPE_RESOURCE;
34 case FEATURE_GROUPS: return false;
35 case FEATURE_GROUPINGS: return false;
aa54ed7b 36 case FEATURE_MOD_INTRO: return true;
37 case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
38 case FEATURE_GRADE_HAS_GRADE: return false;
39 case FEATURE_GRADE_OUTCOMES: return false;
a345de6e 40 case FEATURE_BACKUP_MOODLE2: return true;
3e4c2435 41 case FEATURE_SHOW_DESCRIPTION: return true;
214b1cf7 42
aa54ed7b 43 default: return null;
44 }
45}
713d78ea 46
d18830fe 47/**
aa54ed7b 48 * This function is used by the reset_course_userdata function in moodlelib.
49 * @param $data the data submitted from the reset course.
50 * @return array status array
28f672b2 51 */
aa54ed7b 52function resource_reset_userdata($data) {
0d14fcbc
AA
53
54 // Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
55 // See MDL-9367.
56
aa54ed7b 57 return array();
58}
65634a81 59
aa54ed7b 60/**
b2b4ec30
RT
61 * List the actions that correspond to a view of this module.
62 * This is used by the participation report.
63 *
64 * Note: This is not used by new logging system. Event with
65 * crud = 'r' and edulevel = LEVEL_PARTICIPATING will
66 * be considered as view action.
67 *
aa54ed7b 68 * @return array
69 */
70function resource_get_view_actions() {
cf051cc4 71 return array('view','view all');
aa54ed7b 72}
65634a81 73
aa54ed7b 74/**
b2b4ec30
RT
75 * List the actions that correspond to a post of this module.
76 * This is used by the participation report.
77 *
78 * Note: This is not used by new logging system. Event with
79 * crud = ('c' || 'u' || 'd') and edulevel = LEVEL_PARTICIPATING
80 * will be considered as post action.
81 *
aa54ed7b 82 * @return array
83 */
84function resource_get_post_actions() {
cf051cc4 85 return array('update', 'add');
aa54ed7b 86}
65634a81 87
aa54ed7b 88/**
89 * Add resource instance.
90 * @param object $data
91 * @param object $mform
c6c9a3bc 92 * @return int new resource instance id
aa54ed7b 93 */
94function resource_add_instance($data, $mform) {
95 global $CFG, $DB;
96 require_once("$CFG->libdir/resourcelib.php");
abed5d65 97 require_once("$CFG->dirroot/mod/resource/locallib.php");
f79321f1 98 $cmid = $data->coursemodule;
aa54ed7b 99 $data->timemodified = time();
a2c57666 100
101 resource_set_display_options($data);
d18830fe 102
aa54ed7b 103 $data->id = $DB->insert_record('resource', $data);
d18830fe 104
aa54ed7b 105 // we need to use context now, so we need to make sure all needed info is already in db
106 $DB->set_field('course_modules', 'instance', $data->id, array('id'=>$cmid));
f79321f1 107 resource_set_mainfile($data);
b3bd7a66
MN
108
109 $completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null;
110 \core_completion\api::update_completion_date_event($cmid, 'resource', $data->id, $completiontimeexpected);
111
aa54ed7b 112 return $data->id;
113}
cccb016a 114
aa54ed7b 115/**
116 * Update resource instance.
117 * @param object $data
118 * @param object $mform
119 * @return bool true
120 */
121function resource_update_instance($data, $mform) {
122 global $CFG, $DB;
123 require_once("$CFG->libdir/resourcelib.php");
aa54ed7b 124 $data->timemodified = time();
125 $data->id = $data->instance;
126 $data->revision++;
2a439ba7 127
a2c57666 128 resource_set_display_options($data);
129
130 $DB->update_record('resource', $data);
131 resource_set_mainfile($data);
b3bd7a66
MN
132
133 $completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null;
134 \core_completion\api::update_completion_date_event($data->coursemodule, 'resource', $data->id, $completiontimeexpected);
135
a2c57666 136 return true;
137}
138
139/**
140 * Updates display options based on form input.
141 *
142 * Shared code used by resource_add_instance and resource_update_instance.
143 *
144 * @param object $data Data object
145 */
146function resource_set_display_options($data) {
aa54ed7b 147 $displayoptions = array();
148 if ($data->display == RESOURCELIB_DISPLAY_POPUP) {
149 $displayoptions['popupwidth'] = $data->popupwidth;
150 $displayoptions['popupheight'] = $data->popupheight;
65634a81 151 }
aa54ed7b 152 if (in_array($data->display, array(RESOURCELIB_DISPLAY_AUTO, RESOURCELIB_DISPLAY_EMBED, RESOURCELIB_DISPLAY_FRAME))) {
aa54ed7b 153 $displayoptions['printintro'] = (int)!empty($data->printintro);
3efe78df 154 }
a2c57666 155 if (!empty($data->showsize)) {
156 $displayoptions['showsize'] = 1;
157 }
158 if (!empty($data->showtype)) {
159 $displayoptions['showtype'] = 1;
160 }
ba8b641d
AH
161 if (!empty($data->showdate)) {
162 $displayoptions['showdate'] = 1;
163 }
aa54ed7b 164 $data->displayoptions = serialize($displayoptions);
d18830fe 165}
166
28f672b2 167/**
aa54ed7b 168 * Delete resource instance.
28f672b2 169 * @param int $id
aa54ed7b 170 * @return bool true
28f672b2 171 */
d18830fe 172function resource_delete_instance($id) {
aa54ed7b 173 global $DB;
ec81373f 174
aa54ed7b 175 if (!$resource = $DB->get_record('resource', array('id'=>$id))) {
d18830fe 176 return false;
177 }
79035d46 178
b3bd7a66
MN
179 $cm = get_coursemodule_from_instance('resource', $id);
180 \core_completion\api::update_completion_date_event($cm->id, 'resource', $id, null);
181
aa54ed7b 182 // note: all context files are deleted automatically
ec81373f 183
aa54ed7b 184 $DB->delete_records('resource', array('id'=>$resource->id));
d18830fe 185
aa54ed7b 186 return true;
d18830fe 187}
188
28f672b2 189/**
190 * Given a course_module object, this function returns any
191 * "extra" information that may be needed when printing
192 * this activity in a course listing.
193 *
194 * See {@link get_array_of_activities()} in course/lib.php
195 *
3c620d7f 196 * @param stdClass $coursemodule
3e4c2435 197 * @return cached_cm_info info
28f672b2 198 */
8dddba42 199function resource_get_coursemodule_info($coursemodule) {
aa54ed7b 200 global $CFG, $DB;
201 require_once("$CFG->libdir/filelib.php");
202 require_once("$CFG->dirroot/mod/resource/locallib.php");
516c5eca
PS
203 require_once($CFG->libdir.'/completionlib.php');
204
bf0f06b1 205 $context = context_module::instance($coursemodule->id);
ec81373f 206
3e4c2435 207 if (!$resource = $DB->get_record('resource', array('id'=>$coursemodule->instance),
208 'id, name, display, displayoptions, tobemigrated, revision, intro, introformat')) {
aa54ed7b 209 return NULL;
af65e103 210 }
ec81373f 211
3e4c2435 212 $info = new cached_cm_info();
aa54ed7b 213 $info->name = $resource->name;
3e4c2435 214 if ($coursemodule->showdescription) {
215 // Convert intro to html. Do not filter cached version, filters run at display time.
216 $info->content = format_module_intro('resource', $resource, $coursemodule->id, false);
217 }
8dddba42 218
aa54ed7b 219 if ($resource->tobemigrated) {
c3847443 220 $info->icon ='i/invalid';
aa54ed7b 221 return $info;
af65e103 222 }
66234de2 223
224 // See if there is at least one file.
f79321f1 225 $fs = get_file_storage();
66234de2 226 $files = $fs->get_area_files($context->id, 'mod_resource', 'content', 0, 'sortorder DESC, id ASC', false, 0, 0, 1);
f79321f1 227 if (count($files) >= 1) {
020088d6 228 $mainfile = reset($files);
72225e18 229 $info->icon = file_file_icon($mainfile, 24);
f79321f1
DC
230 $resource->mainfile = $mainfile->get_filename();
231 }
d18830fe 232
aa54ed7b 233 $display = resource_get_final_display_type($resource);
9f741612 234
aa54ed7b 235 if ($display == RESOURCELIB_DISPLAY_POPUP) {
236 $fullurl = "$CFG->wwwroot/mod/resource/view.php?id=$coursemodule->id&amp;redirect=1";
237 $options = empty($resource->displayoptions) ? array() : unserialize($resource->displayoptions);
238 $width = empty($options['popupwidth']) ? 620 : $options['popupwidth'];
239 $height = empty($options['popupheight']) ? 450 : $options['popupheight'];
240 $wh = "width=$width,height=$height,toolbar=no,location=no,menubar=no,copyhistory=no,status=no,directories=no,scrollbars=yes,resizable=yes";
3e4c2435 241 $info->onclick = "window.open('$fullurl', '', '$wh'); return false;";
6da4b261 242
aa54ed7b 243 } else if ($display == RESOURCELIB_DISPLAY_NEW) {
244 $fullurl = "$CFG->wwwroot/mod/resource/view.php?id=$coursemodule->id&amp;redirect=1";
3e4c2435 245 $info->onclick = "window.open('$fullurl'); return false;";
6da4b261 246
6da4b261 247 }
89bfeee0 248
9dfe8704
MG
249 // If any optional extra details are turned on, store in custom data,
250 // add some file details as well to be used later by resource_get_optional_details() without retriving.
251 // Do not store filedetails if this is a reference - they will still need to be retrieved every time.
252 if (($filedetails = resource_get_file_details($resource, $coursemodule)) && empty($filedetails['isref'])) {
253 $displayoptions = @unserialize($resource->displayoptions);
254 $displayoptions['filedetails'] = $filedetails;
255 $info->customdata = serialize($displayoptions);
256 } else {
257 $info->customdata = $resource->displayoptions;
258 }
a2c57666 259
aa54ed7b 260 return $info;
6da4b261 261}
f3221af9 262
a2c57666 263/**
264 * Called when viewing course page. Shows extra details after the link if
265 * enabled.
266 *
267 * @param cm_info $cm Course module information
268 */
269function resource_cm_info_view(cm_info $cm) {
9a584346
MG
270 global $CFG;
271 require_once($CFG->dirroot . '/mod/resource/locallib.php');
272
273 $resource = (object)array('displayoptions' => $cm->customdata);
274 $details = resource_get_optional_details($resource, $cm);
a2c57666 275 if ($details) {
276 $cm->set_after_link(' ' . html_writer::tag('span', $details,
277 array('class' => 'resourcelinkdetails')));
278 }
279}
f3221af9 280
28f672b2 281/**
aa54ed7b 282 * Lists all browsable file areas
d2b7803e
DC
283 *
284 * @package mod_resource
285 * @category files
286 * @param stdClass $course course object
287 * @param stdClass $cm course module object
288 * @param stdClass $context context object
28f672b2 289 * @return array
290 */
aa54ed7b 291function resource_get_file_areas($course, $cm, $context) {
292 $areas = array();
64f93798 293 $areas['content'] = get_string('resourcecontent', 'resource');
aa54ed7b 294 return $areas;
f3221af9 295}
296
28f672b2 297/**
f1b8bcf7 298 * File browsing support for resource module content area.
d2b7803e
DC
299 *
300 * @package mod_resource
301 * @category files
302 * @param stdClass $browser file browser instance
303 * @param stdClass $areas file areas
304 * @param stdClass $course course object
305 * @param stdClass $cm course module object
306 * @param stdClass $context context object
307 * @param string $filearea file area
308 * @param int $itemid item ID
309 * @param string $filepath file path
310 * @param string $filename file name
311 * @return file_info instance or null if not found
28f672b2 312 */
aa54ed7b 313function resource_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) {
314 global $CFG;
a69be0d8 315
64f93798
PS
316 if (!has_capability('moodle/course:managefiles', $context)) {
317 // students can not peak here!
318 return null;
319 }
a69be0d8 320
aa54ed7b 321 $fs = get_file_storage();
a69be0d8 322
64f93798 323 if ($filearea === 'content') {
aa54ed7b 324 $filepath = is_null($filepath) ? '/' : $filepath;
325 $filename = is_null($filename) ? '.' : $filename;
a69be0d8 326
aa54ed7b 327 $urlbase = $CFG->wwwroot.'/pluginfile.php';
64f93798 328 if (!$storedfile = $fs->get_file($context->id, 'mod_resource', 'content', 0, $filepath, $filename)) {
aa54ed7b 329 if ($filepath === '/' and $filename === '.') {
64f93798 330 $storedfile = new virtual_root_file($context->id, 'mod_resource', 'content', 0);
a69be0d8 331 } else {
aa54ed7b 332 // not found
333 return null;
a69be0d8 334 }
335 }
aa54ed7b 336 require_once("$CFG->dirroot/mod/resource/locallib.php");
64f93798 337 return new resource_content_file_info($browser, $context, $storedfile, $urlbase, $areas[$filearea], true, true, true, false);
a69be0d8 338 }
339
aa54ed7b 340 // note: resource_intro handled in file_browser automatically
a69be0d8 341
aa54ed7b 342 return null;
a69be0d8 343}
344
0b5a80a1 345/**
aa54ed7b 346 * Serves the resource files.
d2b7803e
DC
347 *
348 * @package mod_resource
349 * @category files
350 * @param stdClass $course course object
351 * @param stdClass $cm course module object
352 * @param stdClass $context context object
353 * @param string $filearea file area
354 * @param array $args extra arguments
355 * @param bool $forcedownload whether or not force download
261cbbac 356 * @param array $options additional options affecting the file serving
b4ff85aa 357 * @return bool false if file not found, does not return if found - just send the file
28f672b2 358 */
261cbbac 359function resource_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
aa54ed7b 360 global $CFG, $DB;
361 require_once("$CFG->libdir/resourcelib.php");
0d06b6fd 362
64f93798 363 if ($context->contextlevel != CONTEXT_MODULE) {
aa54ed7b 364 return false;
3efe78df 365 }
366
64f93798 367 require_course_login($course, true, $cm);
ce459060
PS
368 if (!has_capability('mod/resource:view', $context)) {
369 return false;
370 }
3efe78df 371
64f93798
PS
372 if ($filearea !== 'content') {
373 // intro is handled automatically in pluginfile.php
aa54ed7b 374 return false;
3efe78df 375 }
376
aa54ed7b 377 array_shift($args); // ignore revision - designed to prevent caching problems only
3efe78df 378
aa54ed7b 379 $fs = get_file_storage();
64f93798 380 $relativepath = implode('/', $args);
fe3c5dae
PS
381 $fullpath = rtrim("/$context->id/mod_resource/$filearea/0/$relativepath", '/');
382 do {
383 if (!$file = $fs->get_file_by_hash(sha1($fullpath))) {
9815ccee 384 if ($fs->get_file_by_hash(sha1("$fullpath/."))) {
fe3c5dae
PS
385 if ($file = $fs->get_file_by_hash(sha1("$fullpath/index.htm"))) {
386 break;
387 }
388 if ($file = $fs->get_file_by_hash(sha1("$fullpath/index.html"))) {
389 break;
390 }
391 if ($file = $fs->get_file_by_hash(sha1("$fullpath/Default.htm"))) {
392 break;
393 }
394 }
395 $resource = $DB->get_record('resource', array('id'=>$cm->instance), 'id, legacyfiles', MUST_EXIST);
396 if ($resource->legacyfiles != RESOURCELIB_LEGACYFILES_ACTIVE) {
397 return false;
398 }
399 if (!$file = resourcelib_try_file_migration('/'.$relativepath, $cm->id, $cm->course, 'mod_resource', 'content', 0)) {
400 return false;
401 }
402 // file migrate - update flag
403 $resource->legacyfileslast = time();
404 $DB->update_record('resource', $resource);
0d06b6fd 405 }
fe3c5dae 406 } while (false);
ffcfd8a7 407
aa54ed7b 408 // should we apply filters?
409 $mimetype = $file->get_mimetype();
112aed60 410 if ($mimetype === 'text/html' or $mimetype === 'text/plain' or $mimetype === 'application/xhtml+xml') {
64f93798 411 $filter = $DB->get_field('resource', 'filterfiles', array('id'=>$cm->instance));
4eaa964f 412 $CFG->embeddedsoforcelinktarget = true;
aa54ed7b 413 } else {
414 $filter = 0;
18a2a0cb 415 }
18a2a0cb 416
aa54ed7b 417 // finally send the file
0c431257 418 send_stored_file($file, null, $filter, $forcedownload, $options);
13ca1e06 419}
b1627a92
DC
420
421/**
422 * Return a list of page types
423 * @param string $pagetype current page type
424 * @param stdClass $parentcontext Block's parent context
425 * @param stdClass $currentcontext Current context of block
426 */
b38e2e28 427function resource_page_type_list($pagetype, $parentcontext, $currentcontext) {
b1627a92
DC
428 $module_pagetype = array('mod-resource-*'=>get_string('page-mod-resource-x', 'resource'));
429 return $module_pagetype;
430}
ec0d6ea2
DC
431
432/**
433 * Export file resource contents
434 *
435 * @return array of file content
436 */
437function resource_export_contents($cm, $baseurl) {
438 global $CFG, $DB;
439 $contents = array();
bf0f06b1 440 $context = context_module::instance($cm->id);
ec0d6ea2
DC
441 $resource = $DB->get_record('resource', array('id'=>$cm->instance), '*', MUST_EXIST);
442
443 $fs = get_file_storage();
444 $files = $fs->get_area_files($context->id, 'mod_resource', 'content', 0, 'sortorder DESC, id ASC', false);
445
446 foreach ($files as $fileinfo) {
447 $file = array();
448 $file['type'] = 'file';
449 $file['filename'] = $fileinfo->get_filename();
450 $file['filepath'] = $fileinfo->get_filepath();
451 $file['filesize'] = $fileinfo->get_filesize();
452 $file['fileurl'] = file_encode_url("$CFG->wwwroot/" . $baseurl, '/'.$context->id.'/mod_resource/content/'.$resource->revision.$fileinfo->get_filepath().$fileinfo->get_filename(), true);
453 $file['timecreated'] = $fileinfo->get_timecreated();
454 $file['timemodified'] = $fileinfo->get_timemodified();
455 $file['sortorder'] = $fileinfo->get_sortorder();
456 $file['userid'] = $fileinfo->get_userid();
457 $file['author'] = $fileinfo->get_author();
458 $file['license'] = $fileinfo->get_license();
1104a9fa
JL
459 $file['mimetype'] = $fileinfo->get_mimetype();
460 $file['isexternalfile'] = $fileinfo->is_external_file();
461 if ($file['isexternalfile']) {
462 $file['repositorytype'] = $fileinfo->get_repository_type();
463 }
ec0d6ea2
DC
464 $contents[] = $file;
465 }
466
467 return $contents;
468}
32528f94
DS
469
470/**
471 * Register the ability to handle drag and drop file uploads
472 * @return array containing details of the files / types the mod can handle
473 */
6b8b0b2e 474function resource_dndupload_register() {
32528f94
DS
475 return array('files' => array(
476 array('extension' => '*', 'message' => get_string('dnduploadresource', 'mod_resource'))
477 ));
478}
479
480/**
481 * Handle a file that has been uploaded
482 * @param object $uploadinfo details of the file / content that has been uploaded
483 * @return int instance id of the newly created mod
484 */
6b8b0b2e 485function resource_dndupload_handle($uploadinfo) {
abed5d65
DS
486 // Gather the required info.
487 $data = new stdClass();
488 $data->course = $uploadinfo->course->id;
489 $data->name = $uploadinfo->displayname;
5fece0f2 490 $data->intro = '';
abed5d65
DS
491 $data->introformat = FORMAT_HTML;
492 $data->coursemodule = $uploadinfo->coursemodule;
493 $data->files = $uploadinfo->draftitemid;
494
495 // Set the display options to the site defaults.
32528f94 496 $config = get_config('resource');
abed5d65
DS
497 $data->display = $config->display;
498 $data->popupheight = $config->popupheight;
499 $data->popupwidth = $config->popupwidth;
abed5d65 500 $data->printintro = $config->printintro;
10654e32
SH
501 $data->showsize = (isset($config->showsize)) ? $config->showsize : 0;
502 $data->showtype = (isset($config->showtype)) ? $config->showtype : 0;
ba8b641d 503 $data->showdate = (isset($config->showdate)) ? $config->showdate : 0;
a274df85 504 $data->filterfiles = $config->filterfiles;
32528f94 505
abed5d65 506 return resource_add_instance($data, null);
32528f94 507}
537f7b38
JL
508
509/**
510 * Mark the activity completed (if required) and trigger the course_module_viewed event.
511 *
512 * @param stdClass $resource resource object
513 * @param stdClass $course course object
514 * @param stdClass $cm course module object
515 * @param stdClass $context context object
516 * @since Moodle 3.0
517 */
518function resource_view($resource, $course, $cm, $context) {
519
520 // Trigger course_module_viewed event.
521 $params = array(
522 'context' => $context,
523 'objectid' => $resource->id
524 );
525
526 $event = \mod_resource\event\course_module_viewed::create($params);
527 $event->add_record_snapshot('course_modules', $cm);
528 $event->add_record_snapshot('course', $course);
529 $event->add_record_snapshot('resource', $resource);
530 $event->trigger();
531
532 // Completion.
533 $completion = new completion_info($course);
534 $completion->set_module_viewed($cm);
535}
02a73d76
JL
536
537/**
538 * Check if the module has any update that affects the current user since a given time.
539 *
540 * @param cm_info $cm course module data
541 * @param int $from the time to check updates from
542 * @param array $filter if we need to check only specific updates
543 * @return stdClass an object with the different type of areas indicating if they were updated or not
544 * @since Moodle 3.2
545 */
546function resource_check_updates_since(cm_info $cm, $from, $filter = array()) {
547 $updates = course_check_module_updates_since($cm, $from, array('content'), $filter);
548 return $updates;
549}
b3bd7a66
MN
550
551/**
59391e80
MN
552 * This function receives a calendar event and returns the action associated with it, or null if there is none.
553 *
554 * This is used by block_myoverview in order to display the event appropriately. If null is returned then the event
555 * is not displayed on the block.
b3bd7a66 556 *
e1cd93ce 557 * @param calendar_event $event
b3bd7a66 558 * @param \core_calendar\action_factory $factory
01f96180 559 * @return \core_calendar\local\event\entities\action_interface|null
b3bd7a66 560 */
e1cd93ce 561function mod_resource_core_calendar_provide_event_action(calendar_event $event,
3ff8068f
P
562 \core_calendar\action_factory $factory, $userid = 0) {
563
564 global $USER;
565
566 if (empty($userid)) {
567 $userid = $USER->id;
568 }
569
570 $cm = get_fast_modinfo($event->courseid, $userid)->instances['resource'][$event->instance];
b3bd7a66 571
50d845e3 572 $completion = new \completion_info($cm->get_course());
b3bd7a66 573
3ff8068f 574 $completiondata = $completion->get_data($cm, false, $userid);
b3bd7a66
MN
575
576 if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
577 return null;
578 }
579
580 return $factory->create_instance(
581 get_string('view'),
582 new \moodle_url('/mod/resource/view.php', ['id' => $cm->id]),
583 1,
584 true
585 );
586}