// Update 'viewed' state if required by completion system $completion = new completion_info($course); $completion->set_module_viewed($cm); $PAGE->set_url('/mod/pdfparts/view.php', array('id' => $cm->id)); $fs = get_file_storage(); $files = $fs->get_area_files($context->id, 'mod_pdfparts', 'content', 0, 'sortorder DESC, id ASC', false); // TODO: this is not very efficient!! if (count($files) < 1) { resource_print_filenotfound($pdfparts, $cm, $course); die; } else { $file = reset($files); unset($files); } $pdfparts->mainfile = $file->get_filename(); $displaytype = pdfparts_get_final_display_type($pdfparts); // override the property loaded from DB with the values from the GET request if ($pages) { $pdfparts->pages = $pages; // I don't like this ideea, but... } /* if ($displaytype == RESOURCELIB_DISPLAY_OPEN || $displaytype == RESOURCELIB_DISPLAY_DOWNLOAD) { // For 'open' and 'download' links, we always redirect to the content - except // if the user just chose 'save and display' from the form then that would be // confusing if (!isset($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], 'modedit.php') === false) { $redirect = true; } }
/** * Given a course_module object, this function returns any * "extra" information that may be needed when printing * this activity in a course listing. * * See {@link get_array_of_activities()} in course/lib.php * * @param object $coursemodule * @return object info */ function pdfparts_get_coursemodule_info($coursemodule) { global $CFG, $DB; require_once "{$CFG->libdir}/filelib.php"; require_once "{$CFG->dirroot}/mod/pdfparts/locallib.php"; require_once $CFG->libdir . '/completionlib.php'; $context = context_module::instance($coursemodule->id); if (!($pdfparts = $DB->get_record('pdfparts', array('id' => $coursemodule->instance), 'id, name, revision'))) { return null; } $info = new cached_cm_info(); $info->name = $pdfparts->name; // we want to use the default module icon instead of the PDF file icon. $info->icon = null; $display = pdfparts_get_final_display_type($pdfparts); if ($display == RESOURCELIB_DISPLAY_POPUP) { $fullurl = "{$CFG->wwwroot}/mod/pdfparts/view.php?id={$coursemodule->id}&redirect=1"; $options = empty($resource->displayoptions) ? array() : unserialize($resource->displayoptions); $width = empty($options['popupwidth']) ? 620 : $options['popupwidth']; $height = empty($options['popupheight']) ? 450 : $options['popupheight']; $wh = "width={$width},height={$height},toolbar=no,location=no,menubar=no,copyhistory=no,status=no,directories=no,scrollbars=yes,resizable=yes"; $info->extra = "onclick=\"window.open('{$fullurl}', '', '{$wh}'); return false;\""; } else { if ($display == RESOURCELIB_DISPLAY_NEW) { $fullurl = "{$CFG->wwwroot}/mod/pdfparts/view.php?id={$coursemodule->id}&redirect=1"; $info->extra = "onclick=\"window.open('{$fullurl}'); return false;\""; } } if ($coursemodule->showdescription) { // Convert intro to html. Do not filter cached version, filters run at display time. $info->content = format_module_intro('pdfparts', $pdfparts, $coursemodule->id, false); } return $info; }