function getInfo($slug)
 {
     $production = Production::where(Production::ATTR_SLUG, $slug)->get();
     if (count($production) == 0) {
         //Verifica en el log el slug
         if (is_null($id = Slug::getIdProduction($slug))) {
             return abort(404);
         } else {
             return redirect("production/" . Production::findOrNew($id)->slug);
         }
     }
     $production = $production[0];
     //Visitantes
     if (!Auth::check()) {
         return view("frontend/contents/production/play-forbbiden")->with("production", $production)->with("message", view("ui/msg/contents/info-production-login")->with("production", $production)->render());
     }
     $categories = $production->terms;
     $director = $production->staff()->count() > 0 ? $production->staff()->where(Person::ATTR_PIVOT_ROLE, Person::ROLE_DIRECTOR)->get()[0] : null;
     $staff = $production->staff()->count() > 0 ? $production->staff()->where(Person::ATTR_PIVOT_ROLE, Person::ROLE_ACTOR)->get() : null;
     $isVideoMain = $production->haveVideoMain() && $production->state == Production::STATE_ACTIVE;
     $chapters = $production->chapters;
     $rating_count = $production->ratings()->count();
     $rating = number_format($production->ratings()->avg('rating') * 100 / 5, 0);
     $userIsRated = ProductionRating::userIsRated($production->id);
     $inFav = Production::inFavorites($production->id);
     $view = view("frontend/contents/production/info")->with("production", $production)->with("categories", $categories)->with("staff", $staff)->with("director", $director)->with("isVideoMain", $isVideoMain)->with("chapters", $chapters)->with("rating", $rating)->with("rating_count", $rating_count)->with("userIsRated", $userIsRated)->with("inFav", $inFav);
     //Muestra un mensaje para indicarle al usuario que debe activar su cuenta
     if (Auth::user()->state == User::STATE_UNCONFIRMED_ACCOUNT) {
         Session::put(\App\System\Library\Complements\UI::modalMessage("¡ACTIVA TU CUENTA!", view("ui/msg/contents/activa-tu-cuenta")->render()));
     }
     return $view;
 }
Esempio n. 2
0
 /** Recibe una peticion ajax para agregar a favoritos una produccion (ajax/user/favorites/add/production)
  * 
  * @param Request $request
  * @return type
  */
 function ajax_addProductionToFavorites(Request $request)
 {
     if (!$request->ajax()) {
         return;
     }
     $data = $request->all();
     //Verifica si la produccion ya se encuentra en favoritos
     if (Production::inFavorites($data["production_id"])) {
         return json_encode(array(false));
     }
     Auth::user()->favorites()->attach($data["production_id"], array(User::ATTR_FAVORITES_PIVOT_DATE => DateUtil::getCurrentTime()));
     return json_encode(array(true));
 }