2013-01-25 02:23:05 +01:00
|
|
|
<?php
|
|
|
|
|
2014-07-10 00:12:48 +02:00
|
|
|
final class ConpherenceListController extends ConpherenceController {
|
2013-01-25 02:23:05 +01:00
|
|
|
|
2013-04-26 19:30:41 +02:00
|
|
|
const SELECTED_MODE = 'selected';
|
|
|
|
const UNSELECTED_MODE = 'unselected';
|
|
|
|
|
|
|
|
/**
|
2015-03-31 21:45:32 +02:00
|
|
|
* Two main modes of operation...
|
2013-04-26 19:30:41 +02:00
|
|
|
*
|
|
|
|
* 1 - /conpherence/ - UNSELECTED_MODE
|
|
|
|
* 2 - /conpherence/<id>/ - SELECTED_MODE
|
|
|
|
*
|
|
|
|
* UNSELECTED_MODE is not an Ajax request while the other two are Ajax
|
|
|
|
* requests.
|
|
|
|
*/
|
|
|
|
private function determineMode() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
$mode = self::UNSELECTED_MODE;
|
|
|
|
if ($request->isAjax()) {
|
2015-03-31 21:45:32 +02:00
|
|
|
$mode = self::SELECTED_MODE;
|
2013-04-26 19:30:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $mode;
|
|
|
|
}
|
2015-03-27 00:37:32 +01:00
|
|
|
|
2015-05-08 23:59:11 +02:00
|
|
|
public function shouldAllowPublic() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-27 00:37:32 +01:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
2013-01-25 02:23:05 +01:00
|
|
|
$user = $request->getUser();
|
|
|
|
$title = pht('Conpherence');
|
2013-04-01 21:44:00 +02:00
|
|
|
$conpherence = null;
|
2013-01-25 02:23:05 +01:00
|
|
|
|
2015-03-31 21:45:32 +02:00
|
|
|
$limit = ConpherenceThreadListView::SEE_MORE_LIMIT * 5;
|
2013-04-26 19:30:41 +02:00
|
|
|
$all_participation = array();
|
2013-01-25 02:23:05 +01:00
|
|
|
|
2013-04-26 19:30:41 +02:00
|
|
|
$mode = $this->determineMode();
|
|
|
|
switch ($mode) {
|
|
|
|
case self::SELECTED_MODE:
|
2015-03-27 00:37:32 +01:00
|
|
|
$conpherence_id = $request->getURIData('id');
|
2013-04-26 19:30:41 +02:00
|
|
|
$conpherence = id(new ConpherenceThreadQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withIDs(array($conpherence_id))
|
|
|
|
->executeOne();
|
|
|
|
if (!$conpherence) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
if ($conpherence->getTitle()) {
|
|
|
|
$title = $conpherence->getTitle();
|
|
|
|
}
|
2015-03-25 02:38:16 +01:00
|
|
|
$cursor = $conpherence->getParticipantIfExists($user->getPHID());
|
2015-03-31 21:45:32 +02:00
|
|
|
$data = $this->loadDefaultParticipation($limit);
|
|
|
|
$all_participation = $data['all_participation'];
|
|
|
|
if (!$cursor) {
|
|
|
|
$menu_participation = id(new ConpherenceParticipant())
|
|
|
|
->makeEphemeral()
|
2015-03-25 02:38:16 +01:00
|
|
|
->setConpherencePHID($conpherence->getPHID())
|
|
|
|
->setParticipantPHID($user->getPHID());
|
2013-04-26 19:30:41 +02:00
|
|
|
} else {
|
2015-03-31 21:45:32 +02:00
|
|
|
$menu_participation = $cursor;
|
2013-04-26 19:30:41 +02:00
|
|
|
}
|
2015-03-31 21:45:32 +02:00
|
|
|
$all_participation =
|
|
|
|
array($conpherence->getPHID() => $menu_participation) +
|
|
|
|
$all_participation;
|
2013-04-26 19:30:41 +02:00
|
|
|
break;
|
|
|
|
case self::UNSELECTED_MODE:
|
|
|
|
default:
|
2015-03-31 21:45:32 +02:00
|
|
|
$data = $this->loadDefaultParticipation($limit);
|
2015-03-25 02:38:16 +01:00
|
|
|
$all_participation = $data['all_participation'];
|
2013-04-26 19:30:41 +02:00
|
|
|
break;
|
2013-01-25 02:23:05 +01:00
|
|
|
}
|
|
|
|
|
2013-04-26 19:30:41 +02:00
|
|
|
$threads = $this->loadConpherenceThreadData(
|
|
|
|
$all_participation);
|
2013-04-01 21:50:39 +02:00
|
|
|
|
|
|
|
$thread_view = id(new ConpherenceThreadListView())
|
|
|
|
->setUser($user)
|
|
|
|
->setBaseURI($this->getApplicationURI())
|
2015-03-31 21:45:32 +02:00
|
|
|
->setThreads($threads);
|
2013-01-25 02:23:05 +01:00
|
|
|
|
2013-04-26 19:30:41 +02:00
|
|
|
switch ($mode) {
|
|
|
|
case self::SELECTED_MODE:
|
|
|
|
$response = id(new AphrontAjaxResponse())->setContent($thread_view);
|
|
|
|
break;
|
|
|
|
case self::UNSELECTED_MODE:
|
|
|
|
default:
|
|
|
|
$layout = id(new ConpherenceLayoutView())
|
2015-03-25 19:48:22 +01:00
|
|
|
->setUser($user)
|
2013-04-26 19:30:41 +02:00
|
|
|
->setBaseURI($this->getApplicationURI())
|
|
|
|
->setThreadView($thread_view)
|
|
|
|
->setRole('list');
|
|
|
|
if ($conpherence) {
|
2015-03-26 20:24:29 +01:00
|
|
|
$policy_objects = id(new PhabricatorPolicyQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->setObject($conpherence)
|
|
|
|
->execute();
|
|
|
|
$layout->setHeader($this->buildHeaderPaneContent(
|
|
|
|
$conpherence,
|
|
|
|
$policy_objects));
|
2013-04-26 19:30:41 +02:00
|
|
|
$layout->setThread($conpherence);
|
2013-05-29 21:46:06 +02:00
|
|
|
} else {
|
2015-03-31 21:45:32 +02:00
|
|
|
$thread = ConpherenceThread::initializeNewThread($user);
|
|
|
|
$thread->attachHandles(array());
|
2015-04-13 20:31:34 +02:00
|
|
|
$thread->attachTransactions(array());
|
2015-03-31 21:45:32 +02:00
|
|
|
$thread->makeEphemeral();
|
2013-05-29 21:46:06 +02:00
|
|
|
$layout->setHeader(
|
2015-03-31 21:45:32 +02:00
|
|
|
$this->buildHeaderPaneContent($thread, array()));
|
2013-04-26 19:30:41 +02:00
|
|
|
}
|
|
|
|
$response = $this->buildApplicationPage(
|
|
|
|
$layout,
|
|
|
|
array(
|
|
|
|
'title' => $title,
|
|
|
|
));
|
|
|
|
break;
|
2013-04-01 21:52:56 +02:00
|
|
|
}
|
|
|
|
|
2013-04-26 19:30:41 +02:00
|
|
|
return $response;
|
|
|
|
|
|
|
|
}
|
2013-04-01 21:44:00 +02:00
|
|
|
|
2015-03-31 21:45:32 +02:00
|
|
|
private function loadDefaultParticipation($limit) {
|
2015-03-25 02:38:16 +01:00
|
|
|
$viewer = $this->getRequest()->getUser();
|
|
|
|
|
|
|
|
$all_participation = id(new ConpherenceParticipantQuery())
|
|
|
|
->withParticipantPHIDs(array($viewer->getPHID()))
|
2015-03-31 21:45:32 +02:00
|
|
|
->setLimit($limit)
|
2015-03-25 02:38:16 +01:00
|
|
|
->execute();
|
|
|
|
|
|
|
|
return array(
|
2015-04-05 14:29:39 +02:00
|
|
|
'all_participation' => $all_participation,
|
|
|
|
);
|
2013-04-26 19:30:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function loadConpherenceThreadData($participation) {
|
|
|
|
$user = $this->getRequest()->getUser();
|
|
|
|
$conpherence_phids = array_keys($participation);
|
2013-05-03 00:23:55 +02:00
|
|
|
$conpherences = array();
|
2013-04-26 19:30:41 +02:00
|
|
|
if ($conpherence_phids) {
|
|
|
|
$conpherences = id(new ConpherenceThreadQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withPHIDs($conpherence_phids)
|
2015-05-04 22:52:22 +02:00
|
|
|
->needCropPics(true)
|
2013-04-26 19:30:41 +02:00
|
|
|
->needParticipantCache(true)
|
|
|
|
->execute();
|
2013-04-01 21:43:07 +02:00
|
|
|
|
2013-05-03 00:23:55 +02:00
|
|
|
// this will re-sort by participation data
|
|
|
|
$conpherences = array_select_keys($conpherences, $conpherence_phids);
|
|
|
|
}
|
2013-04-26 19:30:41 +02:00
|
|
|
|
|
|
|
return $conpherences;
|
|
|
|
}
|
|
|
|
|
2013-01-25 02:23:05 +01:00
|
|
|
}
|