public function networkField($network, $fields) { if (!$network instanceof Network_Model_Network || !$network->field_id || !$fields || false == ($field = $fields->getRowMatching('field_id', $network->field_id)) || empty($network->pattern['type']) || empty($network->pattern['value'])) { return $this->view->translate('n/a'); } $type = $network->pattern['type']; $value = $network->pattern['value']; $info = Engine_Api::_()->fields()->getFieldInfo($field->type); $genericType = $field->type; if (!empty($info['base'])) { $genericType = $info['base']; } $content = $this->view->translate($field->label); switch ($type) { case 'text': case 'exact': $content .= ' (' . $value . ')'; break; case 'select': case 'multiselect': if ($field->type == 'country') { $tmp = new Fields_Form_Element_Country('tmp'); $multiOptions = $tmp->getMultiOptions(); $option = $multiOptions[$value]; } else { if ($field->type != $genericType) { $elOpt = $field->getElementParams(null); $option = $elOpt['options']['multiOptions'][$value]; } else { $option = $field->getOption($value); if (is_object($option)) { $option = $option->label; } } } if (is_array($value)) { return $content .= ' (' . $this->view->translate('Multiple Options') . ')'; } if (!$option) { return $this->view->translate('n/a'); } $content .= ' (' . $this->view->translate($option) . ')'; break; case 'range': case 'date': $arr = array(); if (!empty($value['min']) && !empty($value['max'])) { $content .= ' (' . $value['min'] . ' - ' . $value['max'] . ')'; } else { if (!empty($value['min']) && empty($value['max'])) { $content .= ' (>' . $value['min'] . ')'; } else { if (empty($value['min']) && !empty($value['max'])) { $content .= ' (<' . $value['max'] . ')'; } else { return $this->view->translate('n/a'); } } } break; default: return $this->view->translate('n/a'); break; } return $content; }
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'; // Get options $multiOptions = array(); if ($meta->type == 'country') { $tmp = new Fields_Form_Element_Country('tmp'); $multiOptions = $tmp->getMultiOptions(); } else { if ($meta->type != $genericType) { //die('whoops'); $elOpt = $meta->getElementParams(null); $multiOptions = $elOpt['options']['multiOptions']; } else { foreach ($meta->getOptions() as $option) { $multiOptions[$option->option_id] = $option->label; } } } if (empty($multiOptions)) { continue; } $this->addElement('Multiselect', $id, array('label' => 'Matching Value', 'multiOptions' => $multiOptions)); break; // Text // Text case 'text': case 'textarea': $pattern_type = 'text'; $this->addElement('Textarea', $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'); }