Ejemplo n.º 1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Foro();
     date_default_timezone_set("America/Monterrey");
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Foro'])) {
         $model->attributes = $_POST['Foro'];
         $usuarioActual = Usuario::model()->obtenerUsuarioActual();
         if (isset($_GET["id"])) {
             $model->identificador = $_GET["id"];
             $temaPrincipal = $this->loadModel($_GET["id"]);
             $temaPrincipal->respuestas++;
             $temaPrincipal->fecha_f = date("Y-d-m H:i:s", strtotime($temaPrincipal->fecha_f));
             $temaPrincipal->ult_respuesta = date("Y-d-m H:i:s", strtotime($temaPrincipal->ult_respuesta));
             $temaPrincipal->save();
         } else {
             $model->identificador = 0;
         }
         $model->respuestas = 0;
         $model->fecha_f = date("Y-d-m H:i:s");
         $model->ult_respuesta = date("Y-d-m H:i:s");
         $model->estatus_did = 1;
         $model->usuario_did = $usuarioActual->id;
         if ($model->save()) {
             Yii::app()->user->setFlash('info', "Agregó un nuevo mensaje: ' " . $model->mensaje . "'");
             $this->redirect(array('view', 'id' => isset($_GET["id"]) ? $_GET["id"] : $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Ejemplo n.º 2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Foro();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Foro'])) {
         date_default_timezone_set('America/Monterrey');
         $usuarioActual = Usuario::model()->obtenerUsuarioActual();
         $model->attributes = $_POST['Foro'];
         $model->autor = $usuarioActual->nombre . " " . $usuarioActual->apPaterno . " " . $usuarioActual->apMaterno;
         $model->fecha_f = date("Y-d-m H:m:s");
         $model->respuestas++;
         if (isset($_GET["id"])) {
             $model->identificador = $_GET["id"];
             $temaPrincipal = $this->loadModel($_GET["id"]);
             $temaPrincipal->respuestas++;
             $temaPrincipal->fecha_f = date("Y-d-m H:i:s", strtotime($temaPrincipal->fecha_f));
             $temaPrincipal->ult_respuesta = date("Y-d-m H:i:s", strtotime($temaPrincipal->ult_respuesta));
             $temaPrincipal->save();
         } else {
             $model->respuestas = 0;
             $model->identificador = 0;
         }
         $model->ult_respuesta = date("Y-d-m H:m:s");
         $model->estatus_did = 2;
         $model->usuario_did = $usuarioActual->id;
         if ($model->save()) {
             if (isset($_GET["foro"])) {
                 Yii::app()->user->setFlash('info', "Se envió tu respuesta");
                 $this->redirect(array('view', 'id' => $_GET["foro"]));
             } else {
                 Yii::app()->user->setFlash('info', "Se envió tu foro, lo publicarán lo antes posible");
                 $this->redirect(array('index'));
             }
         }
     }
     $this->render('create', array('model' => $model));
 }