예제 #1
0
파일: mvc.php 프로젝트: Tapac/hotscot
/**
 * returns all avaliable ids for a specific model type
 *
 * @param string $model_name 
 * @return array
 * @author Craig Ulliott
 */
function get_model_ids($model_name)
{
    // build an empty of this model type
    $m = m($model_name);
    // query to get all the ids
    $result = DB::getArray('select `' . $m->getPrimaryKey() . '` from `' . $m->getDatabase() . '`.`' . $m->getTable() . '`');
    // simplify this nested array
    return array_suck($result);
}
예제 #2
0
 /**
  * Return an array of ids for users that are friends with the given user
  *
  * @param User $user
  * @return array
  */
 public static function getFriendIDs(UserModel $user)
 {
     // need a session user for this function
     if (!($session_user = self::$user)) {
         return array();
     }
     // build unique cache key (method, owner_id, viewer_id)
     $cache_key = self::buildCacheKey(__METHOD__, $user->getID(), $session_user->getID());
     // if friends data is already in the cache, return it straight away
     if ($friendIDs = Cache::get($cache_key)) {
         return $friendIDs;
     }
     // this will hold the friend ids
     $friendIDs = array();
     // this holds the FB profile data
     $fb_data = array();
     // we may need to hit FB twice for the friends list if the session is expired
     $results = self::tryAndRetry('_getFriends', array($user));
     // process results
     if ($results) {
         foreach ($results as $row) {
             // if we didnt get a name then skip it, user probably has privacy settings that make the data unineresting on the site
             if (isset($row['name']) && $row['name']) {
                 $fb_data[$row['uid']] = $row;
             }
         }
     }
     // if we found friends, find the friends with wib
     if ($fb_data) {
         // convert network ids to person ids and build the user objects
         $uids = array_keys($fb_data);
         $sql = 'SELECT personID FROM wib_person.facebook WHERE facebookID IN (' . implode(',', $uids) . ')';
         $rows = DB::getArray($sql, __LINE__, __FILE__);
         $friendIDs = array_suck($rows);
     }
     // if friendIDs data isn't empty, cache it
     if (!empty($friendIDs)) {
         Cache::add($cache_key, $friendIDs, 1, 1, FB_CACHE_DURATION);
     }
     return $friendIDs;
 }