예제 #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Serie();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Serie'])) {
         $model->attributes = $_POST['Serie'];
         // Si es predeterminada desmarcamos el resto y marcamos esta
         if ($model->Pred == 1) {
             $criteria = new CDbCriteria();
             $criteria->condition = "UserID = :userid";
             $criteria->params = array(':userid' => Yii::app()->user->ID);
             $modelSeries = Serie::model()->findAll($criteria);
             foreach ($modelSeries as $serie) {
                 $laSerie = Serie::model()->findByPK($serie->ID);
                 $laSerie->Pred = 0;
                 $laSerie->save();
             }
         }
         if ($model->save()) {
             $this->redirect(array('admin'));
         }
     }
     $this->render('create', array('model' => $model));
 }