Beispiel #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Xata();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Xata'])) {
         $data = $_POST['Xata'];
         //$data['Xata']['owner']=1;//Yii::app()->user->id;
         if ($cntry_id = Country::check($data['country_caption'], $data['country_short'])) {
             if ($city_id = City::check($data['city_caption'], $cntry_id)) {
                 unset($data['country_short']);
                 unset($data['country_caption']);
                 unset($data['city_caption']);
                 $type_id = 0;
                 for ($i = 2; $i >= 0; $i--) {
                     if (isset($_POST['type_id_lvl' . $i])) {
                         if ($type_id = (int) $_POST['type_id_lvl' . $i]) {
                             break;
                         }
                     }
                 }
                 if ($type_id) {
                     $data['type_id'] = $type_id;
                 }
                 $data['owner'] = Yii::app()->user->id;
                 // Saving owner as current user
                 $data['city_id'] = $city_id;
                 $model->attributes = $data;
                 if ($model->save()) {
                     $userXata = new UserXata();
                     $userXata->attributes = array('uid' => Yii::app()->user->id, 'xid' => $model->getPrimaryKey(), 'rights' => hexdec('FFFFFF'), 'public' => 10);
                     if ($userXata->save()) {
                         $this->redirect(array('view', 'id' => $model->id));
                     }
                 }
             }
             // if city is setted
         }
         // if country is setted
     }
     // if there is POST
     $this->render('create', array('model' => $model));
 }
Beispiel #2
0
 /**
  * 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 the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = UserXata::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }