/**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return CitySitePhone the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = CitySitePhone::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 public function actionSYNInfo()
 {
     //$models = CitySitePhone::model()->findAllByAttributes(array('active'=>1, 'main_center'=>1));
     $criteria = new CDbCriteria();
     $criteria->with = array('city', 'site');
     $criteria->together = true;
     //$criteria->compare('city.main_city',1);
     $criteria->compare('t.active', 1);
     $models = CitySitePhone::model()->findAll($criteria);
     if ($models) {
         $json = array();
         $city = '';
         foreach ($models as $model) {
             //$json[] = array('phone'=>$model->phone, 'city'=>$model->city->city, 'site'=>$model->site->site);
             //если город основной тогда выводим его название, если нет тогда выводим название рег. центра
             if ($model->city->main_city == 1) {
                 $json[] = array('phone' => $model->phone, 'city' => $model->city->city, 'site' => $model->site->site, 'direct_phone' => $model->direct_phone, 'google_phone' => $model->google_phone);
             } else {
                 $json[] = array('phone' => $model->phone, 'city' => $model->city->region->city, 'site' => $model->site->site, 'direct_phone' => $model->direct_phone, 'google_phone' => $model->google_phone);
             }
         }
         echo json_encode($json);
     }
 }