function getProductions($slug) { $category = Term::where(Term::ATTR_SLUG, $slug)->get()[0]; //Obtiene la cantidad total de producciones asociadas a la categoria $cant = Term::findOrNew($category->id)->productions()->count(); return view("frontend/contents/production/category")->with("category", $category)->with("cant", $cant); }
function ajax_getProductionsByCategory(Request $request) { if (!$request->ajax()) { return json_encode(array()); } $data = $request->all(); $cat_id = $data["category_id"]; $skip = $data["skip"]; $filtered = isset($data["filtered"]) && $data["filtered"] == "true" ? true : false; $productions = $filtered ? Term::findOrNew($cat_id)->productions()->where(Production::ATTR_STATE, Production::STATE_ACTIVE)->orderBy("state", "ASC")->skip($skip)->take(72)->groupBy("id")->get() : Term::findOrNew($cat_id)->productions()->orderBy("state", "ASC")->skip($skip)->take(72)->groupBy("id")->get(); $response = array(); if ($skip == 0) { $total_productions = $filtered ? Term::findOrNew($cat_id)->productions()->where(Production::ATTR_STATE, Production::STATE_ACTIVE)->count() : Term::findOrNew($cat_id)->productions()->count(); } foreach ($productions as $production) { $data_production = array("html" => Production::getVisualHtml($production)); if ($skip == 0) { $data_production["total"] = $total_productions; } $response[] = $data_production; } if (count($productions) == 0) { $response[] = array("total" => 0); } return json_encode($response); }