예제 #1
0
 public static function GetLocations($db, $options = array())
 {
     $defaults = array('post_id' => array());
     foreach ($defaults as $k => $v) {
         $options[$k] = array_key_exists($k, $options) ? $options[$k] : $v;
     }
     $select = $db->select();
     $select->from(array('l' => 'blog_posts_locations'), 'l.*');
     if (count($options['post_id']) > 0) {
         $select->where('l.post_id in (?)', $options['post_id']);
     }
     $data = $db->fetchAll($select);
     $locations = parent::BuildMultiple($db, __CLASS__, $data);
     return $locations;
 }
예제 #2
0
 public static function GetUsers($db, $options = array())
 {
     // initialize the options
     $defaults = array('offset' => 0, 'limit' => 0, 'order' => 'u.username');
     foreach ($defaults as $k => $v) {
         $options[$k] = array_key_exists($k, $options) ? $options[$k] : $v;
     }
     $select = self::_GetBaseQuery($db, $options);
     // set the fields to select
     $select->from(null, 'u.*');
     // set the offset, limit, and ordering of results
     if ($options['limit'] > 0) {
         $select->limit($options['limit'], $options['offset']);
     }
     $select->order($options['order']);
     // fetch user data from database
     $data = $db->fetchAll($select);
     // turn data into array of DatabaseObject_User objects
     $users = parent::BuildMultiple($db, __CLASS__, $data);
     if (count($users) == 0) {
         return $users;
     }
     $user_ids = array_keys($users);
     // load the profile data for loaded posts
     $profiles = Profile::BuildMultiple($db, 'Profile_User', array('user_id' => $user_ids));
     foreach ($users as $user_id => $user) {
         if (array_key_exists($user_id, $profiles) && $profiles[$user_id] instanceof Profile_User) {
             $users[$user_id]->profile = $profiles[$user_id];
         } else {
             $users[$user_id]->profile->setUserId($user_id);
         }
     }
     return $users;
 }