Exemple #1
0
 /**
  *
  * @param any $pParam
  * @return Zupal_Places_States
  */
 public static function get_state($pState, $country_id = NULL, $pCreate_if_missing = TRUE)
 {
     if ($pState instanceof Zupal_Places) {
         return self::get_state($pState->state, $pState->country_id);
     }
     if (is_numeric($pState)) {
         return new Zupal_Places_States($pState);
     }
     $i = self::getInstance();
     $select = $i->table()->select();
     if ($country_id) {
         $select->where('country = ?', $country_id);
     }
     $select->where('name LIKE ?', $pState);
     $select->orWhere('code LIKE ?', $pState);
     $row = $i->table()->fetchRow($select);
     if ($row) {
         return new Zupal_Places_States($row);
     }
     //@TODO: cache;
     // @TODO -- don't do for known contry states (like US)
     if ($pCreate_if_missing) {
         $state = new Zupal_Places_States();
         $state->set_name($pState);
         $state->set_country($country_id);
         $state->save();
     }
     return $state;
 }
Exemple #2
0
 public function set_state($pValue)
 {
     $state = Zupal_Places_States::getInstance()->get_state($pValue);
     if ($state) {
         $this->state = $state->identity();
     } else {
         $this->state = 0;
     }
 }
Exemple #3
0
 /**
  *
  * @return <type>
  */
 public function save()
 {
     $country = $this->getCountry();
     if ($country && $country->identity()) {
         $this->country_id = $country->identity();
         if ($this->getState()->identity()) {
             $this->state_id = $this->getState()->identity();
         } elseif ($this->state) {
             $state = new Zupal_Places_States();
             $state->set_value($this->state);
             $state->country = $this->country_id;
             $state->save();
             $this->state_id = $state->identity();
         }
         if ($this->getstate()->identity()) {
             $this->state_id = $this->getstate()->identity();
         }
     }
     parent::save();
 }