2013-07-28 03:37:17 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PonderQuestionStatusController
|
|
|
|
extends PonderController {
|
|
|
|
|
2015-07-22 22:23:11 +02:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
$id = $request->getURIData('id');
|
|
|
|
$status = $request->getURIData('status');
|
2013-07-29 02:40:11 +02:00
|
|
|
|
|
|
|
$question = id(new PonderQuestionQuery())
|
|
|
|
->setViewer($viewer)
|
2015-07-22 22:23:11 +02:00
|
|
|
->withIDs(array($id))
|
2013-07-29 02:40:11 +02:00
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
2013-07-28 03:37:17 +02:00
|
|
|
if (!$question) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2015-07-22 22:23:11 +02:00
|
|
|
switch ($status) {
|
2013-07-28 03:37:17 +02:00
|
|
|
case 'open':
|
2013-07-29 02:52:35 +02:00
|
|
|
$status = PonderQuestionStatus::STATUS_OPEN;
|
2013-07-28 03:37:17 +02:00
|
|
|
break;
|
|
|
|
case 'close':
|
2013-07-29 02:52:35 +02:00
|
|
|
$status = PonderQuestionStatus::STATUS_CLOSED;
|
2013-07-28 03:37:17 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return new Aphront400Response();
|
|
|
|
}
|
|
|
|
|
2013-07-29 02:52:35 +02:00
|
|
|
$xactions = array();
|
|
|
|
$xactions[] = id(new PonderQuestionTransaction())
|
|
|
|
->setTransactionType(PonderQuestionTransaction::TYPE_STATUS)
|
|
|
|
->setNewValue($status);
|
|
|
|
|
|
|
|
$editor = id(new PonderQuestionEditor())
|
|
|
|
->setActor($viewer)
|
|
|
|
->setContentSourceFromRequest($request);
|
|
|
|
|
|
|
|
$editor->applyTransactions($question, $xactions);
|
2013-07-28 03:37:17 +02:00
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())->setURI('/Q'.$question->getID());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|