2008-09-29 03:18:23 +00:00
|
|
|
<?php
|
2017-08-09 11:55:09 +12:00
|
|
|
|
|
|
|
namespace SilverStripe\UserForms\Model\Submission;
|
|
|
|
|
|
|
|
use SilverStripe\ORM\DataObject;
|
2017-08-11 11:33:06 +12:00
|
|
|
use SilverStripe\UserForms\Model\Submission\SubmittedForm;
|
2017-08-09 11:55:09 +12:00
|
|
|
|
2008-09-29 03:18:23 +00:00
|
|
|
/**
|
|
|
|
* Data received from a UserDefinedForm submission
|
2009-04-15 04:23:43 +00:00
|
|
|
*
|
|
|
|
* @package userforms
|
2008-09-29 03:18:23 +00:00
|
|
|
*/
|
2016-07-21 17:53:59 +12:00
|
|
|
class SubmittedFormField extends DataObject
|
|
|
|
{
|
2017-08-11 11:33:06 +12:00
|
|
|
private static $db = [
|
|
|
|
'Name' => 'Varchar',
|
|
|
|
'Value' => 'Text',
|
|
|
|
'Title' => 'Varchar(255)'
|
|
|
|
];
|
2015-09-11 10:20:06 +12:00
|
|
|
|
2017-08-11 11:33:06 +12:00
|
|
|
private static $has_one = [
|
|
|
|
'Parent' => SubmittedForm::class
|
|
|
|
];
|
2013-03-05 10:45:54 +13:00
|
|
|
|
2017-08-11 11:33:06 +12:00
|
|
|
private static $summary_fields = [
|
2016-07-21 17:53:59 +12:00
|
|
|
'Title' => 'Title',
|
|
|
|
'FormattedValue' => 'Value'
|
2017-08-11 11:33:06 +12:00
|
|
|
];
|
|
|
|
|
|
|
|
private static $table_name = 'SubmittedFormField';
|
2013-03-05 10:45:54 +13:00
|
|
|
|
2016-07-21 17:53:59 +12:00
|
|
|
/**
|
2017-08-11 11:33:06 +12:00
|
|
|
* @param Member $member
|
2017-08-14 12:29:57 +12:00
|
|
|
* @param array $context
|
2016-07-21 17:53:59 +12:00
|
|
|
* @return boolean
|
|
|
|
*/
|
2017-08-11 12:36:28 +12:00
|
|
|
public function canCreate($member = null, $context = [])
|
2016-07-21 17:53:59 +12:00
|
|
|
{
|
|
|
|
return $this->Parent()->canCreate();
|
|
|
|
}
|
2013-05-13 14:32:41 +12:00
|
|
|
|
2016-07-21 17:53:59 +12:00
|
|
|
/**
|
2017-08-11 11:33:06 +12:00
|
|
|
* @param Member $member
|
2016-07-21 17:53:59 +12:00
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function canView($member = null)
|
|
|
|
{
|
|
|
|
return $this->Parent()->canView();
|
|
|
|
}
|
2013-05-01 10:49:57 +12:00
|
|
|
|
2016-07-21 17:53:59 +12:00
|
|
|
/**
|
2017-08-11 11:33:06 +12:00
|
|
|
* @param Member $member
|
2016-07-21 17:53:59 +12:00
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function canEdit($member = null)
|
|
|
|
{
|
|
|
|
return $this->Parent()->canEdit();
|
|
|
|
}
|
2013-05-01 10:49:57 +12:00
|
|
|
|
2016-07-21 17:53:59 +12:00
|
|
|
/**
|
2017-08-11 11:33:06 +12:00
|
|
|
* @param Member $member
|
2016-07-21 17:53:59 +12:00
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function canDelete($member = null)
|
|
|
|
{
|
|
|
|
return $this->Parent()->canDelete();
|
|
|
|
}
|
2013-05-01 10:49:57 +12:00
|
|
|
|
2016-07-21 17:53:59 +12:00
|
|
|
/**
|
|
|
|
* Generate a formatted value for the reports and email notifications.
|
|
|
|
* Converts new lines (which are stored in the database text field) as
|
|
|
|
* <brs> so they will output as newlines in the reports
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getFormattedValue()
|
|
|
|
{
|
|
|
|
return nl2br($this->dbObject('Value')->ATT());
|
|
|
|
}
|
2015-09-11 10:20:06 +12:00
|
|
|
|
2016-07-21 17:53:59 +12:00
|
|
|
/**
|
|
|
|
* Return the value of this submitted form field suitable for inclusion
|
|
|
|
* into the CSV
|
|
|
|
*
|
|
|
|
* @return Text
|
|
|
|
*/
|
|
|
|
public function getExportValue()
|
|
|
|
{
|
|
|
|
return $this->Value;
|
|
|
|
}
|
2014-08-11 11:12:00 +12:00
|
|
|
|
2016-07-21 17:53:59 +12:00
|
|
|
/**
|
|
|
|
* Find equivalent editable field for this submission.
|
|
|
|
*
|
|
|
|
* Note the field may have been modified or deleted from the original form
|
|
|
|
* so this may not always return the data you expect. If you need to save
|
|
|
|
* a particular state of editable form field at time of submission, copy
|
|
|
|
* that value to the submission.
|
|
|
|
*
|
|
|
|
* @return EditableFormField
|
|
|
|
*/
|
|
|
|
public function getEditableField()
|
|
|
|
{
|
2017-08-11 11:33:06 +12:00
|
|
|
return $this->Parent()->Parent()->Fields()->filter([
|
2016-07-21 17:53:59 +12:00
|
|
|
'Name' => $this->Name
|
2017-08-11 11:33:06 +12:00
|
|
|
])->First();
|
2016-07-21 17:53:59 +12:00
|
|
|
}
|
2008-09-29 03:18:23 +00:00
|
|
|
}
|