public static function get_total_feeds($data = array()) { $user = Acl::instance()->relevant_user(); if (!$user) { $user = Auth::instance()->get_user(); } // TODO the streams for the current user can be cached $user_streams = Model_Feedstream::user_streams(null, Arr::get($data, 'course_id')); $streams = $user_streams->as_array(null, 'id'); if (!$streams) { return array(); } $feed = ORM::factory('feed')->join('feeds_feedstreams')->on('feeds.id', ' = ', 'feeds_feedstreams.feed_id')->where('feedstream_id', ' IN ', $streams); return $feed->count_all(); }
/** * Method to save the streams to be associated to the feed * @param array $data */ public function streams($data) { if (!empty($data['user_id']) && is_array($data['user_id'])) { // multiple user ids passed $users = $data['user_id']; foreach ($users as $user_id) { $this->_streams[] = Model_Feedstream::create_if_not_exists(array('user_id' => $user_id)); } } elseif (!empty($data['role_id']) && is_array($data['role_id'])) { // if multiple role_ids passed $roles = $data['role_id']; foreach ($roles as $role_id) { $this->_streams[] = Model_Feedstream::create_if_not_exists(array_merge($data, array('role_id' => $role_id))); } } else { // create only one stream with whatever data passed including user_id and role_id $this->_streams[] = Model_Feedstream::create_if_not_exists($data); } return $this; }