2012-04-14 08:36:50 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A file uploaded on a {@link UserDefinedForm} and attached to a single
|
2013-01-29 09:44:00 +01:00
|
|
|
* {@link SubmittedForm}.
|
2012-04-14 08:36:50 +02:00
|
|
|
*
|
|
|
|
* @package userforms
|
|
|
|
*/
|
|
|
|
|
|
|
|
class SubmittedFileField extends SubmittedFormField {
|
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $has_one = array(
|
2012-04-14 08:36:50 +02:00
|
|
|
"UploadedFile" => "File"
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
2013-01-29 09:44:00 +01:00
|
|
|
* Return the value of this field for inclusion into things such as
|
|
|
|
* reports.
|
2012-04-14 08:36:50 +02:00
|
|
|
*
|
|
|
|
* @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) {
|
2013-09-04 23:46:38 +02:00
|
|
|
return DBField::create_field('HTMLText', sprintf(
|
2013-01-29 09:44:00 +01:00
|
|
|
'%s - <a href="%s" target="_blank">%s</a>',
|
|
|
|
$name, $link, $title
|
2013-09-04 23:46:38 +02:00
|
|
|
));
|
2012-04-14 08:36:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2012-05-07 11:19:16 +02:00
|
|
|
|
|
|
|
/**
|
2013-01-29 09:44:00 +01:00
|
|
|
* Return the value for this field in the CSV export.
|
2012-05-07 11:19:16 +02:00
|
|
|
*
|
2013-01-29 09:44:00 +01:00
|
|
|
* @return string
|
2012-05-07 11:19:16 +02:00
|
|
|
*/
|
|
|
|
public function getExportValue() {
|
|
|
|
return ($link = $this->getLink()) ? $link : "";
|
|
|
|
}
|
2012-04-14 08:36:50 +02:00
|
|
|
|
2013-01-29 09:44:00 +01:00
|
|
|
/**
|
|
|
|
* Return the link for the file attached to this submitted form field.
|
2012-04-14 08:36:50 +02:00
|
|
|
*
|
|
|
|
* @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()) {
|
2012-07-17 06:09:31 +02:00
|
|
|
if(trim($file->getFilename(), '/') != trim(ASSETS_DIR,'/')) {
|
2012-04-14 08:36:50 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2013-01-29 09:44:00 +01:00
|
|
|
}
|