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