public function getRankingPageDev($where, $category, $page = 1) { $where = ucfirst($where); if (!Cache::has('rankingLikes' . $where . 'PageCat' . $category . '_' . ($page - 1) * 20)) { if ($where != 'World' && $where != 'Hispanic') { $ranking = FacebookPageLocalFans::take(20)->skip(($page - 1) * 20)->orderBy('likes_local_fans', 'DESC')->orderBy('likes', 'DESC'); } else { $ranking = FacebookPage::take(20)->skip(($page - 1) * 20)->orderBy('likes', 'DESC')->orderBy('talking_about', 'DESC'); } switch ($where) { case 'World': $ranking->whereParent(0); break; case 'Hispanic': $ranking->whereIdiom('es')->whereParent(0); break; default: if (FacebookPage::whereCode(strtolower($where))) { $ranking->where('country_code', strtoupper($where)); } else { return 'Invalid method'; } } if ($category != 'all' && is_numeric($category)) { $ranking->where('Category_id', $category); } if ($where != 'World' && $where != 'Hispanic') { $ranking = $ranking->get(['fb_id', 'username', 'name', 'is_verified', 'likes', 'likes_grow_7', 'talking_about', 'likes_local_fans']); } else { $ranking = $ranking->get(['fb_id', 'username', 'name', 'is_verified', 'likes', 'likes_grow_7', 'talking_about', 'country_code', 'first_country_code']); } foreach ($ranking as $key => $value) { $cache = NULL; $cache['position'] = ($page - 1) * 20 + $key + 1; $cache['username'] = strtolower($value['username']); $cache['name'] = $value['name']; $cache['picture'] = 'http://graph.facebook.com/' . $value['fb_id'] . '/picture?height=50&type=normal&width=50'; $cache['is_verified'] = $value['is_verified']; $cache['likes'] = $this->owloo_number_format($value['likes']); $cache['grow_7'] = $value['likes_grow_7']; $cache['pta'] = 0; if ($value['likes'] > 0) { $cache['pta'] = $this->owlooFormatPorcent($value['talking_about'], $value['likes']); } if ($where != 'World' && $where != 'Hispanic') { $cache['likes_local_fans'] = $this->owloo_number_format($value['likes_local_fans']); } else { $cache['country'] = strtolower(!empty($value['country_code']) ? $value['country_code'] : $value['first_country_code']); } $var = 'rankingLikes' . $where . 'PageCat' . $category . '_' . (($page - 1) * 20 + $key); Cache::put($var, $cache, 1440); } } $from = ($page - 1) * 20; $to = $page * 20 - 1; $foo = array(); for ($from; $from <= $to; $from++) { $var = 'rankingLikes' . $where . 'PageCat' . $category . '_' . $from; $foo[$from] = Cache::get($var); } return $foo; }