public function init() { parent::init(); // Get Content Container by Param if ($this->contentContainer->wall_id != "") { $this->criteria->condition .= " AND wall_entry.wall_id = " . $this->contentContainer->wall_id; //$this->criteria->condition .= " AND wall_entry.created_by=".$this->contentContainer->id; } else { file_put_contents("php://stderr", print_r("in else", TRUE)); Yii::log("No wall id for content container " . get_class($this->contentContainer) . " - " . $this->contentContainer->getPrimaryKey() . " set - stopped stream action!", CLogger::LEVEL_ERROR); $this->criteria->condition .= " AND 1=2"; } /** * Limit to public posts when no member */ //if (!$this->contentContainer->canAccessPrivateContent($this->user)) { // $this->criteria->condition .= " AND content.visibility=" . Content::VISIBILITY_PUBLIC; //} /** * Handle sticked posts only in content containers */ if ($this->limit != 1) { if ($this->from == '') { $this->criteria->order = "content.sticked DESC, " . $this->criteria->order; } else { $this->criteria->condition .= " AND (content.sticked != 1 OR content.sticked is NULL)"; } } }
public function init() { parent::init(); // Build subselect to create a list of user wall_ids $wallIdSelectCriteria = new CDbCriteria(); $wallIdSelectCriteria->select = 'wall_id'; if (Yii::app()->user->isGuest) { $wallIdSelectCriteria->condition = 'visibility=' . User::VISIBILITY_ALL; } $wallIdSelectSql = User::model()->getCommandBuilder()->createFindCommand(User::model()->getTableSchema(), $wallIdSelectCriteria)->getText(); $this->criteria->condition .= ' AND wall_entry.wall_id IN (' . $wallIdSelectSql . ')'; $this->criteria->condition .= " AND content.visibility=" . Content::VISIBILITY_PUBLIC; }
public function init() { parent::init(); if ($this->user == null) { /** * For guests collect all wall_ids of "guest" public spaces / user profiles. * Generally show only public content */ $publicSpacesSql = Yii::app()->db->createCommand()->select('si.wall_id')->from('space si')->where("si.visibility=" . Space::VISIBILITY_ALL)->getText(); $publicProfilesSql = Yii::app()->db->createCommand()->select('pi.wall_id')->from('user pi')->where("pi.status=1 AND pi.visibility=" . User::VISIBILITY_ALL)->getText(); $this->criteria->join .= ' LEFT JOIN wall ON wall.id = wall_entry.wall_id'; $this->criteria->condition .= ' AND (wall_entry.wall_id IN (' . $publicSpacesSql . ') OR wall_entry.wall_id IN (' . $publicProfilesSql . '))'; //$this->criteria->condition .= ' AND content.visibility=' . Content::VISIBILITY_PUBLIC; $this->criteria->condition .= ' AND wall.object_model="Space"'; $this->criteria->order = 'RAND()'; } else { /** * Collect all wall_ids we need to include into dashboard stream */ // User to user follows $userFollow = Yii::app()->db->createCommand()->select("uf.wall_id")->from('user_follow')->leftJoin('user uf', 'uf.id=user_follow.object_id AND user_follow.object_model="User"')->where('user_follow.user_id=' . $this->user->id . ' AND uf.wall_id IS NOT NULL')->getText(); // User to space follows $spaceFollow = Yii::app()->db->createCommand()->select("sf.wall_id")->from('user_follow')->leftJoin('space sf', 'sf.id=user_follow.object_id AND user_follow.object_model="Space"')->where('user_follow.user_id=' . $this->user->id . ' AND sf.wall_id IS NOT NULL')->getText(); // User to space memberships $spaceMemberships = Yii::app()->db->createCommand()->select("sm.wall_id")->from('space_membership')->leftJoin('space sm', 'sm.id=space_membership.space_id')->where('space_membership.user_id=' . $this->user->id . ' AND sm.wall_id IS NOT NULL')->getText(); // Glue together also with current users wall $wallIdsSql = Yii::app()->db->createCommand()->select('wall_id')->from('user uw')->where('uw.id=' . $this->user->id)->union($spaceMemberships)->union($spaceFollow)->union($userFollow)->getText(); $this->criteria->condition .= ' AND wall_entry.wall_id IN (' . $wallIdsSql . ')'; /** * Begin visibility checks regarding the content container */ // In case of an space entry, we need to join the space membership to verify the user can see private space content $this->criteria->join .= ' LEFT JOIN wall ON wall.id = wall_entry.wall_id'; $this->criteria->join .= ' LEFT JOIN space_membership ON wall.object_id = space_membership.space_id AND space_membership.user_id=:userId AND space_membership.status=' . SpaceMembership::STATUS_MEMBER; $this->criteria->condition .= ' AND ( '; $this->criteria->condition .= ' (wall.object_model="user" AND content.visibility=0 AND content.user_id = :userId) OR '; $this->criteria->condition .= ' (wall.object_model="space" AND content.visibility = 0 AND space_membership.status = ' . SpaceMembership::STATUS_MEMBER . ') OR '; $this->criteria->condition .= ' (content.visibility = 1 OR content.visibility IS NULL) '; $this->criteria->condition .= ' )'; $this->criteria->condition .= ' AND wall.object_model="Space"'; $this->criteria->order = 'RAND()'; } }
public function testLimit() { $baseStreamAction = new BaseStreamAction(Yii::app()->getController(), 'test'); $baseStreamAction->limit = 2; $baseStreamAction->init(); $wallEntries = $baseStreamAction->getWallEntries(); $wallEntryIds = array_map(create_function('$entry', 'return $entry->id;'), $wallEntries); $this->assertEquals(array_slice($this->postWallEntryIds, 0, 2), $wallEntryIds); }