private function searchAccountInDB($username, $social_network) { switch ($social_network) { case 'facebook': $data = FacebookPage::whereUsername($username)->first(['fb_id', 'username', 'name']); break; case 'twitter': $data = TwitterProfile::whereScreenName($username)->first(['screen_name', 'name', 'picture']); break; case 'instagram': $data = InstagramProfile::whereUsername($username)->first(['username', 'name', 'picture']); break; default: return 'Invalid method'; break; } if ($data) { $page['username'] = strtolower(isset($data['username']) ? $data['username'] : $data['screen_name']); $page['name'] = !empty($data['name']) ? $data['name'] : $page['username']; $page['picture'] = $social_network == 'facebook' ? 'http://graph.facebook.com/' . $data['fb_id'] . '/picture?height=200&type=normal&width=200' : str_replace('_normal.', '_200x200.', $data['picture']); return $page; } else { return NULL; } }
public function getTotalProfile($idiom) { switch ($idiom) { case 'world': if (!Cache::has('totalWorldTwitterProfiles')) { $data = TwitterProfile::whereOwlooUserStatus('1')->count(); Cache::put('totalWorldTwitterProfiles', $data, 1440); } return Cache::get('totalWorldTwitterProfiles'); break; case 'hispanic': if (!Cache::has('totalHispanicTwitterProfiles')) { $data = TwitterProfile::whereOwlooUserStatus('1')->count(); Cache::put('totalHispanicTwitterProfiles', $data, 1440); } return Cache::get('totalHispanicTwitterProfiles'); break; } return 'Invalid method'; }
public function getLastProfileAdded($idiom, $limit = 4) { $idiom = ucfirst($idiom); $var_cache = 'lastTwitterProfileAdded' . $idiom . $limit; if (!Cache::has($var_cache)) { $ranking = TwitterProfile::take($limit)->orderBy('id', 'DESC'); switch ($idiom) { case 'All': break; default: $country_idiom = FacebookCountry::whereIdiom(strtolower($idiom))->first(); if ($country_idiom) { $ranking->whereIdiom(strtolower($idiom)); } else { return 'Invalid method'; } } $ranking = $ranking->get(['screen_name', 'name', 'picture']); $pages = array(); foreach ($ranking as $key => $value) { $cache = NULL; $cache['screen_name'] = strtolower($value['screen_name']); $cache['name'] = $value['name']; $cache['picture'] = str_replace('_normal.', '.', $value['picture']); $pages[] = $cache; } Cache::put($var_cache, $pages, 1440); } return Cache::get($var_cache); }
public function getRankingProfileGrow($idiom) { $idiom = ucfirst($idiom); $var_cache = 'rankingGrowTwitterProfile' . $idiom; if (!Cache::has($var_cache)) { $ranking = TwitterProfile::take(4)->orderBy('followers_grow_30', 'DESC'); switch ($idiom) { case 'All': break; case 'Es': $ranking->whereIdiom('es'); break; /*case 'It': $ranking->whereIdiom('it')->whereParent(0); break;*/ /*case 'It': $ranking->whereIdiom('it')->whereParent(0); break;*/ default: return 'Invalid method'; } $ranking = $ranking->get(['screen_name', 'name', 'picture', 'followers_count', 'followers_grow_30']); $pages = array(); foreach ($ranking as $key => $value) { $cache = NULL; $cache['screen_name'] = strtolower($value['screen_name']); $cache['name'] = $value['name']; $cache['picture'] = str_replace('_normal.', '.', $value['picture']); $cache['percent'] = 0; if ($value['followers_count'] - $value['followers_grow_30'] > 0) { $cache['percent'] = $this->owlooFormatPorcent($value['followers_grow_30'], $value['followers_count'] - $value['followers_grow_30']); } $cache['grow_30'] = $this->owloo_number_format($value['followers_grow_30']); $pages[] = $cache; } Cache::put($var_cache, $pages, 1440); } return Cache::get($var_cache); }
public function testUserProfile() { $user = $this->buildUser(); $github = new GithubProfile(); $github->setName('Felipe Pimenta'); $github->setLogin('felipe'); $github->setEmail('*****@*****.**'); $github->setAvatar('felipe.png'); $facebook = new FacebookProfile(); $facebook->setName('Felipe Pimenta'); $facebook->setLogin('felipe'); $facebook->setEmail('*****@*****.**'); $facebook->setAvatar('felipe.png'); $twitter = new TwitterProfile(); $twitter->setName('Felipe Pimenta'); $twitter->setLogin('felipe'); $twitter->setEmail('*****@*****.**'); $twitter->setAvatar('felipe.png'); $profileCollection = new ArrayCollection(); $profileCollection->add($github); $profileCollection->add($facebook); $profileCollection->add($twitter); $user->setProfileCollection($profileCollection); $this->getEntityManager()->persist($user); $this->getEntityManager()->flush(); $savedUser = $this->getEntityManager()->find(get_class($user), 1); $this->assertEquals(3, count($savedUser->getProfileCollection())); $savedProfiles = $savedUser->getProfileCollection(); $this->assertInstanceOf(get_class($github), $savedProfiles[0]); $this->assertInstanceOf(get_class($facebook), $savedProfiles[1]); $this->assertInstanceOf(get_class($twitter), $savedProfiles[2]); }