rs = $rs; $this->fmp = $fmp; $this->router = $router; $this->process = $process; } /** * @param FolderItemBase $folderItem * @return null|array */ public function formatFolderToPublicDisplay(FolderItemBase $folderItem){ $ret = null; if($this->fmp->canReadFolder($folderItem)){ return $this->process->objectToArray($folderItem, array('name','guid','permission','base','description')); } return $ret; } public function formatFoldersToPublicDisplay(array $array){ $output = []; foreach($array as $folderItem){ if($folderItem instanceof FolderItemBase){ $output[] = $this->formatFolderToPublicDisplay($folderItem); } } return $output; } /** * @param FileItem $fileItem * @return null|array */ public function formatFileToPublicDisplay(FileItem $fileItem){ $tmp = null; //if actual user/virtualUser can read the file & the file is not hidden if($this->fmp->canRead($fileItem) && !$fileItem->isHidden()){ //get the file with default function $tmp = $this->process->objectToArray($fileItem, array('id','static','name','size','guid','permission','FilePreview','mime','dateUpd','originalHash','lastModified'), array('FilePreview' => array('ActualFileSecureArray'))); $tmp['FilePreview']['ActualFileSecureArrayAbsolute'] = false; //check if there's any preview if(isset($tmp['FilePreview']['ActualFileSecureArray']) && $tmp['FilePreview']['ActualFileSecureArray'] != false){ $tmpNewActualFileSecureArray = array(); $tmpNewActualFileSecureArrayAbsolute = array(); foreach($tmp['FilePreview']['ActualFileSecureArray'] as $size){ $tmpNewActualFileSecureArray[$size] = $this->router->generate('api_filemanager_distributor_display_thumbs', array( 'guid' => $tmp['guid'], 'size' => $size ) ).'?s='.(string)$fileItem->getFilePreview()->getSelected() .(string)$fileItem->getVersion(); $tmpNewActualFileSecureArrayAbsolute[$size] = $this->router->generate('api_filemanager_distributor_display_thumbs', array( 'guid' => $tmp['guid'], 'size' => $size ), UrlGeneratorInterface::ABSOLUTE_URL ).'?s='.(string)$fileItem->getFilePreview()->getSelected() .(string)$fileItem->getVersion(); } $tmp['FilePreview']['ActualFileSecureArray'] = $tmpNewActualFileSecureArray; $tmp['FilePreview']['ActualFileSecureArrayAbsolute'] = $tmpNewActualFileSecureArrayAbsolute; } //download & display links $tmp['display'] = $this->router->generate('api_filemanager_distributor_display',array('guid'=>$tmp['guid']),UrlGeneratorInterface::ABSOLUTE_URL); $tmp['download'] = $this->router->generate('api_filemanager_distributor_download',array('guid'=>$tmp['guid']),UrlGeneratorInterface::ABSOLUTE_URL); } return $tmp; } public function formatFilesToPublicDisplay(array $array){ $output = []; foreach($array as $fileItem){ if($fileItem instanceof FileItem){ $output[] = $this->formatFileToPublicDisplay($fileItem); } } return $output; } }