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;
|
2018-08-15 17:00:49 +12:00
|
|
|
use SilverStripe\ORM\FieldType\DBField;
|
|
|
|
use SilverStripe\Security\Member;
|
|
|
|
use SilverStripe\UserForms\Model\EditableFormField;
|
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
|
2021-02-26 16:13:23 +13:00
|
|
|
* @property string $Name
|
|
|
|
* @property string $Value
|
2023-12-15 17:04:35 +13:00
|
|
|
* @method SubmittedForm Parent()
|
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',
|
2022-03-07 11:02:34 +11:00
|
|
|
'Title' => 'Varchar(255)',
|
|
|
|
'Displayed' => 'Boolean',
|
2017-08-11 11:33:06 +12:00
|
|
|
];
|
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
|
|
|
|
2022-06-13 19:36:35 +12:00
|
|
|
private static $indexes = [
|
|
|
|
'Name' => 'Name',
|
|
|
|
];
|
|
|
|
|
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
|
2018-08-15 17:00:49 +12:00
|
|
|
* <brs> so they will output as newlines in the reports.
|
2016-07-21 17:53:59 +12:00
|
|
|
*
|
2018-08-15 17:00:49 +12:00
|
|
|
* @return DBField
|
2016-07-21 17:53:59 +12:00
|
|
|
*/
|
|
|
|
public function getFormattedValue()
|
|
|
|
{
|
2018-08-15 17:00:49 +12:00
|
|
|
return $this->dbObject('Value');
|
2016-07-21 17:53:59 +12:00
|
|
|
}
|
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
|
|
|
|
*
|
2018-08-15 17:00:49 +12:00
|
|
|
* @return DBField
|
2016-07-21 17:53:59 +12:00
|
|
|
*/
|
|
|
|
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
|
|
|
}
|