/** * Preprocessing the file list to add the portfolio links if required. * * @param array $dir * @param string $filearea * @param string $component * @return void */ public function preprocess($dir, $filearea, $component) { global $CFG; // Added // Start global $DB; // End foreach ($dir['subdirs'] as $subdir) { $this->preprocess($subdir, $filearea, $component); } foreach ($dir['files'] as $file) { $file->portfoliobutton = ''; // Added // Start /** * Get the created at time of the file from the table using it's id. */ $fileData = $DB->get_record('files', ['id' => $file->get_id()]); $timestamp = date("d-m-Y H:i:s", $fileData->timecreated); $file->createdAt = $timestamp; // End if (!empty($CFG->enableportfolios)) { require_once($CFG->libdir . '/portfoliolib.php'); $button = new portfolio_add_button(); if (has_capability('mod/assign:exportownsubmission', $this->context)) { $portfolioparams = array('cmid' => $this->cm->id, 'fileid' => $file->get_id()); $button->set_callback_options('assign_portfolio_caller', $portfolioparams, 'mod_assign'); $button->set_format_by_file($file); $file->portfoliobutton = $button->to_html(PORTFOLIO_ADD_ICON_LINK); } } $path = '/' . $this->context->id . '/' . $component . '/' . $filearea . '/' . $file->get_itemid() . $file->get_filepath() . $file->get_filename(); $url = file_encode_url("$CFG->wwwroot/pluginfile.php", $path, true); $filename = $file->get_filename(); $file->fileurl = html_writer::link($url, $filename, [ 'target' => '_blank', ]); } }