Exemple #1
0
 public static function GetPosts($db, $options = array())
 {
     $defaults = array('offset' => 0, 'limit' => 0, 'order' => 'p.ts_created');
     foreach ($defaults as $k => $v) {
         $options[$k] = array_key_exists($k, $options) ? $options[$k] : $v;
     }
     $select = self::_GetBaseQuery($db, $options);
     $select->from(null, 'p.*');
     if ($options['limit'] > 0) {
         $select->limit($options['limit'], $options['offset']);
     }
     $select->order($options['order']);
     $data = $db->fetchAll($select);
     $posts = self::BuildMultiple($db, __CLASS__, $data);
     $post_ids = array_keys($posts);
     if (count($post_ids) == 0) {
         return array();
     }
     $profiles = Profile::BuildMultiple($db, 'Profile_BlogPost', array('post_id' => $post_ids));
     foreach ($posts as $post_id => $post) {
         if (array_key_exists($post_id, $profiles) && $profiles[$post_id] instanceof Profile_BlogPost) {
             $posts[$post_id]->profile = $profiles[$post_id];
         } else {
             $posts[$post_id]->profile->setPostId($post_id);
         }
     }
     $options = array('post_id' => $post_ids);
     $images = DatabaseObject_BlogPostImage::GetImages($db, $options);
     foreach ($images as $image) {
         $posts[$image->post_id]->images[$image->getId()] = $image;
     }
     $locations = DatabaseObject_BlogPostLocation::GetLocations($db, $options);
     foreach ($locations as $l) {
         $posts[$l->post_id]->locations[$l->getId()] = $l;
     }
     return $posts;
 }