2012-04-14 08:36:50 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A file uploaded on a {@link UserDefinedForm} and attached to a single
|
|
|
|
* {@link SubmittedForm}
|
|
|
|
*
|
|
|
|
* @package userforms
|
|
|
|
*/
|
|
|
|
|
|
|
|
class SubmittedFileField extends SubmittedFormField {
|
|
|
|
|
|
|
|
static $has_one = array(
|
|
|
|
"UploadedFile" => "File"
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the value of this field for inclusion into things such as reports
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-05-04 03:39:08 +02:00
|
|
|
public function getFormattedValue() {
|
2012-04-14 08:36:50 +02:00
|
|
|
$link = $this->getLink();
|
|
|
|
$title = _t('SubmittedFileField.DOWNLOADFILE', 'Download File');
|
|
|
|
|
2012-04-20 02:12:03 +02:00
|
|
|
if($link) {
|
2012-04-14 08:36:50 +02:00
|
|
|
return sprintf('<a href="%s">%s</a>', $link, $title);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2012-05-07 11:19:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the value for this field in the CSV export
|
|
|
|
*
|
|
|
|
* @return String
|
|
|
|
*/
|
|
|
|
public function getExportValue() {
|
|
|
|
return ($link = $this->getLink()) ? $link : "";
|
|
|
|
}
|
2012-04-14 08:36:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the link for the file attached to this submitted form field
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-05-04 03:39:08 +02:00
|
|
|
public function getLink() {
|
2012-04-14 08:36:50 +02:00
|
|
|
if($file = $this->UploadedFile()) {
|
|
|
|
if(trim($file->getFilename(), '/') != trim(ASSETS_DIR,'/')) {
|
|
|
|
return $this->UploadedFile()->URL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|