Пример #1
0
 public function testGetRankingSuccess()
 {
     $user_id = $this->_user_id;
     $_params = $this->_params;
     $_params['user_id'] = $user_id;
     $response = $this->_getAuth($_params);
     //get created login information
     $page = 1;
     $limit = 10;
     $user = Profile::orderBy('rate_count', 'desc')->forPage($page, $limit)->get();
     if (count($user) != 0) {
         foreach ($user as $users) {
             $follow = Follow::where('from_id', $user_id)->where('to_id', $users->user_id)->first();
             if ($follow) {
                 $users->is_follow = true;
             } else {
                 if ($users->user_id != $user_id) {
                     $users->is_follow = false;
                 }
             }
             if ($users->image != null) {
                 $users->image = URL::asset($users->image);
             }
         }
     }
     $this->assertNotNull($user);
     $this->assertEquals(array("code" => ApiResponse::OK, "data" => $user->toArray()), json_decode($response->getContent(), true));
 }
Пример #2
0
 public function testGetProfileBasicSuccessOtherUser()
 {
     $user_id = $this->_user_id;
     $other_user = User::where('email', '*****@*****.**')->first()->user_id;
     $response = $this->action('GET', 'ProfileController@get_profile_basic_user', array('user_id' => $other_user));
     $profile = Profile::where('user_id', $other_user)->first();
     if (User::where('user_id', $other_user)->first()) {
         $users = Profile::orderBy('rate_count', 'desc')->get();
         $i = 0;
         if ($users) {
             foreach ($users as $key) {
                 $i++;
                 if ($key['user_id'] == $other_user) {
                     break;
                 }
             }
         }
     }
     $profile->user_ranking = $i;
     if ($profile->image != null) {
         $profile->image = URL::asset($profile->image);
     }
     $wishlist = Wishlist::where('user_id', $user_id)->get();
     $profile->wishlist_count = count($wishlist);
     $follow = Follow::where('from_id', $user_id)->where('to_id', $other_user)->first();
     if ($follow) {
         $profile->is_follow = true;
     } else {
         $profile->is_follow = false;
     }
     $data = $profile;
     $this->assertEquals(array("code" => ApiResponse::OK, "data" => $data->toArray()), json_decode($response->getContent(), true));
 }
Пример #3
0
 /**
  * Get profiles tagged with this people tag,
  * include modified timestamp as a "cursor" field
  * order by descending order of modified time
  *
  * @param integer $offset   offset
  * @param integer $limit    maximum no of results
  * @param integer $since_id=null    since unix timestamp
  * @param integer $upto=null  maximum unix timestamp when subscription was made
  *
  * @return Profile results
  */
 function getTagged($offset = 0, $limit = null, $since = 0, $upto = 0)
 {
     $tagged = new Profile();
     $tagged->joinAdd(array('id', 'profile_tag:tagged'));
     #@fixme: postgres
     $tagged->selectAdd('unix_timestamp(profile_tag.modified) as "cursor"');
     $tagged->whereAdd('profile_tag.tagger = ' . $this->tagger);
     $tagged->whereAdd("profile_tag.tag = '{$this->tag}'");
     if ($since != 0) {
         $tagged->whereAdd('cursor > ' . $since);
     }
     if ($upto != 0) {
         $tagged->whereAdd('cursor <= ' . $upto);
     }
     if ($limit != null) {
         $tagged->limit($offset, $limit);
     }
     $tagged->orderBy('profile_tag.modified DESC');
     $tagged->find();
     return $tagged;
 }
Пример #4
0
 public static function getProfileBasicUser($user_id)
 {
     $error_code = ApiResponse::OK;
     $user_login = Session::get('user_id');
     if (User::where('user_id', $user_id)->first()) {
         $users = Profile::orderBy('rate_count', 'desc')->get();
         $i = 0;
         if ($users) {
             foreach ($users as $key) {
                 $i++;
                 if ($key['user_id'] == $user_id) {
                     break;
                 }
             }
         }
         $profile = Profile::where('user_id', $user_id)->first();
         if ($profile->image != null) {
             $profile->image = URL::asset($profile->image);
         }
         if ($profile->country_id != null) {
             $country = Country::where('id', $profile->country_id)->first();
             $profile->country_name = $country->country_name;
             $profile->country_flag = URL::asset($country->flag_url);
         }
         $wishlists = Wishlist::where('user_id', $user_id)->get();
         if ($wishlists) {
             $profile->wishlist_count = count($wishlists);
         } else {
             $profile->wishlist_count = 0;
         }
         if ($user_id != $user_login) {
             $follow = Follow::where('from_id', $user_login)->where('to_id', $user_id)->first();
             if ($follow) {
                 $profile->is_follow = true;
             } else {
                 $profile->is_follow = false;
             }
         }
         $profile->user_ranking = $i;
         $data = $profile->toArray();
     } else {
         $error_code = ApiResponse::UNAVAILABLE_USER;
         $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_USER);
     }
     return array("code" => $error_code, "data" => $data);
 }
