static function fromNoticeInbox($user_id)
 {
     $ids = array();
     $ni = new Notice_inbox();
     $ni->user_id = $user_id;
     $ni->selectAdd();
     $ni->selectAdd('notice_id');
     $ni->orderBy('notice_id DESC');
     $ni->limit(0, self::MAX_NOTICES);
     if ($ni->find()) {
         while ($ni->fetch()) {
             $ids[] = $ni->notice_id;
         }
     }
     $ni->free();
     unset($ni);
     $inbox = new Inbox();
     $inbox->user_id = $user_id;
     $inbox->pack($ids);
     $inbox->fake = true;
     return $inbox;
 }
Beispiel #2
0
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");
}