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;
|
2018-08-15 07:00:49 +02:00
|
|
|
use SilverStripe\ORM\FieldType\DBField;
|
|
|
|
use SilverStripe\Security\Member;
|
|
|
|
use SilverStripe\UserForms\Model\EditableFormField;
|
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
|
2018-08-15 07:00:49 +02:00
|
|
|
* <brs> so they will output as newlines in the reports.
|
2016-07-21 07:53:59 +02:00
|
|
|
*
|
2018-08-15 07:00:49 +02:00
|
|
|
* @return DBField
|
2016-07-21 07:53:59 +02:00
|
|
|
*/
|
|
|
|
public function getFormattedValue()
|
|
|
|
{
|
2018-08-15 07:00:49 +02:00
|
|
|
return $this->dbObject('Value');
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
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
|
|
|
|
*
|
2018-08-15 07:00:49 +02:00
|
|
|
* @return DBField
|
2016-07-21 07:53:59 +02:00
|
|
|
*/
|
|
|
|
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
|
|
|
}
|