/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Comentarios();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if ($model->fecha == '') {
         $model->fecha = NULL;
     }
     $model->postsIdPost = $_SESSION['idPost'];
     if (isset($_POST['Comentarios'])) {
         $model->attributes = $_POST['Comentarios'];
         if ($model->save()) {
             if (Yii::app()->request->isAjaxRequest) {
                 echo CJSON::encode(array('status' => 'Exito', 'div' => "Se agrego Comentario con exito."));
                 exit;
             } else {
                 $this->redirect(array('view', 'id' => $model->id));
             }
         }
     }
     if (Yii::app()->request->isAjaxRequest) {
         echo CJSON::encode(array('status' => 'failure', 'div' => $this->renderPartial('_form', array('model' => $model), true)));
         exit;
     } else {
         $this->render('create', array('model' => $model));
     }
 }
 public function postComment()
 {
     if (Request::ajax()) {
         $id = Input::get('id');
         $comentario = Input::get('comment');
         if (strlen($comentario) < 4) {
             return 'El comentario es muy corto';
         }
         $publication = Publicaciones::find($id);
         $comentarios = new Comentarios();
         $comentarios->user_id = Auth::id();
         $comentarios->pub_id = $id;
         $comentarios->comentario = $comentario;
         $comentarios->updated_at = date('Y-m-d', time());
         $comentarios->created_at = date('Y-m-d', time());
         $comentarios->save();
         $msg = "Han comentado tu publicacion: " . $publication->titulo;
         $user = User::find($publication->user_id);
         $data = array('message' => $msg, 'title' => $msg, 'msgcnt' => null, 'timeToLive' => 3000);
         $gcm = GcmDevices::where('user_id', '=', $user->id)->orderBy('id', 'DESC')->get(array('gcm_regid'));
         $regId = array();
         $i = 0;
         foreach ($gcm as $g) {
             $regId[$i] = $g['gcm_regid'];
             $i++;
         }
         $doGcm = new Gcm();
         $response = $doGcm->send_notification($regId, $data);
         return Response::json(array('type' => 'success', 'msg' => 'Comentario Guardado Sactisfactoriamente', 'date' => date('d-m-Y', strtotime($comentarios->created_at))));
     }
 }