silverstripe-userforms/code/model/formfields/EditableMemberListField.php

48 lines
1.2 KiB
PHP
Raw Normal View History

<?php
/**
* Creates an editable field that displays members in a given group
*
* @package userforms
*/
class EditableMemberListField extends EditableFormField {
static $singular_name = 'Member List Field';
2009-04-27 06:32:47 +02:00
static $plural_name = 'Member List Fields';
public function getFieldConfiguration() {
2009-04-27 08:17:02 +02:00
$groupID = ($this->getSetting('GroupID')) ? $this->getSetting('GroupID') : 0;
$groups = DataObject::get("Group");
if($groups) $groups = $groups->map('ID', 'Title');
$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;
}
public function getFormField() {
if ($this->getSetting('GroupID')) {
$members = Member::map_in_groups($this->getSetting('GroupID'));
return new DropdownField($this->Name, $this->Title, $members);
}
return false;
}
public function getValueFromData($data) {
if(isset($data[$this->Name])) {
$value = Convert::raw2sql($data[$this->Name]);
$member = DataObject::get_one('Member', "Member.ID = {$value}");
return ($member) ? $member->getName() : "";
}
return false;
}
}