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 {
|
|
|
|
|
2009-05-06 03:34:40 +00:00
|
|
|
static $singular_name = 'Member List Field';
|
2009-04-27 04:32:47 +00:00
|
|
|
|
2009-05-06 03:34:40 +00:00
|
|
|
static $plural_name = 'Member List Fields';
|
2008-09-29 03:18:23 +00:00
|
|
|
|
2012-05-04 13:39:08 +12:00
|
|
|
public function getFieldConfiguration() {
|
2009-04-27 06:17:02 +00:00
|
|
|
$groupID = ($this->getSetting('GroupID')) ? $this->getSetting('GroupID') : 0;
|
|
|
|
$groups = DataObject::get("Group");
|
2012-04-14 18:36:50 +12:00
|
|
|
|
2012-05-10 14:17:44 +12:00
|
|
|
if($groups) $groups = $groups->map('ID', 'Title');
|
2012-04-14 18:36:50 +12:00
|
|
|
|
2012-04-22 16:17:42 -03:00
|
|
|
$fields = new FieldList(
|
2009-04-27 06:17:02 +00:00
|
|
|
new DropdownField("Fields[$this->ID][CustomSettings][GroupID]", _t('EditableFormField.GROUP', 'Group'), $groups, $groupID)
|
|
|
|
);
|
|
|
|
|
|
|
|
return $fields;
|
|
|
|
}
|
2009-05-06 03:34:40 +00:00
|
|
|
|
2012-05-04 13:39:08 +12:00
|
|
|
public function getFormField() {
|
2012-04-14 18:36:50 +12:00
|
|
|
if ($this->getSetting('GroupID')) {
|
2012-05-10 14:17:44 +12:00
|
|
|
$members = Member::map_in_groups($this->getSetting('GroupID'));
|
2012-04-14 18:36:50 +12:00
|
|
|
|
|
|
|
return new DropdownField($this->Name, $this->Title, $members);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2008-09-29 03:18:23 +00: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])) {
|
|
|
|
$value = Convert::raw2sql($data[$this->Name]);
|
2008-09-29 03:18:23 +00:00
|
|
|
|
2011-01-18 16:15:57 +13:00
|
|
|
$member = DataObject::get_one('Member', "Member.ID = {$value}");
|
2012-04-14 18:36:50 +12:00
|
|
|
|
2011-01-18 16:15:57 +13:00
|
|
|
return ($member) ? $member->getName() : "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2008-09-29 03:18:23 +00:00
|
|
|
}
|
2009-12-07 02:04:20 +00:00
|
|
|
}
|