예제 #1
0
 public function ingresoNoticia()
 {
     /**INGRESO **/
     $token = Input::get('token');
     if (isset($token)) {
         $data = array('titulos' => Input::get('t'), 'contenidos' => Input::get('c'), 'fuentes' => Input::get('f'), 'periodo' => Input::get('p'), 'finalizar' => Input::get('finalizar'), 'autor' => Input::get('autor'), 'enlace' => Input::get('enlace'), 'responsable' => Input::get('i'), 'especial' => Input::get('especial'), 'tipo' => Input::get('tipo'));
         $validaciones = array('titulos' => array('required'));
         $validator = Validator::make($data, $validaciones);
         if ($validator->fails()) {
             $respuesta;
             $mensajes = $validator->messages();
             foreach ($mensajes->all() as $mensaje) {
                 $respuesta = $mensaje;
             }
             $response = array('status' => 'ERRORV', 'message' => $respuesta);
         } else {
             $format = "Y-m-d H:i:s";
             $timestamp = time();
             $fecha = date($format, $timestamp);
             if ($data['especial'] == 1) {
                 $isAsi = AsignacionesController::consultaGetResponsablePeriodoFuente(null, $data['responsable'], $data['fuentes']);
             } else {
                 $isAsi = AsignacionesController::consultaGetResponsablePeriodoFuente($data['periodo'], $data['responsable'], $data['fuentes']);
             }
             $idConPerF = $isAsi[0];
             $idAsignacion = $idConPerF['asiId'];
             $sinInfo = NoticiasController::verificaSinInfo($idAsignacion);
             if (count($sinInfo) > 0) {
                 $response = array('status' => 'ERROR', 'message' => 'Ya se tiene registrada la fuente seleccionada como "Sin Publicación" o "Sin Información relevante" para el día de hoy.');
             } else {
                 $insert = Noticias::insert(array('notTitulo' => trim($data['titulos']), 'notContenido' => trim($data['contenidos']), 'notFecha' => $fecha, 'notAsignaciones' => $idAsignacion, 'notFinalizar' => $data['finalizar'], 'notAutor' => $data['autor'], 'notEnlace' => $data['enlace'], 'notTipo' => $data['tipo']));
                 //  $insert=1;
                 if ($insert) {
                     $response = array('status' => 'OK', 'data' => $sinInfo, 'message' => 'Noticia agregado correctamente.');
                 } else {
                     $response = array('status' => 'ERROR', 'message' => 'No se pudo agregar la noticia, intente de nuevo');
                 }
             }
         }
     } else {
         $response = array('status' => 'ERROR', 'message' => 'Vuelva a intentar en un momento');
     }
     return Response::json($response);
 }