Source of file CleanFile.php
Size: 3,518 Bytes - Last Modified: 2022-02-21T10:01:58+00:00
/var/www/docs.ssmods.com/process/src/code/models/CleanFile.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 | <?php /** * A wrapper for File, which adds a Title field * and a relation to it's page. * * @package cleanutilities * @subpackage models * * @author arillo */ class CleanFile extends DataObject { private static $db = array( 'Title'=> 'Text' ); private static $has_one = array( 'Attachment' => 'File', 'Reference' => 'SiteTree' ); private static $searchable_fields = array( 'Title', "Attachment.Extension", 'Attachment.Title' ); private static $summary_fields = array( 'Title' => 'Title', 'Attachment.Extension' => 'Type', 'Attachment.Title' => 'Attachment' ); /** * Allowed file extensions for uploading. * @var array */ public static $allowed_extensions = array( '','html','htm','xhtml','js','css', 'bmp','png','gif','jpg','jpeg','ico','pcx','tif','tiff', 'au','mid','midi','mpa','mp3','ogg','m4a','ra','wma','wav','cda', 'avi','mpg','mpeg','asf','wmv','m4v','mov','mkv','mp4','swf','flv','ram','rm', 'doc','docx','txt','rtf','xls','xlsx','pages', 'ppt','pptx','pps','csv', 'cab','arj','tar','zip','zipx','sit','sitx','gz','tgz','bz2','ace','arc','pkg','dmg','hqx','jar', 'xml','pdf', ); /** * This var specifies the name of the upload folder * @var string */ public static $upload_folder = "files"; /** * CMS fields, can be extended by write your * own updateCMSFields function. * @return FieldList */ public function getCMSFields() { $fields = FieldList::create( new TabSet( "Root", new Tab("Main") ) ); $fields->addFieldToTab( 'Root.Main', TextField::create( 'Title', _t('CleanUtilities.TITLE', 'Title') ) ); $upload = UploadField::create( 'Attachment', _t('CleanFile.FILE', 'File') ); $upload->setConfig('allowedMaxFileNumber', 1); $upload->getValidator()->setAllowedExtensions(self::$allowed_extensions); if ($this->hasExtension('ControlledFolderDataExtension')) { $upload->setFolderName($this->getUploadFolder()); } else { $upload->setFolderName(self::$upload_folder); } $fields->addFieldToTab('Root.Main', $upload); $this->extend('updateCMSFields', $fields); return $fields; } /** * Returns a download link like: * URLSegment/download/ClassName/ID * * To make this to work you need to implement a "download" function in * the Reference's controller. * This can be achieved by using DownloadExtension. * * @return string */ public function DownloadLink() { return Controller::join_links( $this->Reference()->Link('download'), $this->ClassName, $this->ID ); } /** * Returns a absolute download link like: * http://domain.com/URLSegment/download/ClassName/ID * * To make this to work you need to implement a "download" function in * the Reference's controller. * This can be achieved by using DownloadExtension. * * @return string */ public function AbsoluteDownloadLink() { return Director::absoluteURL( $this->DownloadLink() ); } } |