2008-09-29 05:18:23 +02:00
|
|
|
<?php
|
2017-08-09 01:55:09 +02:00
|
|
|
|
|
|
|
namespace SilverStripe\UserForms\Model\Submission;
|
|
|
|
|
|
|
|
use SilverStripe\ORM\DataObject;
|
2017-08-11 01:33:06 +02:00
|
|
|
use SilverStripe\UserForms\Model\Submission\SubmittedForm;
|
2017-08-09 01:55:09 +02:00
|
|
|
|
2008-09-29 05:18:23 +02:00
|
|
|
/**
|
|
|
|
* Data received from a UserDefinedForm submission
|
2009-04-15 06:23:43 +02:00
|
|
|
*
|
|
|
|
* @package userforms
|
2008-09-29 05:18:23 +02:00
|
|
|
*/
|
2016-07-21 07:53:59 +02:00
|
|
|
class SubmittedFormField extends DataObject
|
|
|
|
{
|
2017-08-11 01:33:06 +02:00
|
|
|
private static $db = [
|
|
|
|
'Name' => 'Varchar',
|
|
|
|
'Value' => 'Text',
|
|
|
|
'Title' => 'Varchar(255)'
|
|
|
|
];
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
private static $has_one = [
|
|
|
|
'Parent' => SubmittedForm::class
|
|
|
|
];
|
2013-03-04 22:45:54 +01:00
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
private static $summary_fields = [
|
2016-07-21 07:53:59 +02:00
|
|
|
'Title' => 'Title',
|
|
|
|
'FormattedValue' => 'Value'
|
2017-08-11 01:33:06 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
private static $table_name = 'SubmittedFormField';
|
2013-03-04 22:45:54 +01:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
/**
|
2017-08-11 01:33:06 +02:00
|
|
|
* @param Member $member
|
2017-08-14 02:29:57 +02:00
|
|
|
* @param array $context
|
2016-07-21 07:53:59 +02:00
|
|
|
* @return boolean
|
|
|
|
*/
|
2017-08-11 02:36:28 +02:00
|
|
|
public function canCreate($member = null, $context = [])
|
2016-07-21 07:53:59 +02:00
|
|
|
{
|
|
|
|
return $this->Parent()->canCreate();
|
|
|
|
}
|
2013-05-13 04:32:41 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
/**
|
2017-08-11 01:33:06 +02:00
|
|
|
* @param Member $member
|
2016-07-21 07:53:59 +02:00
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function canView($member = null)
|
|
|
|
{
|
|
|
|
return $this->Parent()->canView();
|
|
|
|
}
|
2013-05-01 00:49:57 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
/**
|
2017-08-11 01:33:06 +02:00
|
|
|
* @param Member $member
|
2016-07-21 07:53:59 +02:00
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function canEdit($member = null)
|
|
|
|
{
|
|
|
|
return $this->Parent()->canEdit();
|
|
|
|
}
|
2013-05-01 00:49:57 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
/**
|
2017-08-11 01:33:06 +02:00
|
|
|
* @param Member $member
|
2016-07-21 07:53:59 +02:00
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function canDelete($member = null)
|
|
|
|
{
|
|
|
|
return $this->Parent()->canDelete();
|
|
|
|
}
|
2013-05-01 00:49:57 +02:00
|
|
|
|
2016-07-21 07:53:59 +02: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 00:20:06 +02:00
|
|
|
|
2016-07-21 07:53:59 +02: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 01:12:00 +02:00
|
|
|
|
2016-07-21 07:53:59 +02: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 01:33:06 +02:00
|
|
|
return $this->Parent()->Parent()->Fields()->filter([
|
2016-07-21 07:53:59 +02:00
|
|
|
'Name' => $this->Name
|
2017-08-11 01:33:06 +02:00
|
|
|
])->First();
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
2008-09-29 05:18:23 +02:00
|
|
|
}
|