Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Select limited stories where they are less than the given timestamp
- *
- * @param int $limit
- * @param int $timestamp
- * @param Mongo_ID $category
- * @return array
- */
- public function select_stories($limit, $timestamp, $category = null)
- {
- $where = array('timestamp' => array('$lt' => $timestamp), 'status' => 1);
- if(!is_null($category))
- {
- $where += array('category_id' => $category);
- }
- $stories = $this->find($where)->sort(array('timestamp' => '-1'))->limit($limit);
- return $this->build_stories_data($stories);
- }
- public function build_stories_data($stories)
- {
- $tags = $data = $categories = $users = $domains = array();
- $count = 0;
- foreach($stories as $row)
- {
- $data[$count] = $row;
- $data[$count]['tags'] = array();
- /* Build story tags */
- foreach($row['tags'] as $tag)
- {
- $tag_key = (string) $tag;
- if(!isset($tags[$tag_key]))
- {
- $tags[$tag_key] = \Tag::instance()->get(array('_id' => $tag), array('tag', 'link'));
- }
- $data[$count]['tags'][] = $tags[$tag_key];
- }
- /* Build Category */
- $category = (string) $row['category_id'];
- if(!isset($categories[$category]))
- {
- $categories[$category] = \Category::instance()->get(array('_id' => $row['category_id']), array('category', 'link'));
- }
- $data[$count]['category'] = $categories[(string) $row['category_id']];
- /* Build user */
- $user = (string) $row['user_id'];
- if(!isset($users[$user]))
- {
- $users[$user] = \User::instance()->get(array('_id' => $row['user_id']), array('username', 'username_link'));
- }
- /* Build domain */
- $domain = (string) $row['domain_id'];
- if(!isset($domains[$domain]))
- {
- $domains[$domain] = \Domain::instance()->get(array('_id' => $row['domain_id']), array('domain', 'link'));
- }
- $data[$count]['domain'] = $domains[$domain];
- /* Build Votes */
- if(!isset($row['votes']))
- {
- $data[$count]['votes'] = array(
- 'ratio' => 0
- );
- }
- $count++;
- }
- return $data;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement