Exemplo n.º 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);
 }
Exemplo n.º 2
0
 public function getCityDetails($id_city)
 {
     $var_cache = 'facebookCityDetails' . $id_city;
     if (!Cache::has($var_cache)) {
         $value = FacebookCity::whereIdCity($id_city)->first();
         if (!$value) {
             return 'Invalid method';
         }
         $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']));
         //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']));
         }
         Cache::put($var_cache, $cache, 1440);
     }
     return Cache::get($var_cache);
 }