Beispiel #1
0
 /**
  * Get newsfeed item as HTML
  *
  * @param   Model_NewsfeedItem  $item
  * @return  string
  */
 public static function get(Model_NewsfeedItem $item)
 {
     $link = $item->is_aggregate() ? implode('<br>', self::get_links($item)) : self::get_link($item);
     if (!$link) {
         return '';
     }
     $text = '';
     switch ($item->type) {
         case self::TYPE_COMMENT:
             $text = $item->is_aggregate() ? __('commented photos') : __('commented a photo');
             break;
         case self::TYPE_COMMENT_FLYER:
             $text = $item->is_aggregate() ? __('commented flyers') : __('commented a flyer');
             break;
         case self::TYPE_FLYER_EDIT:
             $text = $item->is_aggregate() ? __('updated flyers') : __('updated a flyer');
             break;
         case self::TYPE_NOTE:
             $user = Model_User::find_user($item->data['user_id']);
             if ($link && $user->loaded()) {
                 $text = __('tagged :user to a photo', array(':user' => HTML::user($user)));
             }
             break;
         case self::TYPE_UPLOAD:
             $text = __('added new photos to a gallery');
             break;
     }
     return $text . '<br />' . $link;
 }
Beispiel #2
0
 /**
  * Find Newsfeed items.
  *
  * @static
  * @param   integer  $limit
  * @param   array    $users  User ids
  * @return  Database_Result
  */
 public static function find_items($limit = 20, array $users = null)
 {
     $newsfeeditem = new Model_NewsfeedItem();
     $query = DB::select_array($newsfeeditem->fields())->order_by('id', 'DESC');
     if (is_array($users)) {
         $query = $query->where('user_id', 'IN', $users);
     }
     return $newsfeeditem->load($query, $limit);
 }
Beispiel #3
0
 /**
  * Add a Newsfeed item.
  *
  * @static
  * @param   Model_User  $user
  * @param   string      $class  e.g. 'user'
  * @param   string      $type   e.g. 'login'
  * @param   array       $data   Data to be user with item
  * @return  boolean
  */
 protected static function add(Model_User $user, $class, $type, array $data = null)
 {
     $item = new Model_NewsfeedItem();
     // Update item if previous added less than time window specified time
     $update = DB::update($item->get_table_name())->set(array('stamp' => time()))->where('user_id', '=', $user->id)->and_where('class', '=', $class)->and_where('type', '=', $type)->and_where('stamp', '>', strtotime(Newsfeed::UPDATE_WINDOW));
     $data ? $update->and_where('data', '=', @json_encode($data)) : $update->and_where('data', 'IS', null);
     // Update any?
     if ($update->execute()) {
         return true;
     }
     // No new enough item found, insert
     $item->set_fields(array('user_id' => $user->id, 'class' => $class, 'type' => $type, 'data' => $data, 'stamp' => time()));
     $item->save();
     return $item->loaded();
 }
Beispiel #4
0
 /**
  * Find Newsfeed items.
  *
  * @static
  * @param   integer  $limit
  * @param   array    $users  User ids
  * @return  Model_NewsfeedItem[]
  */
 public static function find_items($limit = 20, array $users = null)
 {
     $newsfeeditem = new Model_NewsfeedItem();
     $query = DB::select_array($newsfeeditem->fields())->order_by('stamp', 'DESC');
     if (is_array($users)) {
         $query = $query->where('user_id', 'IN', $users);
         // Include friend events
         $friend_ids = array();
         foreach ($users as $user_id) {
             $friend_ids[] = json_encode(array('friend_id' => $user_id));
         }
         $query = $query->or_where_open()->where('class', '=', 'user')->and_where('type', '=', 'friend')->and_where('data', 'IN', $friend_ids)->or_where_close();
     }
     return $newsfeeditem->load($query, $limit);
 }
Beispiel #5
0
 /**
  * Get newsfeed item as HTML
  *
  * @param   Model_NewsfeedItem  $item
  * @return  string
  */
 public static function get(Model_NewsfeedItem $item)
 {
     $link = $item->is_aggregate() ? implode('<br>', self::get_links($item)) : self::get_link($item);
     if (!$link) {
         return '';
     }
     $text = '';
     switch ($item->type) {
         case self::TYPE_COMMENT:
             $text = $item->is_aggregate() ? __('commented to blogs') : __('commented to a blog');
             break;
         case self::TYPE_ENTRY:
             $text = $item->is_aggregate() ? __('wrote new blog entries') : __('wrote a new blog entry');
             break;
     }
     return $text . '<br>' . $link;
 }
Beispiel #6
0
 /**
  * Get newsfeed item as HTML
  *
  * @param   Model_NewsfeedItem  $item
  * @return  string
  */
 public static function get(Model_NewsfeedItem $item)
 {
     $link = $item->is_aggregate() ? implode('<br>', self::get_links($item)) : self::get_link($item);
     if (!$link) {
         return '';
     }
     $text = '';
     switch ($item->type) {
         case self::TYPE_MIX:
             $text = $item->is_aggregate() ? __('added new mixtapes') : __('added a new mixtape');
             break;
         case self::TYPE_TRACK:
             $text = $item->is_aggregate() ? __('added new tracks') : __('added a new track');
             break;
     }
     return $text . '<br>' . $link;
 }
Beispiel #7
0
 /**
  * Load newsfeed items
  *
  * @return  boolean
  */
 protected function _find_items()
 {
     if (empty($this->_items)) {
         $this->_items = $this->_personal ? Model_NewsfeedItem::find_items_personal($this->_user, $this->max_items) : Model_NewsfeedItem::find_items($this->max_items);
     }
 }
Beispiel #8
0
 /**
  * Load newsfeed items
  *
  * @return  Database_Result
  */
 protected function get_items()
 {
     if (empty($this->_items)) {
         switch ($this->_type) {
             // Personal newsfeed
             case self::PERSONAL:
                 $this->_items = Model_NewsfeedItem::find_items($this->max_items, $this->_user ? array($this->_user->id) : null);
                 break;
                 // Multiple user newsfeed
             // Multiple user newsfeed
             case self::USERS:
                 $this->_items = empty($this->users) ? array() : Model_NewsfeedItem::find_items($this->max_items, $this->users);
                 break;
                 // All users
             // All users
             case self::ALL:
             default:
                 $this->_items = Model_NewsfeedItem::find_items($this->max_items);
                 break;
         }
     }
     return $this->_items;
 }
Beispiel #9
0
 /**
  * Load newsfeed items.
  *
  * @return  Model_NewsfeedItem[]
  */
 protected function get_items()
 {
     if (empty($this->_items)) {
         switch ($this->_type) {
             // Personal newsfeed
             case self::PERSONAL:
                 $this->_items = array();
                 foreach (Model_NewsfeedItem::find_items($this->max_items, $this->_user ? array($this->_user->id) : null) as $item) {
                     $this->_items[] = $item;
                 }
                 break;
                 // Multiple user newsfeed
             // Multiple user newsfeed
             case self::USERS:
                 $this->_items = $this->aggregate(empty($this->users) ? array() : Model_NewsfeedItem::find_items($this->max_items * 2, $this->users));
                 break;
                 // All users
             // All users
             case self::ALL:
             default:
                 $this->_items = $this->aggregate(Model_NewsfeedItem::find_items($this->max_items * 2));
                 break;
         }
     }
     return count($this->_items) > $this->max_items ? array_slice($this->_items, 0, $this->max_items) : $this->_items;
 }