public function getAdditionalOptionsElement() { $subform = new Zend_Form_SubForm(array('name' => 'extra', 'order' => 1000000, 'decorators' => array('FormElements'))); Engine_Form::enableForm($subform); $subform->addElement('Checkbox', 'has_photo', array('label' => 'Only Members With Photos', 'decorators' => array('ViewHelper', array('Label', array('placement' => 'APPEND', 'tag' => 'label')), array('HtmlTag', array('tag' => 'li'))))); $subform->addElement('Checkbox', 'is_online', array('label' => 'Only Online Members', 'decorators' => array('ViewHelper', array('Label', array('placement' => 'APPEND', 'tag' => 'label')), array('HtmlTag', array('tag' => 'li'))))); $subform->addElement('Button', 'done', array('label' => 'Search', 'onclick' => 'javascript:searchMembers()', 'ignore' => true)); $this->addSubForm($subform, $subform->getName()); return $this; }
public function generate() { // get the search structure $structure = Engine_Api::_()->getApi('core', 'fields')->getFieldsStructureSearch($this->_fieldType, $this->_topLevelId, $this->_topLevelValue); $globalOrderIndex = 100; $normalOrderIndex = 1000; // Start firing away foreach ($structure as $map) { $field = $map->getChild(); // Ignore fields not searchable (even though getFieldsStructureSearch should have skipped it already) if (!$field->search) { continue; } $isGlobal = $map->field_id == 0 || $field->search == 2 || $map->field_id == $this->_topLevelId && $map->option_id == $this->_topLevelValue; // Get search key $key = null; if (!empty($field->alias)) { $key = $field->alias; } else { $key = sprintf('field_%d', $field->field_id); } // Get params $params = $field->getElementParams($this->_fieldType, array('required' => false)); // Add attribs if (!@is_array($params['options']['attribs'])) { $params['options']['attribs'] = array(); } $params['options']['attribs']['class'] = 'field_toggle' . ' ' . 'parent_' . $map->field_id . ' ' . 'option_' . $map->option_id . ' ' . 'field_' . $map->child_id . ' '; if ($isGlobal) { $params['options']['attribs']['class'] .= ' field_toggle_nohide'; } $params['options']['attribs']['onchange'] = 'changeFields();'; //$params['options']['attribs']['id'] = $map->getKey(); // Remove some stuff unset($params['options']['required']); unset($params['options']['allowEmpty']); unset($params['options']['validators']); // Change decorators $params['options']['decorators'] = array('ViewHelper', array('Label', array('tag' => 'span')), array('HtmlTag', array('tag' => 'li', 'style' => !$isGlobal ? 'display:none;' : ''))); // Change order if ($isGlobal) { $params['options']['order'] = $globalOrderIndex++; } else { $params['options']['order'] = $normalOrderIndex++; } // Get generic type $info = Engine_Api::_()->fields()->getFieldInfo($field->type); $genericType = null; if (!empty($info['base'])) { $genericType = $info['base']; } else { $genericType = $field->type; } $params['type'] = $genericType; // For now // Hack birthdate->age if ($field->type == 'birthdate') { $params['type'] = 'Select'; $params['options']['label'] = Zend_Registry::get('Zend_Translate')->translate('Age'); $params['options']['disableTranslator'] = true; $multiOptions = array('' => ' '); $min_age = 13; if (isset($field->config['min_age'])) { $min_age = $field->config['min_age']; } for ($i = $min_age; $i <= 100; $i++) { $multiOptions[$i] = $i; } $params['options']['multiOptions'] = $multiOptions; } // Populate country multiOptions if ($field->type == 'country') { $locale = Zend_Registry::get('Locale'); $territories = Zend_Locale::getTranslationList('territory', $locale, 2); asort($territories); // fixes #1279 $params['options']['multiOptions'] = array_merge(array('' => ''), $territories); } // Ignored fields (these are hard-coded) if (in_array($field->type, array('profile_type', 'first_name', 'last_name'))) { continue; } // Hacks switch ($genericType) { // Ranges case 'date': case 'int': case 'integer': case 'float': // Use subform $subform = new Zend_Form_SubForm(array('description' => $params['options']['label'], 'order' => $params['options']['order'], 'decorators' => array('FormElements', array('Description', array('placement' => 'PREPEND', 'tag' => 'span')), array('HtmlTag', array('tag' => 'li', 'class' => 'browse-range-wrapper', 'style' => !$isGlobal ? 'display:none;' : ''))))); Fields_Form_Standard::enableForm($subform); Engine_Form::enableForm($subform); unset($params['options']['label']); unset($params['options']['order']); $params['options']['decorators'] = array('ViewHelper'); $subform->addElement($params['type'], 'min', $params['options']); $subform->addElement($params['type'], 'max', $params['options']); $this->addSubForm($subform, $key); break; // Select types // Select types case 'select': case 'radio': case 'multiselect': case 'multi_checkbox': // Ignore if there is only one/zero option? if (count(@$params['options']['multiOptions']) <= 1 && isset($params['options']['multiOptions'][''])) { continue; } else { if (count(@$params['options']['multiOptions']) <= 0) { continue; } } $this->addElement(Engine_Api::_()->fields()->inflectFieldType($params['type']), $key, $params['options']); break; // Checkbox // Checkbox case 'checkbox': $params['options']['uncheckedValue'] = null; $params['options']['decorators'] = array('ViewHelper', array('Label', array('placement' => 'APPEND', 'tag' => 'label')), array('HtmlTag', array('tag' => 'li', 'class' => 'browse-range-wrapper', 'style' => !$isGlobal ? 'display:none;' : ''))); $this->addElement($params['type'], $key, $params['options']); break; // Normal // Normal default: $this->addElement($params['type'], $key, $params['options']); break; } $element = $this->{$key}; //$element = $this->getElement($key); $this->_fieldElements[$key] = $element; } // Add a separators? $this->addElement('Heading', 'separator1', array('order' => $globalOrderIndex++, 'decorators' => array('ViewHelper', array('Label', array('tag' => 'span')), array('HtmlTag', array('tag' => 'li', 'class' => 'browse-separator-wrapper'))))); $this->addElement('Heading', 'separator2', array('order' => $normalOrderIndex++, 'decorators' => array('ViewHelper', array('Label', array('tag' => 'span')), array('HtmlTag', array('tag' => 'li', 'class' => 'browse-separator-wrapper'))))); }
public function init() { $this->setAttrib('id', 'admin-form')->setMethod('POST')->setAction($_SERVER['REQUEST_URI'])->setTitle('Create Network')->setDescription('NETWORK_FORM_ADMIN_NETWORK_DESCRIPTION'); // Set up form title/params //if( !$isCreate ) { // $this->setTitle('Edit Network'); //} // set up hidden param //if( !$isCreate ) { // $network = Engine_Api::_()->network()->getNetwork($this->_networkIdentity); //} else { // $network = null; //} // init name $this->addElement('Text', 'title', array('label' => 'Name', 'required' => true, 'allowEmpty' => false)); // init description $this->addElement('Text', 'description', array('label' => 'Description', 'validators' => array(array('StringLength', true, array(6, 32))))); // init assignment $this->addElement('Radio', 'assignment', array('label' => 'Member Assignment', 'required' => true, 'allowEmpty' => false, 'multiOptions' => array('0' => 'Members can choose to join this network at any time', '1' => 'Members are automatically assigned to this network', '2' => 'Members must be assigned to this network by an administrator'))); // init field_id $this->addElement('Select', 'field_id', array('label' => 'Related Profile Question', 'multiOptions' => array('' => ''))); // init fields $fieldsMeta = Engine_Api::_()->fields()->getFieldsMeta("user"); $fieldTypes = array(); foreach ($fieldsMeta as $meta) { $info = Engine_Api::_()->fields()->getFieldInfo($meta->type); $genericType = $meta->type; if (!empty($info['base'])) { $genericType = $info['base']; } $id = 'field_pattern_' . $meta->field_id; $pattern_type = null; switch ($genericType) { // Select case 'select': case 'radio': case 'multiselect': case 'multi_checkbox': $pattern_type = 'select'; $options = $meta->getOptions(); if (empty($options)) { continue; } $multiOptions = array(); foreach ($options as $option) { $multiOptions[$option->option_id] = $option->label; } $this->addElement('Select', $id, array('label' => 'Matching Value', 'multiOptions' => $multiOptions)); break; // Text // Text case 'text': case 'textarea': $pattern_type = 'text'; $this->addElement('Text', $id, array('label' => 'Matching Value')); break; // Range - birthday // Range - birthday case 'date': case 'birthdate': case 'birthday': $pattern_type = 'date'; $subform = new Zend_Form_SubForm(array()); Engine_Form::enableForm($subform); $subform->addElement('Date', 'min', array('label' => 'From:')); $subform->addElement('Date', 'max', array('label' => 'To:')); $this->addSubForm($subform, $id); //$this->$id->getDecorator(); break; // Range // Range case 'integer': case 'float': $pattern_type = 'range'; $subform = new Zend_Form_SubForm(array()); Engine_Form::enableForm($subform); $subform->addElement($genericType, 'min', array('label' => 'From:')); $subform->addElement($genericType, 'max', array('label' => 'To:')); $this->addSubForm($subform, $id); break; // Unknown // Unknown default: continue 2; break; } $el = $this->{$id}; if ($el instanceof Zend_Form_SubForm) { $el->setDecorators(array(array('FormElements'), array('HtmlTag', array('tag' => 'div', 'class' => 'form-wrapper network_field_container', 'id' => $id . '-wrapper', 'style' => 'display:none')))); } else { if ($el instanceof Zend_Form_Element) { $el->getDecorator('HtmlTag2')->setOption('class', 'form-wrapper network_field_container')->setOption('style', 'display:none'); } else { continue; } } $fieldTypes[$meta->field_id] = $pattern_type; $this->field_id->addMultiOption($meta->field_id, $meta->label); } // Field types $this->addElement('Hidden', 'types', array('value' => Zend_Json::encode($fieldTypes))); // Add invisible $this->addElement('Checkbox', 'hide', array('label' => 'Yes, hide membership for this network.', 'description' => 'Invisible?')); // Buttons $this->addElement('Button', 'submit', array('label' => 'Save Changes', 'type' => 'submit', 'ignore' => true, 'decorators' => array('ViewHelper'))); $this->addElement('Cancel', 'cancel', array('label' => 'cancel', 'link' => true, 'prependText' => ' or ', 'ignore' => true, 'href' => Zend_Controller_Front::getInstance()->getRouter()->assemble(array('module' => 'network', 'controller' => 'manage', 'action' => 'index'), 'admin_default', true), 'decorators' => array('ViewHelper'))); $this->addDisplayGroup(array('submit', 'cancel'), 'buttons'); }