public function preprocess($dir, $filearea, $component) {
        global $CFG;

        foreach ($dir['subdirs'] as $subdir) {
            $this->preprocess($subdir, $filearea, $component);
        }
        foreach ($dir['files'] as $file) {
            $file->portfoliobutton = '';

            $file->timemodified = userdate(
                $file->get_timemodified(),
                get_string('strftimedatetime', 'langconfig')
            );

            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',
                ]);
        }
    }
public function preprocess($dir, $filearea, $component) {
        global $CFG;

        foreach ($dir['subdirs'] as $subdir) {
            $this->preprocess($subdir, $filearea, $component);
        }
        foreach ($dir['files'] as $file) {
            $file->portfoliobutton = '';

            $file->timemodified = userdate(
                $file->get_timemodified(),
                get_string('strftimedatetime', 'langconfig')
            );

            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',
                ]);
        }
    }
public function preprocess ( $ dir , $ filearea , $ component ) { global $ CFG ; foreach ( $ dir [ 'subdirs' ] as $ subdir ) { $ this -> preprocess ( $ subdir , $ filearea , $ component ) ; } foreach ( $ dir [ 'files' ] as $ file ) { $ file -> portfoliobutton = '' ; $ file -> timemodified = userdate ( $ file -> get_timemodified ( ) , get_string ( 'strftimedatetime' , 'langconfig' ) ) ; 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' , ] ) ; } }
Preprocessing the file list to add the portfolio links if required.

@param array $dir
@param string $filearea
@param string $component
@return void
Preprocessing the file list to add the portfolio links if required .