/** * Executes show action * */ public function executeShow() { $request = $this->getRequest(); // get params $chatId = $request->getParameter('id'); $userId = $this->getUser()->getRaykuUserId(); // chat query & check access $criteria = new Criteria(); $criteria->add(WhiteboardChatPeer::ID, $chatId); if (!$this->getUser()->hasCredential('admin')) { $cPublicA = $criteria->getNewCriterion(WhiteboardChatPeer::IS_PUBLIC, true); $cPublicB = $criteria->getNewCriterion(WhiteboardChatPeer::EXPERT_ID, $userId); $cPublicC = $criteria->getNewCriterion(WhiteboardChatPeer::ASKER_ID, $userId); $cPublicA->addOr($cPublicB); $cPublicA->addOr($cPublicC); $criteria->add($cPublicA); } $chat = WhiteboardChatPeer::doSelectOne($criteria); $this->forward404Unless($chat); // messages query $msgCriteria = new Criteria(); $msgCriteria->add(WhiteboardMessagePeer::WHITEBOARD_CHAT_ID, $chatId); $msgCriteria->addAscendingOrderByColumn(WhiteboardMessagePeer::CREATED_AT); $messages = WhiteboardMessagePeer::doSelect($msgCriteria); // snapshots query $snapCriteria = new Criteria(); $snapCriteria->add(WhiteboardSnapshotPeer::WHITEBOARD_CHAT_ID, $chatId); $snapCriteria->addAscendingOrderByColumn(WhiteboardSnapshotPeer::CREATED_AT); $snapshots = WhiteboardSnapshotPeer::doSelect($snapCriteria); // assign variables to view $this->chat = $chat; $this->messages = $messages; $this->snapshots = $snapshots; }
/** * Gets an array of WhiteboardMessage objects which contain a foreign key that references this object. * * If this collection has already been initialized with an identical Criteria, it returns the collection. * Otherwise if this WhiteboardChat has previously been saved, it will retrieve * related WhiteboardMessages from storage. If this WhiteboardChat is new, it will return * an empty collection or the current collection, the criteria is ignored on a new object. * * @param PropelPDO $con * @param Criteria $criteria * @return array WhiteboardMessage[] * @throws PropelException */ public function getWhiteboardMessages($criteria = null, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(WhiteboardChatPeer::DATABASE_NAME); } elseif ($criteria instanceof Criteria) { $criteria = clone $criteria; } if ($this->collWhiteboardMessages === null) { if ($this->isNew()) { $this->collWhiteboardMessages = array(); } else { $criteria->add(WhiteboardMessagePeer::WHITEBOARD_CHAT_ID, $this->id); WhiteboardMessagePeer::addSelectColumns($criteria); $this->collWhiteboardMessages = WhiteboardMessagePeer::doSelect($criteria, $con); } } else { // criteria has no effect for a new object if (!$this->isNew()) { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. $criteria->add(WhiteboardMessagePeer::WHITEBOARD_CHAT_ID, $this->id); WhiteboardMessagePeer::addSelectColumns($criteria); if (!isset($this->lastWhiteboardMessageCriteria) || !$this->lastWhiteboardMessageCriteria->equals($criteria)) { $this->collWhiteboardMessages = WhiteboardMessagePeer::doSelect($criteria, $con); } } } $this->lastWhiteboardMessageCriteria = $criteria; return $this->collWhiteboardMessages; }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(WhiteboardMessagePeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(WhiteboardMessagePeer::DATABASE_NAME); $criteria->add(WhiteboardMessagePeer::ID, $pks, Criteria::IN); $objs = WhiteboardMessagePeer::doSelect($criteria, $con); } return $objs; }