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-05-14 04:16:46 +02:00
|
|
|
$name = $this->getName();
|
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-05-14 04:16:46 +02:00
|
|
|
return sprintf('%s - <a href="%s" target="_blank">%s</a>', $name, $link, $title);
|
2012-04-14 08:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2012-05-14 04:16:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the name of the file, if present
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getName() {
|
|
|
|
if($this->UploadedFile()) {
|
|
|
|
return $this->UploadedFile()->Name;
|
|
|
|
}
|
|
|
|
}
|
2012-04-14 08:36:50 +02:00
|
|
|
}
|