2008-09-29 05:18:23 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Creates an editable field that displays members in a given group
|
2009-04-17 04:26:40 +02: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 EditableMemberListField extends EditableFormField {
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $singular_name = 'Member List Field';
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $plural_name = 'Member List Fields';
|
2015-07-24 04:37:48 +02:00
|
|
|
|
|
|
|
private static $has_one = array(
|
|
|
|
'Group' => 'Group'
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return FieldList
|
|
|
|
*/
|
|
|
|
public function getCMSFields() {
|
|
|
|
$fields = parent::getCMSFields();
|
|
|
|
|
|
|
|
$fields->removeByName('Default');
|
|
|
|
$fields->removeByName('Validation');
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2015-07-24 04:37:48 +02:00
|
|
|
$fields->addFieldToTab(
|
|
|
|
'Root.Main',
|
|
|
|
DropdownField::create(
|
|
|
|
"GroupID",
|
|
|
|
_t('EditableFormField.GROUP', 'Group'),
|
|
|
|
Group::get()->map()
|
|
|
|
)->setEmptyString(' ')
|
2009-04-27 08:17:02 +02:00
|
|
|
);
|
2015-07-24 04:37:48 +02:00
|
|
|
|
2009-04-27 08:17:02 +02:00
|
|
|
return $fields;
|
|
|
|
}
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2012-05-04 03:39:08 +02:00
|
|
|
public function getFormField() {
|
2015-07-24 04:37:48 +02:00
|
|
|
if(empty($this->GroupID)) {
|
|
|
|
return false;
|
2012-04-14 08:36:50 +02:00
|
|
|
}
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2015-07-24 04:37:48 +02:00
|
|
|
$members = Member::map_in_groups($this->GroupID);
|
2015-08-10 07:03:36 +02:00
|
|
|
$field = new DropdownField($this->Name, $this->EscapedTitle, $members);
|
|
|
|
$this->doUpdateFormField($field);
|
|
|
|
return $field;
|
2008-09-29 05:18:23 +02:00
|
|
|
}
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2012-05-04 03:39:08 +02:00
|
|
|
public function getValueFromData($data) {
|
2011-01-18 04:15:57 +01:00
|
|
|
if(isset($data[$this->Name])) {
|
2015-07-24 04:37:48 +02:00
|
|
|
$memberID = $data[$this->Name];
|
|
|
|
$member = Member::get()->byID($memberID);
|
|
|
|
return $member ? $member->getName() : "";
|
2011-01-18 04:15:57 +01:00
|
|
|
}
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2011-01-18 04:15:57 +01:00
|
|
|
return false;
|
2008-09-29 05:18:23 +02:00
|
|
|
}
|
2009-12-07 03:04:20 +01:00
|
|
|
}
|