Ejemplo n.º 1
0
 public function getLastPageAdded($idiom, $limit = 4)
 {
     $where = strtolower($idiom);
     $var_cache = 'lastFacebookPageAdded' . ucfirst($where) . $limit;
     if (!Cache::has($var_cache)) {
         $ranking = FacebookPage::take($limit)->orderBy('id_page', 'DESC');
         switch ($where) {
             case 'all':
                 $ranking->whereParent(0)->orWhereRaw('id_page = parent');
                 break;
             default:
                 $country_idiom = FacebookCountry::whereIdiom($where)->first();
                 if ($country_idiom) {
                     $ranking->whereIdiom($where)->where(function ($query) {
                         $query->whereParent(0)->orWhereRaw('id_page = parent');
                     });
                 } else {
                     return 'Invalid method';
                 }
         }
         $ranking = $ranking->get(['fb_id', 'username', 'name']);
         $pages = array();
         foreach ($ranking as $key => $value) {
             $cache = NULL;
             $cache['username'] = strtolower($value['username']);
             $cache['name'] = $value['name'];
             $cache['picture'] = 'https://graph.facebook.com/' . $value['fb_id'] . '/picture?type=large';
             $pages[] = $cache;
         }
         Cache::put($var_cache, $pages, 1440);
     }
     return Cache::get($var_cache);
 }
Ejemplo n.º 2
0
 public function getRankingPageGrow($idiom)
 {
     $where = ucfirst($idiom);
     $var_cache = 'rankingGrowLikes' . $where;
     if (!Cache::has($var_cache)) {
         $ranking = FacebookPage::take(4)->orderBy('likes_grow_30', 'DESC');
         switch ($where) {
             case 'All':
                 $ranking->whereParent(0)->orWhereRaw('id_page = parent');
                 break;
             case 'Es':
                 $ranking->whereIdiom('es')->whereParent(0)->orWhereRaw('id_page = parent');
                 break;
                 /*case 'It':
                   $ranking->whereIdiom('it')->whereParent(0)->orWhereRaw('id_page = parent');
                   break;*/
             /*case 'It':
               $ranking->whereIdiom('it')->whereParent(0)->orWhereRaw('id_page = parent');
               break;*/
             default:
                 return 'Invalid method';
         }
         $ranking = $ranking->get(['fb_id', 'username', 'name', 'likes', 'likes_grow_30']);
         $pages = array();
         foreach ($ranking as $key => $value) {
             $cache = NULL;
             $cache['username'] = strtolower($value['username']);
             $cache['name'] = $value['name'];
             $cache['picture'] = 'https://graph.facebook.com/' . $value['fb_id'] . '/picture?type=large';
             $cache['percent'] = 0;
             if ($value['likes'] - $value['likes_grow_30'] > 0) {
                 $cache['percent'] = $this->owlooFormatPorcent($value['likes_grow_30'], $value['likes'] - $value['likes_grow_30']);
             }
             $cache['grow_30'] = $this->owloo_number_format($value['likes_grow_30']);
             $pages[] = $cache;
         }
         Cache::put($var_cache, $pages, 1440);
     }
     return Cache::get($var_cache);
 }
Ejemplo n.º 3
0
 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;
 }