public function postResponse()
 {
     $input = Input::all();
     $rules = array('id' => 'required|numeric', 'respuesta' => 'required', 'pub_id' => 'required|numeric');
     $validator = Validator::make($input, $rules);
     if ($validator->fails()) {
         return Response::json(array('type' => 'danger', 'msg' => 'Debe enviar un mensaje.'));
     }
     $com = Comentarios::find($input['id']);
     if ($com->respondido == 1) {
         return Response::json(array('type' => 'danger', 'msg' => 'El comantario ya fue respondido.'));
     }
     if ($com->deleted == 1) {
         $com->deleted = 0;
     }
     $resp = new Respuestas();
     $resp->comentario_id = $input['id'];
     $resp->respuesta = $input['respuesta'];
     $resp->pub_id = $input['pub_id'];
     $resp->user_id = $com->user_id;
     $resp->created_at = date('Y-m-d', time());
     $resp->updated_at = date('Y-m-d', time());
     $user = User::find($resp->user_id);
     $to_Email = $user->email;
     $subject = "han respondido tu comentario";
     $data = array('email' => $to_Email);
     Mail::send('emails.respuesta', $data, function ($message) use($to_Email, $subject) {
         $message->to($to_Email)->from('*****@*****.**')->subject($subject);
     });
     if ($resp->save()) {
         $com->respondido = 1;
         $com->save();
         $msg = "Han respondido tu comentario: " . $com->comentario;
         $data = array('message' => $msg, 'title' => $msg, 'msgcnt' => null, 'timeToLive' => 3000);
         /*$gcm = GcmDevices::where('usuario','=',$user->username)->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' => 'Respuesta guardada satisfactoriamente'));
     } else {
         return Response::json(array('type' => 'danger', 'msg' => 'Error al guardar la respuesta'));
     }
     return Response::json($input);
 }
Ejemplo n.º 2
0
 public function postElimCommentrecividos()
 {
     $comment_id = Input::get('comment_id');
     $comment = Comentarios::find($comment_id);
     $comment->respondido = 1;
     if ($comment->save()) {
         return Response::json(array('type' => 'success', 'msg' => 'Comentario marcado como respondido sactisfactoriamente.'));
     } else {
         return Response::json(array('type' => 'danger', 'msg' => 'Error al marcar el comentario.'));
     }
 }