예제 #1
0
 private function _addElementParent()
 {
     $this->addElement('select', 'parent_id', array('label' => 'Parent region', 'dimension' => 4));
     $el = $this->getElement('parent_id');
     $cd = new Location_Domain_CityRegion();
     $c = $cd->getAll('name');
     $el->addMultiOption(null, null);
     foreach ($c as $region) {
         $el->addMultiOption($region->getId(), $region->getName());
     }
     if ($this->_model && $this->_model->parent_id) {
         $el->setValue($this->_model->parent_id);
     }
 }
예제 #2
0
 /**
  * Adds an element CityRegionId.
  * Defaults:
  * name         = city_region_id
  * requires     = false
  * label        = City region
  * placeholder  = 'Choose a region'
  * dimension    = 4
  * modelfield   = city_region_id
  * showcity     = false (if should show city name with region name)
  * 
  * @param Zend_Form $form The Zend_Form object where the element will be added
  * @param array $options The options to pass in the element
  */
 public function addElementCityRegionId($form, $options = array())
 {
     $elementName = isset($options['name']) ? $options['name'] : 'city_region_id';
     $modelField = isset($options['modelfield']) ? $options['modelfield'] : 'city_region_id';
     $showCity = isset($options['showcity']) ? $options['showcity'] : false;
     $form->addElement('select', $elementName, array('filters' => array('StringTrim'), 'label' => isset($options['label']) ? $options['label'] : 'City region', 'dimension' => isset($options['dimension']) ? $options['dimension'] : 4, 'placeholder' => 'Choose a region', 'required' => isset($options['required']) ? $options['required'] : false, 'value' => $this->_model ? $this->_model->{$modelField} : ''));
     $el = $form->getElement($elementName);
     $cd = new Location_Domain_CityRegion();
     $c = $cd->getAll(array('orderby' => 'name'));
     $el->addMultiOption(null, null);
     foreach ($c as $region) {
         $regionName = $region->getName();
         if ($showCity) {
             $regionName .= ' (' . $region->getCity()->name . ')';
         }
         $el->addMultiOption($region->getId(), $regionName);
     }
     if ($this->_model && $this->_model->{$modelField}) {
         $el->setValue($this->_model->{$modelField});
     } else {
         $el->setValue(null);
     }
 }