2008-09-29 05:18:23 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Contents of an UserDefinedForm submission
|
2009-12-07 03:04:20 +01:00
|
|
|
*
|
|
|
|
* @package userforms
|
2008-09-29 05:18:23 +02:00
|
|
|
*/
|
2009-12-07 03:04:20 +01:00
|
|
|
|
2008-09-29 05:18:23 +02:00
|
|
|
class SubmittedForm extends DataObject {
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $has_one = array(
|
2008-09-29 05:18:23 +02:00
|
|
|
"SubmittedBy" => "Member",
|
|
|
|
"Parent" => "UserDefinedForm",
|
|
|
|
);
|
2015-09-11 00:20:06 +02:00
|
|
|
|
|
|
|
private static $has_many = array(
|
2010-09-08 12:35:43 +02:00
|
|
|
"Values" => "SubmittedFormField"
|
2008-09-29 05:18:23 +02:00
|
|
|
);
|
2013-03-04 22:45:54 +01:00
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $summary_fields = array(
|
2013-03-04 22:45:54 +01:00
|
|
|
'ID',
|
|
|
|
'Created'
|
|
|
|
);
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2013-03-04 22:45:54 +01:00
|
|
|
/**
|
|
|
|
* Returns the value of a relation or, in the case of this form, the value
|
|
|
|
* of a given child {@link SubmittedFormField}
|
2015-09-11 00:20:06 +02:00
|
|
|
*
|
2013-03-04 22:45:54 +01:00
|
|
|
* @param string
|
2015-09-11 00:20:06 +02:00
|
|
|
*
|
2013-03-04 22:45:54 +01:00
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function relField($fieldName) {
|
|
|
|
// default case
|
|
|
|
if($value = parent::relField($fieldName)) {
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check values for a form field with the matching name.
|
|
|
|
$formField = SubmittedFormField::get()->filter(array(
|
|
|
|
'ParentID' => $this->ID,
|
|
|
|
'Name' => $fieldName
|
|
|
|
))->first();
|
|
|
|
|
|
|
|
if($formField) {
|
|
|
|
return $formField->getFormattedValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return FieldList
|
|
|
|
*/
|
|
|
|
public function getCMSFields() {
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2015-04-20 03:58:15 +02:00
|
|
|
$self = $this;
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2015-04-20 03:58:15 +02:00
|
|
|
$this->beforeUpdateCMSFields(function($fields) use ($self) {
|
|
|
|
$fields->removeByName('Values');
|
|
|
|
$fields->dataFieldByName('SubmittedByID')->setDisabled(true);
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2015-04-20 03:58:15 +02:00
|
|
|
$values = new GridField(
|
2015-09-11 00:20:06 +02:00
|
|
|
'Values',
|
2015-04-20 03:58:15 +02:00
|
|
|
'SubmittedFormField',
|
|
|
|
$self->Values()->sort('Created', 'ASC')
|
|
|
|
);
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2015-04-20 03:58:15 +02:00
|
|
|
$config = new GridFieldConfig();
|
|
|
|
$config->addComponent(new GridFieldDataColumns());
|
|
|
|
$config->addComponent(new GridFieldExportButton());
|
|
|
|
$config->addComponent(new GridFieldPrintButton());
|
|
|
|
$values->setConfig($config);
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2015-04-20 03:58:15 +02:00
|
|
|
$fields->addFieldToTab('Root.Main', $values);
|
|
|
|
});
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2013-03-04 22:45:54 +01:00
|
|
|
$fields = parent::getCMSFields();
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2013-03-04 22:45:54 +01:00
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
2013-05-13 04:32:41 +02:00
|
|
|
/**
|
|
|
|
* @param Member
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function canCreate($member = null) {
|
2016-04-22 03:33:02 +02:00
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member);
|
|
|
|
if($extended !== null) {
|
|
|
|
return $extended;
|
|
|
|
}
|
2013-05-13 04:32:41 +02:00
|
|
|
return $this->Parent()->canCreate();
|
|
|
|
}
|
|
|
|
|
2013-05-01 00:49:57 +02:00
|
|
|
/**
|
|
|
|
* @param Member
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function canView($member = null) {
|
2016-04-22 03:33:02 +02:00
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member);
|
|
|
|
if($extended !== null) {
|
|
|
|
return $extended;
|
|
|
|
}
|
2013-05-01 00:49:57 +02:00
|
|
|
return $this->Parent()->canView();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Member
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function canEdit($member = null) {
|
2016-04-22 03:33:02 +02:00
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member);
|
|
|
|
if($extended !== null) {
|
|
|
|
return $extended;
|
|
|
|
}
|
2013-05-01 00:49:57 +02:00
|
|
|
return $this->Parent()->canEdit();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Member
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function canDelete($member = null) {
|
2016-04-22 03:33:02 +02:00
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member);
|
|
|
|
if($extended !== null) {
|
|
|
|
return $extended;
|
|
|
|
}
|
2013-05-01 00:49:57 +02:00
|
|
|
return $this->Parent()->canDelete();
|
|
|
|
}
|
|
|
|
|
2009-04-15 00:59:46 +02:00
|
|
|
/**
|
2009-04-15 06:23:43 +02:00
|
|
|
* Before we delete this form make sure we delete all the
|
|
|
|
* field values so that we don't leave old data round
|
2009-04-15 00:59:46 +02:00
|
|
|
*
|
2013-03-04 22:45:54 +01:00
|
|
|
* @return void
|
2009-04-15 00:59:46 +02:00
|
|
|
*/
|
2009-04-15 06:23:43 +02:00
|
|
|
protected function onBeforeDelete() {
|
2010-09-08 12:35:43 +02:00
|
|
|
if($this->Values()) {
|
|
|
|
foreach($this->Values() as $value) {
|
2009-04-15 06:23:43 +02:00
|
|
|
$value->delete();
|
|
|
|
}
|
|
|
|
}
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2009-04-15 06:23:43 +02:00
|
|
|
parent::onBeforeDelete();
|
2008-09-29 05:18:23 +02:00
|
|
|
}
|
2013-05-01 00:49:57 +02:00
|
|
|
}
|