Path: blob/master/src/applications/conpherence/controller/ConpherenceListController.php
12256 views
<?php12final class ConpherenceListController extends ConpherenceController {34const SELECTED_MODE = 'selected';5const UNSELECTED_MODE = 'unselected';67/**8* Two main modes of operation...9*10* 1 - /conpherence/ - UNSELECTED_MODE11* 2 - /conpherence/<id>/ - SELECTED_MODE12*13* UNSELECTED_MODE is not an Ajax request while the other two are Ajax14* requests.15*/16private function determineMode() {17$request = $this->getRequest();1819$mode = self::UNSELECTED_MODE;20if ($request->isAjax()) {21$mode = self::SELECTED_MODE;22}2324return $mode;25}2627public function shouldAllowPublic() {28return true;29}3031public function handleRequest(AphrontRequest $request) {32$user = $request->getUser();33$title = pht('Conpherence');34$conpherence = null;3536$limit = ConpherenceThreadListView::SEE_ALL_LIMIT + 1;37$all_participation = array();3839$mode = $this->determineMode();40switch ($mode) {41case self::SELECTED_MODE:42$conpherence_id = $request->getURIData('id');43$conpherence = id(new ConpherenceThreadQuery())44->setViewer($user)45->withIDs(array($conpherence_id))46->executeOne();47if (!$conpherence) {48return new Aphront404Response();49}50if ($conpherence->getTitle()) {51$title = $conpherence->getTitle();52}53$cursor = $conpherence->getParticipantIfExists($user->getPHID());54$data = $this->loadDefaultParticipation($limit);55$all_participation = $data['all_participation'];56if (!$cursor) {57$menu_participation = id(new ConpherenceParticipant())58->makeEphemeral()59->setConpherencePHID($conpherence->getPHID())60->setParticipantPHID($user->getPHID());61} else {62$menu_participation = $cursor;63}6465// check to see if the loaded conpherence is going to show up66// within the SEE_ALL_LIMIT amount of conpherences.67// If its not there, then we just pre-pend it as the "first"68// conpherence so folks have a navigation item in the menu.69$count = 0;70$found = false;71foreach ($all_participation as $phid => $curr_participation) {72if ($conpherence->getPHID() == $phid) {73$found = true;74break;75}76$count++;77if ($count > ConpherenceThreadListView::SEE_ALL_LIMIT) {78break;79}80}81if (!$found) {82$all_participation =83array($conpherence->getPHID() => $menu_participation) +84$all_participation;85}86break;87case self::UNSELECTED_MODE:88default:89$data = $this->loadDefaultParticipation($limit);90$all_participation = $data['all_participation'];91if ($all_participation) {92$conpherence_id = head($all_participation)->getConpherencePHID();93$conpherence = id(new ConpherenceThreadQuery())94->setViewer($user)95->withPHIDs(array($conpherence_id))96->needProfileImage(true)97->executeOne();98}99// If $conpherence is null, NUX state will render100break;101}102103$threads = $this->loadConpherenceThreadData($all_participation);104105$thread_view = id(new ConpherenceThreadListView())106->setUser($user)107->setBaseURI($this->getApplicationURI())108->setThreads($threads);109110switch ($mode) {111case self::SELECTED_MODE:112$response = id(new AphrontAjaxResponse())->setContent($thread_view);113break;114case self::UNSELECTED_MODE:115default:116$layout = id(new ConpherenceLayoutView())117->setUser($user)118->setBaseURI($this->getApplicationURI())119->setThreadView($thread_view)120->setRole('list');121if ($conpherence) {122$layout->setThread($conpherence);123} else {124// make a dummy conpherence so we can render something125$conpherence = ConpherenceThread::initializeNewRoom($user);126$conpherence->attachHandles(array());127$conpherence->attachTransactions(array());128$conpherence->makeEphemeral();129}130$policy_objects = id(new PhabricatorPolicyQuery())131->setViewer($user)132->setObject($conpherence)133->execute();134$layout->setHeader($this->buildHeaderPaneContent(135$conpherence,136$policy_objects));137$response = $this->newPage()138->setTitle($title)139->appendChild($layout);140break;141}142143return $response;144145}146147private function loadDefaultParticipation($limit) {148$viewer = $this->getRequest()->getUser();149150$all_participation = id(new ConpherenceParticipantQuery())151->withParticipantPHIDs(array($viewer->getPHID()))152->setLimit($limit)153->execute();154$all_participation = mpull($all_participation, null, 'getConpherencePHID');155156return array(157'all_participation' => $all_participation,158);159}160161private function loadConpherenceThreadData($participation) {162$user = $this->getRequest()->getUser();163$conpherence_phids = array_keys($participation);164$conpherences = array();165if ($conpherence_phids) {166$conpherences = id(new ConpherenceThreadQuery())167->setViewer($user)168->withPHIDs($conpherence_phids)169->needProfileImage(true)170->execute();171172// this will re-sort by participation data173$conpherences = array_select_keys($conpherences, $conpherence_phids);174}175176return $conpherences;177}178179}180181182