예제 #1
0
 public function getCityRegion()
 {
     if (is_null($this->city_region) && is_numeric($this->city_region_id)) {
         $d = new Location_Domain_CityRegion();
         $this->city_region = $d->getById($this->city_region_id);
     }
     if (is_null($this->city_region)) {
         $this->city_region = new Location_Model_CityRegion();
     }
     return $this->city_region;
 }
예제 #2
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);
     }
 }
예제 #3
0
 public function populate($data)
 {
     if (isset($data['id'])) {
         $this->_region->setId($data['id']);
     }
     $this->_region->setName($data['name']);
     if (isset($data['city_id'])) {
         $dc = new Location_Domain_City();
         $c = $dc->getById($data['city_id']);
         $this->_region->setCity($c);
         $this->_region->setCity_id($data['city_id']);
     }
     if (isset($data['parent_id'])) {
         if (is_numeric($data['parent_id'])) {
             $dc = new Location_Domain_CityRegion();
             $c = $dc->getById($data['parent_id']);
             $this->_region->setParent($c);
             $this->_region->setParent_id($data['parent_id']);
         }
     }
 }
예제 #4
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);
     }
 }