2013-07-28 03:37:17 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PonderQuestionStatusController
|
|
|
|
extends PonderController {
|
|
|
|
|
|
|
|
private $status;
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->status = idx($data, 'status');
|
|
|
|
$this->id = idx($data, 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
2013-07-29 02:40:11 +02:00
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
|
|
|
$question = id(new PonderQuestionQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
2013-07-28 03:37:17 +02:00
|
|
|
if (!$question) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2013-07-29 02:40:11 +02:00
|
|
|
// TODO: Use transactions.
|
|
|
|
|
2013-07-28 03:37:17 +02:00
|
|
|
switch ($this->status) {
|
|
|
|
case 'open':
|
|
|
|
$question->setStatus(PonderQuestionStatus::STATUS_OPEN);
|
|
|
|
break;
|
|
|
|
case 'close':
|
|
|
|
$question->setStatus(PonderQuestionStatus::STATUS_CLOSED);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return new Aphront400Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$question->save();
|
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())->setURI('/Q'.$question->getID());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|