function getNotices() { $notice = new Notice(); $notice->joinAdd(array('id', 'file_to_post:post_id')); $notice->whereAdd(sprintf('file_to_post.file_id = %d', $this->out->attachment->id)); $notice->orderBy('created desc'); $notice->selectAdd('post_id as id'); $notice->find(); return $notice; }
function getNotices() { $notice = new Notice(); $f2p = new File_to_post(); $f2p->file_id = $this->out->attachment->id; $notice->joinAdd($f2p); $notice->orderBy('created desc'); $notice->selectAdd('post_id as id'); $notice->find(); return $notice; }
function initInbox() { printfnq("Ensuring all users have an inbox..."); $user = new User(); $user->whereAdd('not exists (select user_id from inbox where user_id = user.id)'); $user->orderBy('id'); if ($user->find()) { while ($user->fetch()) { try { $notice = new Notice(); $notice->selectAdd(); $notice->selectAdd('id'); $notice->joinAdd(array('profile_id', 'subscription:subscribed')); $notice->whereAdd('subscription.subscriber = ' . $user->id); $notice->whereAdd('notice.created >= subscription.created'); $ids = array(); if ($notice->find()) { while ($notice->fetch()) { $ids[] = $notice->id; } } $notice = null; $inbox = new Inbox(); $inbox->user_id = $user->id; $inbox->pack($ids); $inbox->insert(); } catch (Exception $e) { printv("Error initializing inbox: " . $e->getMessage()); } } } printfnq("DONE.\n"); }
/** * Query notices by users associated with this tag from the database. * * @param integer $offset offset * @param integer $limit maximum no of results * @param integer $since_id=null since this id * @param integer $max_id=null maximum id in result * * @return array array of notice ids. */ function getNoticeIds($offset, $limit, $since_id, $max_id) { $notice = new Notice(); $notice->selectAdd(); $notice->selectAdd('notice.id'); $ptag = new Profile_tag(); $ptag->tag = $this->profile_list->tag; $ptag->tagger = $this->profile_list->tagger; $notice->joinAdd(array('profile_id', 'profile_tag:tagged')); $notice->whereAdd('profile_tag.tagger = ' . $this->profile_list->tagger); $notice->whereAdd(sprintf('profile_tag.tag = "%s"', $this->profile_list->tag)); if ($since_id != 0) { $notice->whereAdd('notice.id > ' . $since_id); } if ($max_id != 0) { $notice->whereAdd('notice.id <= ' . $max_id); } $notice->orderBy('notice.id DESC'); if (!is_null($offset)) { $notice->limit($offset, $limit); } $ids = array(); if ($notice->find()) { while ($notice->fetch()) { $ids[] = $notice->id; } } return $ids; }