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