. * * @category UI * @package StatusNet * @author Evan Prodromou * @author Sarven Capadisli * @copyright 2008 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } require_once INSTALLDIR.'/lib/favorform.php'; require_once INSTALLDIR.'/lib/disfavorform.php'; require_once INSTALLDIR.'/lib/attachmentlist.php'; /** * widget for displaying a list of notices * * There are a number of actions that display a list of notices, in * reverse chronological order. This widget abstracts out most of the * code for UI for notice lists. It's overridden to hide some * data for e.g. the profile page. * * @category UI * @package StatusNet * @author Evan Prodromou * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ * @see Notice * @see NoticeListItem * @see ProfileNoticeList */ class NoticeList extends Widget { /** the current stream of notices being displayed. */ var $notice = null; /** * constructor * * @param Notice $notice stream of notices from DB_DataObject */ function __construct($notice, $out=null) { parent::__construct($out); $this->notice = $notice; } /** * show the list of notices * * "Uses up" the stream by looping through it. So, probably can't * be called twice on the same list. * * @return int count of notices listed. */ function show() { $this->out->elementStart('div', array('id' =>'notices_primary')); $this->out->elementStart('ol', array('class' => 'notices xoxo')); $notices = $this->notice->fetchAll(); $total = count($notices); $notices = array_slice($notices, 0, NOTICES_PER_PAGE); self::prefill($notices); foreach ($notices as $notice) { try { $item = $this->newListItem($notice); $item->show(); } catch (Exception $e) { // we log exceptions and continue common_log(LOG_ERR, $e->getMessage()); continue; } } $this->out->elementEnd('ol'); $this->out->elementEnd('div'); return $total; } /** * returns a new list item for the current notice * * Recipe (factory?) method; overridden by sub-classes to give * a different list item class. * * @param Notice $notice the current notice * * @return NoticeListItem a list item for displaying the notice */ function newListItem($notice) { return new NoticeListItem($notice, $this->out); } static function prefill(&$notices, $avatarSize=AVATAR_STREAM_SIZE) { // Prefill attachments Notice::fillAttachments($notices); // Prefill attachments Notice::fillFaves($notices); // Prefill the profiles $profiles = Notice::fillProfiles($notices); // Prefill the avatars Profile::fillAvatars($profiles, $avatarSize); $p = Profile::current(); $ids = array(); foreach ($notices as $notice) { $ids[] = $notice->id; } if (!empty($p)) { Memcached_DataObject::pivotGet('Fave', 'notice_id', $ids, array('user_id' => $p->id)); } } }