public function getEditPub()
 {
     $title = "Editar publicidad | pasillo24.com";
     $publi = Publicidad::get();
     return View::make('admin.editPublicidad')->with('title', $title)->with('publi', $publi);
 }
 public function showIndex($id = null)
 {
     if (!is_null($id)) {
         $dep = Department::find($id);
     }
     $title = "Inicio | pasillo24.com";
     if (!is_null($id)) {
         $lider = Publicaciones::join('usuario', 'usuario.id', '=', 'publicaciones.user_id')->where('publicaciones.status', '=', 'Aprobado')->where('publicaciones.ubicacion', '=', 'Principal')->where('publicaciones.tipo', '=', 'Lider')->where('publicaciones.pag_web', '!=', "")->where('publicaciones.fechFin', '>=', date('Y-m-d', time()))->where('publicaciones.deleted', '=', 0)->orderBy('publicaciones.fechFin', 'desc')->get($this->toReturn);
         $habitual = Publicaciones::join('usuario', 'usuario.id', '=', 'publicaciones.user_id')->where(function ($query) use($id) {
             /*Busco las habituales*/
             $query->where('publicaciones.tipo', '=', 'Habitual')->where(function ($query) {
                 /*Que vayan en la principal*/
                 $query->where('publicaciones.ubicacion', '=', 'Principal')->orWhere('publicaciones.ubicacion', '=', 'Ambos')->where('publicaciones.status', '=', 'Aprobado');
             })->where(function ($query) {
                 /*y que sigan activas*/
                 $query->where('publicaciones.fechFin', '>=', date('Y-m-d', time()))->where('publicaciones.status', '=', 'Aprobado');
             })->where('publicaciones.departamento', '=', $id);
         })->where('publicaciones.deleted', '=', 0)->orWhere(function ($query) use($id) {
             $query->where('publicaciones.tipo', '=', 'Lider')->where('publicaciones.ubicacion', '=', 'Principal')->where('publicaciones.pag_web', '=', "")->where('publicaciones.status', '=', 'Aprobado')->where('publicaciones.departamento', '=', $id);
         })->orderBy('publicaciones.fechFin', 'desc')->get($this->toReturn);
         $casual = Publicaciones::join('usuario', 'usuario.id', '=', 'publicaciones.user_id')->where('publicaciones.tipo', '=', 'Casual')->where('publicaciones.fechFin', '>=', date('Y-m-d', time()))->where('publicaciones.status', '=', 'Aprobado')->where('publicaciones.departamento', '=', $id)->where('publicaciones.deleted', '=', 0)->get($this->toReturn);
     } else {
         $lider = Publicaciones::join('usuario', 'usuario.id', '=', 'publicaciones.user_id')->where('publicaciones.status', '=', 'Aprobado')->where('publicaciones.ubicacion', '=', 'Principal')->where('publicaciones.tipo', '=', 'Lider')->where('publicaciones.pag_web', '!=', "")->where('publicaciones.fechFin', '>=', date('Y-m-d', time()))->where('publicaciones.deleted', '=', 0)->orderBy('publicaciones.fechFin', 'desc')->get($this->toReturn);
         $habitual = Publicaciones::join('usuario', 'usuario.id', '=', 'publicaciones.user_id')->where(function ($query) {
             /*Busco las habituales*/
             $query->where('publicaciones.tipo', '=', 'Habitual')->where(function ($query) {
                 /*Que vayan en la principal*/
                 $query->where('publicaciones.ubicacion', '=', 'Principal')->orWhere('publicaciones.ubicacion', '=', 'Ambos')->where('publicaciones.status', '=', 'Aprobado');
             })->where(function ($query) {
                 /*y que sigan activas*/
                 $query->where('publicaciones.fechFin', '>=', date('Y-m-d', time()))->where('publicaciones.status', '=', 'Aprobado');
             });
         })->where('publicaciones.deleted', '=', 0)->orWhere(function ($query) {
             $query->where('publicaciones.tipo', '=', 'Lider')->where('publicaciones.ubicacion', '=', 'Principal')->where('publicaciones.pag_web', '=', "")->where('publicaciones.status', '=', 'Aprobado');
         })->orderBy('publicaciones.fechFin', 'desc')->get($this->toReturn);
         $casual = Publicaciones::join('usuario', 'usuario.id', '=', 'publicaciones.user_id')->where('publicaciones.tipo', '=', 'Casual')->where('publicaciones.fechFin', '>=', date('Y-m-d', time()))->where('publicaciones.status', '=', 'Aprobado')->where('publicaciones.deleted', '=', 0)->get($this->toReturn);
     }
     $categories = Categorias::where('deleted', '=', 0)->where('tipo', '=', 1)->orderBy('nombre')->get();
     $otros = new StdClass();
     foreach ($categories as $c) {
         if (strtolower($c->nombre) == 'otros') {
             $otros->id = $c->id;
             $otros->nombre = $c->nombre;
         }
     }
     if (!isset($otros->id)) {
         $otros->id = '1000';
         $otros->nombre = 'Otros';
     }
     $servicios = Categorias::where('deleted', '=', 0)->where('tipo', '=', 2)->orderBy('nombre')->get();
     $otros2 = new StdClass();
     foreach ($servicios as $c) {
         if (strtolower($c->nombre) == 'otros') {
             $otros2->id = $c->id;
             $otros2->nombre = $c->nombre;
         }
     }
     if (!isset($otros2->id)) {
         $otros2->id = '1000';
         $otros2->nombre = 'Otros';
     }
     $departamentos = Department::get();
     $publi = Publicidad::get();
     if (!is_null($id)) {
         return Response::json(array('pubLider' => $lider, 'pubHabitual' => $habitual, 'pubCasual' => $casual, 'categorias' => $categories, 'servicios' => $servicios, 'departamentos' => $departamentos, 'publi' => $publi, 'depFilter' => $dep->id));
     } else {
         return Response::json(array('pubLider' => $lider, 'pubHabitual' => $habitual, 'pubCasual' => $casual, 'categorias' => $categories, 'servicios' => $servicios, 'departamentos' => $departamentos, 'publi' => $publi));
     }
 }
 public function showIndex($id = null)
 {
     if (!is_null($id)) {
         $dep = Department::find($id);
     }
     $title = "Inicio | pasillo24.com";
     if (!is_null($id)) {
         $lider = Publicaciones::where('status', '=', 'Aprobado')->where('ubicacion', '=', 'Principal')->where('tipo', '=', 'Lider')->where('publicaciones.pag_web', '!=', "")->where('fechFin', '>=', date('Y-m-d', time()))->where('publicaciones.deleted', '=', 0)->orderBy('fechFin', 'desc')->get(array('publicaciones.img_1', 'publicaciones.titulo', 'publicaciones.precio', 'publicaciones.moneda', 'publicaciones.id'));
         $habitual = Publicaciones::where(function ($query) use($id) {
             /*Busco las habituales*/
             $query->where('tipo', '=', 'Habitual')->where(function ($query) {
                 /*Que vayan en la principal*/
                 $query->where('ubicacion', '=', 'Principal')->orWhere('ubicacion', '=', 'Ambos')->where('status', '=', 'Aprobado');
             })->where(function ($query) {
                 /*y que sigan activas*/
                 $query->where('fechFin', '>=', date('Y-m-d', time()))->where('status', '=', 'Aprobado');
             })->where('departamento', '=', $id);
         })->where('deleted', '=', 0)->orWhere(function ($query) use($id) {
             $query->where('tipo', '=', 'Lider')->where('ubicacion', '=', 'Principal')->where('pag_web', '=', "")->where('status', '=', 'Aprobado')->where('departamento', '=', $id);
         })->orderBy('fechFin', 'desc')->get();
         $casual = Publicaciones::where('tipo', '=', 'Casual')->where('fechFin', '>=', date('Y-m-d', time()))->where('status', '=', 'Aprobado')->where('departamento', '=', $id)->where('deleted', '=', 0)->get();
     } else {
         $lider = Publicaciones::where('status', '=', 'Aprobado')->where('ubicacion', '=', 'Principal')->where('tipo', '=', 'Lider')->where('pag_web', '!=', "")->where('fechFin', '>=', date('Y-m-d', time()))->where('deleted', '=', 0)->orderBy('fechFin', 'desc')->get();
         $habitual = Publicaciones::where(function ($query) {
             /*Busco las habituales*/
             $query->where('tipo', '=', 'Habitual')->where(function ($query) {
                 /*Que vayan en la principal*/
                 $query->where('ubicacion', '=', 'Principal')->orWhere('ubicacion', '=', 'Ambos')->where('status', '=', 'Aprobado');
             })->where(function ($query) {
                 /*y que sigan activas*/
                 $query->where('fechFin', '>=', date('Y-m-d', time()))->where('status', '=', 'Aprobado');
             });
         })->orWhere(function ($query) {
             $query->where('tipo', '=', 'Lider')->where('ubicacion', '=', 'Principal')->where('pag_web', '=', "")->where('status', '=', 'Aprobado');
         })->where('deleted', '=', 0)->orderBy('fechFin', 'desc')->get();
         $casual = Publicaciones::where('tipo', '=', 'Casual')->where('fechFin', '>=', date('Y-m-d', time()))->where('status', '=', 'Aprobado')->where('deleted', '=', 0)->get();
     }
     $categories = Categorias::where('deleted', '=', 0)->where('tipo', '=', 1)->orderBy('nombre')->get();
     $otros = new StdClass();
     foreach ($categories as $c) {
         if (strtolower($c->nombre) == 'otros') {
             $otros->id = $c->id;
             $otros->nombre = $c->nombre;
         }
     }
     if (!isset($otros->id)) {
         $otros->id = '1000';
         $otros->nombre = 'Otros';
     }
     $servicios = Categorias::where('deleted', '=', 0)->where('tipo', '=', 2)->orderBy('nombre')->get();
     $otros2 = new StdClass();
     foreach ($servicios as $c) {
         if (strtolower($c->nombre) == 'otros') {
             $otros2->id = $c->id;
             $otros2->nombre = $c->nombre;
         }
     }
     if (!isset($otros2->id)) {
         $otros2->id = '1000';
         $otros2->nombre = 'Otros';
     }
     $departamentos = Department::get();
     $publi = Publicidad::get();
     if (!is_null($id)) {
         return View::make('index')->with('title', $title)->with('publi', $publi)->with('lider', $lider)->with('categories', $categories)->with('departamentos', $departamentos)->with('habitual', $habitual)->with('casual', $casual)->with('otros', $otros)->with('otros2', $otros2)->with('servicios', $servicios)->with('depFilter', $dep->id);
     } else {
         return View::make('index')->with('title', $title)->with('publi', $publi)->with('lider', $lider)->with('categories', $categories)->with('departamentos', $departamentos)->with('habitual', $habitual)->with('casual', $casual)->with('otros', $otros)->with('otros2', $otros2)->with('servicios', $servicios);
     }
 }