Пример #5
0
 function showContent()
 {
     // XXX: Note I'm doing it this two-stage way because a raw query
     // with a JOIN was *not* working. --Zach
     $featured_nicks = common_config('nickname', 'featured');
     if (count($featured_nicks) > 0) {
         $quoted = array();
         foreach ($featured_nicks as $nick) {
             $quoted[] = "'{$nick}'";
         }
         $user = new User();
         $user->whereAdd(sprintf('nickname IN (%s)', implode(',', $quoted)));
         $user->limit(($this->page - 1) * PROFILES_PER_PAGE, PROFILES_PER_PAGE + 1);
         $user->orderBy(common_database_tablename('user') . '.nickname ASC');
         $user->find();
         $profile_ids = array();
         while ($user->fetch()) {
             $profile_ids[] = $user->id;
         }
         $profile = new Profile();
         $profile->whereAdd(sprintf('profile.id IN (%s)', implode(',', $profile_ids)));
         $profile->orderBy('nickname ASC');
         $cnt = $profile->find();
         if ($cnt > 0) {
             $featured = new ProfileList($profile, $this);
             $featured->show();
         }
         $profile->free();
         $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE, $this->page, 'featured');
     }
 }
Пример #6
0
 function getUsers()
 {
     $profile = new Profile();
     // Comment this out or disable to get global profile searches
     $profile->joinAdd(array('id', 'user:id'));
     $offset = ($this->page - 1) * PROFILES_PER_PAGE;
     $limit = PROFILES_PER_PAGE + 1;
     if (!empty($this->q)) {
         // User is searching via query
         $search_engine = $profile->getSearchEngine('profile');
         $mode = 'reverse_chron';
         if ($this->sort == 'nickname') {
             if ($this->reverse) {
                 $mode = 'nickname_desc';
             } else {
                 $mode = 'nickname_asc';
             }
         } else {
             if ($this->reverse) {
                 $mode = 'chron';
             }
         }
         $search_engine->set_sort_mode($mode);
         $search_engine->limit($offset, $limit);
         $search_engine->query($this->q);
         $profile->find();
     } else {
         // User is browsing via AlphaNav
         switch ($this->filter) {
             case 'all':
                 // NOOP
                 break;
             case '0-9':
                 $profile->whereAdd(sprintf('LEFT(%1$s.%2$s, 1) BETWEEN %3$s AND %4$s', $profile->escapedTableName(), 'nickname', $profile->_quote("0"), $profile->_quote("9")));
                 break;
             default:
                 $profile->whereAdd(sprintf('LEFT(LOWER(%1$s.%2$s), 1) = %3$s', $profile->escapedTableName(), 'nickname', $profile->_quote($this->filter)));
         }
         $order = sprintf('%1$s.%2$s %3$s, %1$s.%4$s ASC', $profile->escapedTableName(), $this->getSortKey('nickname'), $this->reverse ? 'DESC' : 'ASC', 'nickname');
         $profile->orderBy($order);
         $profile->limit($offset, $limit);
         $profile->find();
     }
     return $profile;
 }
Пример #7
0
 public static function ranking()
 {
     $user_id = Session::get('user_id');
     $error_code = ApiResponse::OK;
     $data = array();
     $pagination = ApiResponse::pagination();
     if ($pagination == false) {
         $error_code = ApiResponse::URL_NOT_EXIST;
         $data = ApiResponse::getErrorContent(ApiResponse::URL_NOT_EXIST);
     } else {
         $page = $pagination['page'];
         $limit = $pagination['limit'];
         $users = Profile::orderBy('rate_count', 'desc')->forPage($page, $limit)->get();
         if (count($users) != 0) {
             foreach ($users as $user) {
                 $follow = Follow::where('from_id', $user_id)->where('to_id', $user->user_id)->first();
                 if ($follow) {
                     $user->is_follow = true;
                 } else {
                     if ($user->user_id != $user_id) {
                         $user->is_follow = false;
                     }
                 }
                 if ($user->image != null) {
                     $user->image = URL::asset($user->image);
                 }
             }
             $data = $users->toArray();
         }
     }
     return array("code" => $error_code, "data" => $data);
 }
Пример #8
0
 /**
  * Get pending subscribers, who have not yet been approved.
  *
  * @param int $offset
  * @param int $limit
  * @return Profile
  */
 function getRequests($offset = 0, $limit = null)
 {
     // FIXME: mysql only
     $subqueue = new Profile();
     $subqueue->joinAdd(array('id', 'subscription_queue:subscriber'));
     $subqueue->whereAdd(sprintf('subscription_queue.subscribed = %d', $this->getID()));
     $subqueue->limit($offset, $limit);
     $subqueue->orderBy('subscription_queue.created', 'DESC');
     if (!$subqueue->find()) {
         throw new NoResultException($subqueue);
     }
     return $subqueue;
 }
Пример #9
0
 function getBlocked($offset = null, $limit = null)
 {
     $blocked = new Profile();
     $blocked->joinAdd(array('id', 'group_block:blocked'));
     $blocked->whereAdd(sprintf('group_block.group_id = %u', $this->id));
     $blocked->orderBy('group_block.modified DESC');
     $blocked->limit($offset, $limit);
     $blocked->find();
     return $blocked;
 }