silverstripe-userforms/code/Model/Submission/SubmittedFormField.php

116 lines
2.6 KiB
PHP
Raw Normal View History

<?php
namespace SilverStripe\UserForms\Model\Submission;
use SilverStripe\ORM\DataObject;
use SilverStripe\UserForms\Model\Submission\SubmittedForm;
/**
* Data received from a UserDefinedForm submission
*
* @package userforms
*/
2016-07-21 07:53:59 +02:00
class SubmittedFormField extends DataObject
{
private static $db = [
'Name' => 'Varchar',
'Value' => 'Text',
'Title' => 'Varchar(255)'
];
2015-09-11 00:20:06 +02:00
private static $has_one = [
'Parent' => SubmittedForm::class
];
private static $summary_fields = [
2016-07-21 07:53:59 +02:00
'Title' => 'Title',
'FormattedValue' => 'Value'
];
private static $casting = [
'FormattedValue' => 'HTMLFragment'
];
private static $table_name = 'SubmittedFormField';
2016-07-21 07:53:59 +02:00
/**
* @param Member $member
* @param array $context
2016-07-21 07:53:59 +02:00
* @return boolean
*/
public function canCreate($member = null, $context = [])
2016-07-21 07:53:59 +02:00
{
return $this->Parent()->canCreate();
}
2016-07-21 07:53:59 +02:00
/**
* @param Member $member
2016-07-21 07:53:59 +02:00
*
* @return boolean
*/
public function canView($member = null)
{
return $this->Parent()->canView();
}
2016-07-21 07:53:59 +02:00
/**
* @param Member $member
2016-07-21 07:53:59 +02:00
*
* @return boolean
*/
public function canEdit($member = null)
{
return $this->Parent()->canEdit();
}
2016-07-21 07:53:59 +02:00
/**
* @param Member $member
2016-07-21 07:53:59 +02:00
*
* @return boolean
*/
public function canDelete($member = null)
{
return $this->Parent()->canDelete();
}
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()
{
return $this->Parent()->Parent()->Fields()->filter([
2016-07-21 07:53:59 +02:00
'Name' => $this->Name
])->First();
2016-07-21 07:53:59 +02:00
}
}