/** {@inheritdoc} */ public function init() { parent::init(); $what = new \Zend\Form\Element\Radio('What'); $what->setValueOptions(array(\Model\Client\Client::MEMBERSHIP_AUTOMATIC => $this->_('Store search parameters. Group memberships will be updated automatically.'), \Model\Client\Client::MEMBERSHIP_ALWAYS => $this->_('Add current search results. Group memberships will be set only this time.'), \Model\Client\Client::MEMBERSHIP_NEVER => $this->_('Exclude search results from a group.'))); $what->setValue(\Model\Client\Client::MEMBERSHIP_AUTOMATIC); $this->add($what); $where = new \Zend\Form\Element\Radio('Where'); $where->setValueOptions(array('new' => $this->_('Store in new group'), 'existing' => $this->_('Store in existing group'))); $where->setValue('new')->setAttribute('onchange', 'selectElements()'); $this->add($where); $newGroup = new \Zend\Form\Element\Text('NewGroup'); $newGroup->setLabel('Name'); $this->add($newGroup); $description = new \Zend\Form\Element\Text('Description'); $description->setLabel('Description'); $this->add($description); $existingGroup = new \Library\Form\Element\SelectSimple('ExistingGroup'); $existingGroup->setLabel('Group'); $groups = array(); foreach ($this->getOption('GroupManager')->getGroups(null, null, 'Name') as $group) { $groups[] = $group['Name']; } $existingGroup->setValueOptions($groups); $this->add($existingGroup); $submit = new \Library\Form\Element\Submit('Submit'); $submit->setLabel('OK'); $this->add($submit); $inputFilter = new \Zend\InputFilter\InputFilter(); $inputFilter->add(array('name' => 'NewGroup', 'continue_if_empty' => true, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateLength'), 'callbackOptions' => array(0, 255), 'message' => $this->_('The input is more than 255 characters long')), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateLength'), 'callbackOptions' => array(1, 255), 'message' => "Value is required and can't be empty"), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateGroupExists'), 'message' => $this->_('The name already exists')))))); $inputFilter->add(array('name' => 'Description', 'required' => false, 'filters' => array(array('name' => 'StringTrim'), array('name' => 'Null', 'options' => array('type' => 'string'))), 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateLength'), 'callbackOptions' => array(0, 255), 'message' => $this->_('The input is more than 255 characters long')))))); $this->setInputFilter($inputFilter); }
/** * Set available groups * * The "Groups" fieldset is (re)created with radio buttons for each group. * * @param string[] $groups Group names */ public function setGroups(array $groups) { if ($this->has('Groups')) { $this->remove('Groups'); } $fieldset = new \Zend\Form\Fieldset('Groups'); $this->add($fieldset); $buttons = array(\Model\Client\Client::MEMBERSHIP_AUTOMATIC => $this->_('automatic'), \Model\Client\Client::MEMBERSHIP_ALWAYS => $this->_('always'), \Model\Client\Client::MEMBERSHIP_NEVER => $this->_('never')); foreach ($groups as $group) { $element = new \Zend\Form\Element\Radio($group); $element->setLabel($group); $element->setValueOptions($buttons); $element->setValue(\Model\Client\Client::MEMBERSHIP_AUTOMATIC); $fieldset->add($element); } }