Version: current

     1 <?php
     2
     3 /**
     4  * A file uploaded on a {@link UserDefinedForm} and attached to a single
     5  * {@link SubmittedForm}
     6  *
     7  * @package userforms
     8  */
     9
    10 class SubmittedFileField extends SubmittedFormField {
    11
    12     static $has_one = array(
    13         "UploadedFile" => "File"
    14     );
    15
    16     /**
    17      * Return the value of this field for inclusion into things such as reports
    18      *
    19      * @return string
    20      */
    21     function getFormattedValue() {
    22         $link = $this->getLink();
    23         $title = _t('SubmittedFileField.DOWNLOADFILE', 'Download File');
    24
    25         if($link) {
    26             return sprintf('<a href="%s">%s</a>', $link, $title);
    27         }
    28
    29         return false;
    30     }
    31
    32     /**
    33      * Return the link for the file attached to this submitted form field
    34      *
    35      * @return string
    36      */
    37     function getLink() {
    38         if($file = $this->UploadedFile()) {
    39             if(trim($file->getFilename(), '/') != trim(ASSETS_DIR,'/'))  {
    40                 return $this->UploadedFile()->URL;
    41             }
    42         }
    43     }
    44 }

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -