/** * Display a listing of the resource. * GET /eventos * * @return Response */ public function index() { $eventos = Eventos::where('fecha_ini', '>=', Carbon::today())->orderby("fecha_ini", "asc")->orderby("tiempo_ini", "asc")->get(); $eventos->each(function ($evento) { $evento = array_add($evento, 'duracion', traducir_fecha(Carbon::parse($evento->fecha_ini . $evento->tiempo_ini)->diffForHumans(Carbon::parse($evento->fecha_fin . $evento->tiempo_fin)), true)); $evento['inicio'] = traducir_fecha(Carbon::parse($evento->fecha_ini . $evento->tiempo_ini)->toDayDateTimeString()); $evento['fin'] = traducir_fecha(Carbon::parse($evento->fecha_fin . $evento->tiempo_fin)->toDayDateTimeString()); foreach ($evento->areas() as $area) { $evento->area .= $area->nombre . ","; } }); return Response::json($eventos, 200); }
public function Calendar($action) { if (isset($action)) { if ($action == "create") { $evento = Eventos::firstOrCreate(Input::all()); foreach ($evento->areas() as $area) { $evento->area .= $area->nombre . ","; } return $respuesta = array('Record' => $evento, 'Result' => "OK"); } if ($action == "edit") { $evento = Eventos::find(Input::get("id")); $evento->fill(Input::all()); $evento->save(); foreach ($evento->areas() as $area) { $evento->area .= $area->nombre . ","; } return $respuesta = array('Record' => $evento, 'Result' => "OK"); } if ($action == "remove") { Eventos::where('id', Input::get("id"))->delete(); return '{"Result":"OK"}'; } if ($action == "list") { $Records = Eventos::get(); $Records->each(function ($evento) { foreach ($evento->areas() as $area) { $evento->area .= $area->nombre . ","; } }); $respuesta = array('Records' => $Records, 'Result' => "OK"); return json_encode($respuesta); } if ($action == "areas") { $nulos = DB::table('areas')->select(DB::raw("'Ninguna' as DisplayText,'null' as value")); $respuesta = Areas::select("nombre as DisplayText", "id as Value")->union($nulos)->orderby('value', 'asc')->distinct()->get(); return "var opciones=" . json_encode($respuesta); } } }
public function verfullcalendar() { $proximos = Eventos::where('fecha_ini', '>=', Carbon::today())->take(10)->orderby('fecha_ini', 'asc')->orderby('tiempo_ini', 'asc')->get(); $eventos = Eventos::select('razon as title', DB::raw('CONCAT(fecha_ini,"T",tiempo_ini) as start'), DB::raw('CONCAT(fecha_fin,"T",tiempo_fin) as end'))->get(); return View::make('vercalendario')->withEventos($eventos->toJson())->withProximos($proximos); }