MetaModels\Helper\ToolboxFile::resolveFiles PHP Method

resolveFiles() public method

Process all folders and resolve to a valid file list.
public resolveFiles ( ) : ToolboxFile
return ToolboxFile
    public function resolveFiles()
    {
        // Step 1.: fetch all files.
        $this->collectFiles();
        // TODO: check if downloading is allowed and send file to browser then
        // See https://github.com/MetaModels/attribute_file/issues/6 for details of how to implement this.
        if (!$this->getShowImages() && ($strFile = \Input::get('file')) && in_array($strFile, $this->foundFiles)) {
            \Controller::sendFileToBrowser($strFile);
        }
        // Step 2.: fetch additional information like modification time etc. and prepare the output buffer.
        $this->fetchAdditionalData();
        return $this;
    }

Usage Example

 /**
  * {@inheritdoc}
  */
 protected function prepareTemplate(Template $objTemplate, $arrRowData, $objSettings)
 {
     parent::prepareTemplate($objTemplate, $arrRowData, $objSettings);
     $objToolbox = new ToolboxFile();
     $objToolbox->setBaseLanguage($this->getMetaModel()->getActiveLanguage());
     $objToolbox->setFallbackLanguage($this->getMetaModel()->getFallbackLanguage());
     $objToolbox->setLightboxId(sprintf('%s.%s.%s', $this->getMetaModel()->getTableName(), $objSettings->get('id'), $arrRowData['id']));
     if (strlen($this->get('file_validFileTypes'))) {
         $objToolbox->setAcceptedExtensions($this->get('file_validFileTypes'));
     }
     $objToolbox->setShowImages($objSettings->get('file_showImage'));
     if ($objSettings->get('file_imageSize')) {
         $objToolbox->setResizeImages($objSettings->get('file_imageSize'));
     }
     if ($arrRowData[$this->getColName()]) {
         if (isset($arrRowData[$this->getColName()]['value']['bin'])) {
             foreach ($arrRowData[$this->getColName()]['value']['bin'] as $strFile) {
                 $objToolbox->addPathById($strFile);
             }
         } elseif (is_array($arrRowData[$this->getColName()])) {
             // FIXME: should not happen anymore.
             foreach ($arrRowData[$this->getColName()] as $strFile) {
                 $objToolbox->addPathById($strFile);
             }
         } else {
             // FIXME: should not happen anymore.
             $objToolbox->addPathById($arrRowData[$this->getColName()]);
         }
     }
     $objToolbox->resolveFiles();
     $arrData = $objToolbox->sortFiles($objSettings->get('file_sortBy'));
     $objTemplate->files = $arrData['files'];
     $objTemplate->src = $arrData['source'];
 }