Пример #1
0
 public function getRankingRegion($country, $page)
 {
     $var_cache = 'rankingRegions_' . $country . '_' . ($page - 1) * 20;
     if (!Cache::has($var_cache)) {
         $ranking = FacebookRegion::take(20)->skip(($page - 1) * 20)->orderBy('total_user', 'DESC');
         if ($country != 'world') {
             $ranking = $ranking->whereCountryCode($country);
         }
         $ranking = $ranking->get(['id_region', 'name', 'country_code', 'total_user', 'total_female', 'total_male', 'grow_90']);
         $cities = array();
         foreach ($ranking as $key => $value) {
             $cache = NULL;
             $cache['position'] = ($page - 1) * 20 + $key + 1;
             $cache['name'] = $value['name'];
             $cache['total_user'] = $this->owloo_number_format($value['total_user']);
             $cache['total_female'] = array('value' => $this->owloo_number_format($value['total_female']), 'percent' => $this->owlooFormatPorcent($value['total_female'], $value['total_user']));
             $cache['total_male'] = array('value' => $this->owloo_number_format($value['total_male']), 'percent' => $this->owlooFormatPorcent($value['total_male'], $value['total_user']));
             $cache['grow_90'] = $this->formatGrow($value['grow_90'], $value['total_user']);
             $data_country = FacebookCountry::whereCode($value['country_code'])->first(['name_en']);
             $cache['country_code'] = strtolower($value['country_code']);
             $cache['country_url_name'] = $this->convert_string_to_url($data_country['name_en']);
             if (false) {
                 //if ($country != 'world') {
                 /***** Ages *****/
                 $cache['ages']['items'] = array();
                 $ages = FacebookCityAge::whereIdCity($value['id_city'])->orderBy('total_user', 'DESC')->take(5)->get(['name', 'total_user']);
                 foreach ($ages as $age) {
                     $cache['ages']['items'][] = array('name' => $age['name'], 'total_user' => $this->owloo_number_format($age['total_user']));
                 }
                 //Get max value
                 $cache['ages']['max_user'] = array();
                 $age_max_total = FacebookCityAge::whereIdCity($value['id_city'])->orderBy('total_user', 'DESC')->orderBy('id', 'ASC')->first(['name', 'total_user']);
                 if (isset($age_max_total['name'])) {
                     $cache['ages']['max_user'] = array('name' => $age_max_total['name'], 'value' => $this->owloo_number_format($age_max_total['total_user']), 'percent' => $this->owlooFormatPorcent($age_max_total['total_user'], $value['total_user']));
                 }
                 /***** Relationships *****/
                 $cache['relationships']['items'] = array();
                 $relationships = FacebookCityRelationship::whereIdCity($value['id_city'])->orderBy('total_user', 'DESC')->take(5)->get(['name', 'total_user']);
                 foreach ($relationships as $relationship) {
                     $cache['relationships']['items'][] = array('name' => $relationship['name'], 'total_user' => $this->owloo_number_format($relationship['total_user']));
                 }
                 /***** Interests *****/
                 $cache['interests']['items'] = array();
                 $interests = FacebookCityInterest::whereIdCity($value['id_city'])->orderBy('total_user', 'DESC')->take(5)->get(['name', 'total_user']);
                 foreach ($interests as $interest) {
                     $cache['interests']['items'][] = array('name' => $interest['name'], 'total_user' => $this->owloo_number_format($interest['total_user']));
                 }
                 //Get the Trend-up
                 $cache['interests']['trend_up'] = array();
                 $interest_grow = FacebookCityInterest::whereIdCity($value['id_city'])->orderBy('grow_30', 'DESC')->orderBy('total_user', 'DESC')->first(['name', 'total_user', 'grow_30']);
                 if (isset($interest_grow['name']) && $interest_grow['grow_30'] > 0) {
                     $cache['interests']['trend_up'] = array('name' => $interest_grow['name'], 'grow' => $this->formatGrow($interest_grow['grow_30'], $interest_grow['total_user']));
                 }
                 /***** Comportamientos *****/
                 $cache['comportamientos']['items'] = array();
                 $comportamientos = FacebookCityComportamiento::whereIdCity($value['id_city'])->orderBy('total_user', 'DESC')->take(5)->get(['name', 'total_user']);
                 foreach ($comportamientos as $comportamiento) {
                     $cache['comportamientos']['items'][] = array('name' => $comportamiento['name'], 'percent' => $this->owlooFormatPorcent($comportamiento['total_user'], $value['total_user']));
                 }
             }
             $cities[] = $cache;
         }
         Cache::put($var_cache, $cities, 1440);
     }
     return Cache::get($var_cache);
 }
Пример #2
0
 public function getRankingRegion($country, $page)
 {
     $country = ucfirst($country);
     $var_cache = 'rankingRegions_' . $country . '_' . ($page - 1) * 20;
     if (!Cache::has($var_cache)) {
         $ranking = FacebookRegion::take(20)->skip(($page - 1) * 20)->orderBy('total_user', 'DESC');
         switch ($country) {
             case 'World':
                 break;
             case 'Hispanic':
                 $ranking->whereIdiom('es');
                 break;
             default:
                 $country_idiom = FacebookCountry::whereIdiom(strtolower($country))->first();
                 if ($country_idiom) {
                     $ranking->whereIdiom(strtolower($country));
                 } else {
                     $country_search = FacebookCountry::whereCode(FacebookCountry::whereSlug($country)->first(['code'])->code)->first();
                     if ($country_search) {
                         $ranking->whereCountryCode($country_search->code);
                     } else {
                         return 'Invalid method';
                     }
                 }
         }
         $ranking = $ranking->get(['id_region', 'name', 'country_code', 'total_user', 'total_female', 'total_male', 'grow_90']);
         $regions = array();
         foreach ($ranking as $key => $value) {
             $cache = NULL;
             $cache['position'] = ($page - 1) * 20 + $key + 1;
             $cache['id'] = $value['id_region'];
             $cache['name'] = $value['name'];
             $data_country = FacebookCountry::whereCode($value['country_code'])->first(['slug']);
             $cache['country_code'] = strtolower($value['country_code']);
             $cache['country_slug'] = $data_country['slug'];
             //Mes
             $aux_num = $this->formatGrow($value['grow_90'], $value['total_user']);
             $cache['second_column'][] = array('value' => $aux_num['value'], 'class' => $aux_num['class']);
             //Total usuarios
             $cache['second_column'][] = array('value' => $this->owloo_number_format($value['total_user']), 'class' => '');
             $regions[] = $cache;
         }
         $second_column = array('País', 'Mes', 'Total usuarios');
         $array_result = array('type' => 'fb_country', 'subtype' => 'fb_region', 'main_column' => 'Region', 'second_column' => $second_column, 'large_column' => 4, 'link' => 'facebook-stats/regions', 'items' => $regions);
         Cache::put($var_cache, $array_result, 1440);
     }
     return Cache::get($var_cache);
 }