2012-08-10 19:44:04 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PonderVoteSaveController extends PonderController {
|
|
|
|
|
|
|
|
private $kind;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->kind = $data['kind'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
$newvote = $request->getInt("vote");
|
|
|
|
$phid = $request->getStr("phid");
|
|
|
|
|
|
|
|
if (1 < $newvote || $newvote < -1) {
|
|
|
|
return new Aphront400Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$target = null;
|
|
|
|
|
|
|
|
if ($this->kind == "question") {
|
2013-07-29 00:38:47 +02:00
|
|
|
$target = id(new PonderQuestionQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withPHIDs(array($phid))
|
|
|
|
->executeOne();
|
2013-01-16 21:16:37 +01:00
|
|
|
} else if ($this->kind == "answer") {
|
2013-07-26 22:00:01 +02:00
|
|
|
$target = id(new PonderAnswerQuery())
|
|
|
|
->setViewer($user)
|
2013-07-26 22:13:38 +02:00
|
|
|
->withPHIDs(array($phid))
|
2013-07-26 22:00:01 +02:00
|
|
|
->executeOne();
|
2012-08-10 19:44:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$target) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$editor = id(new PonderVoteEditor())
|
|
|
|
->setVotable($target)
|
2012-10-10 19:18:23 +02:00
|
|
|
->setActor($user)
|
2012-08-10 19:44:04 +02:00
|
|
|
->setVote($newvote)
|
|
|
|
->saveVote();
|
|
|
|
|
|
|
|
return id(new AphrontAjaxResponse())->setContent(".");
|
|
|
|
}
|
|
|
|
}
|