2009-04-17 04:26:40 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2015-09-11 00:20:06 +02:00
|
|
|
* Base Class for EditableOption Fields such as the ones used in
|
2009-04-17 04:26:40 +02:00
|
|
|
* dropdown fields and in radio check box groups
|
2015-09-11 00:20:06 +02:00
|
|
|
*
|
2015-12-22 23:14:36 +01:00
|
|
|
* @method EditableMultipleOptionField Parent()
|
2009-04-17 04:26:40 +02:00
|
|
|
* @package userforms
|
|
|
|
*/
|
|
|
|
class EditableOption extends DataObject {
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $default_sort = "Sort";
|
2009-04-17 04:26:40 +02:00
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $db = array(
|
2009-07-05 09:14:03 +02:00
|
|
|
"Name" => "Varchar(255)",
|
|
|
|
"Title" => "Varchar(255)",
|
2009-04-17 04:26:40 +02:00
|
|
|
"Default" => "Boolean",
|
|
|
|
"Sort" => "Int"
|
|
|
|
);
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $has_one = array(
|
2009-04-17 04:26:40 +02:00
|
|
|
"Parent" => "EditableMultipleOptionField",
|
|
|
|
);
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $extensions = array(
|
2009-09-23 03:36:52 +02:00
|
|
|
"Versioned('Stage', 'Live')"
|
|
|
|
);
|
2009-04-17 04:26:40 +02:00
|
|
|
|
2015-07-24 04:37:48 +02:00
|
|
|
private static $summary_fields = array(
|
|
|
|
'Title',
|
|
|
|
'Default'
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Member $member
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function canEdit($member = null) {
|
2015-12-22 23:14:36 +01:00
|
|
|
return $this->Parent()->canEdit($member);
|
2015-07-24 04:37:48 +02:00
|
|
|
}
|
2014-07-06 07:35:46 +02:00
|
|
|
|
2015-07-24 04:37:48 +02:00
|
|
|
/**
|
|
|
|
* @param Member $member
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function canDelete($member = null) {
|
2015-12-22 23:14:36 +01:00
|
|
|
return $this->canEdit($member);
|
2015-07-24 04:37:48 +02:00
|
|
|
}
|
2014-07-06 07:35:46 +02:00
|
|
|
|
2015-07-24 04:37:48 +02:00
|
|
|
public function getEscapedTitle() {
|
|
|
|
return Convert::raw2att($this->Title);
|
|
|
|
}
|
2015-12-22 23:14:36 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Member $member
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function canView($member = null) {
|
|
|
|
return $this->Parent()->canView($member);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return whether a user can create an object of this type
|
|
|
|
*
|
|
|
|
* @param Member $member
|
|
|
|
* @param array $context Virtual parameter to allow context to be passed in to check
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function canCreate($member = null) {
|
|
|
|
// Check parent page
|
|
|
|
$parent = $this->getCanCreateContext(func_get_args());
|
|
|
|
if($parent) {
|
|
|
|
return $parent->canEdit($member);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fall back to secure admin permissions
|
|
|
|
return parent::canCreate($member);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method to check the parent for this object
|
|
|
|
*
|
|
|
|
* @param array $args List of arguments passed to canCreate
|
|
|
|
* @return DataObject Some parent dataobject to inherit permissions from
|
|
|
|
*/
|
|
|
|
protected function getCanCreateContext($args) {
|
|
|
|
// Inspect second parameter to canCreate for a 'Parent' context
|
|
|
|
if(isset($args[1]['Parent'])) {
|
|
|
|
return $args[1]['Parent'];
|
|
|
|
}
|
|
|
|
// Hack in currently edited page if context is missing
|
|
|
|
if(Controller::has_curr() && Controller::curr() instanceof CMSMain) {
|
|
|
|
return Controller::curr()->currentPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
// No page being edited
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Member $member
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function canPublish($member = null) {
|
|
|
|
return $this->canEdit($member);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Member $member
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function canUnpublish($member = null) {
|
|
|
|
return $this->canDelete($member);
|
|
|
|
}
|
2016-07-21 08:08:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
protected function onBeforeWrite() {
|
|
|
|
if (!$this->Sort) {
|
|
|
|
$this->Sort = EditableOption::get()->max('Sort') + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::onBeforeWrite();
|
|
|
|
}
|
2013-05-08 09:08:21 +02:00
|
|
|
}
|