1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-04 12:42:43 +01:00
phorge-phorge/src/applications/ponder/controller/PonderVoteSaveController.php

48 lines
1.1 KiB
PHP
Raw Normal View History

<?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") {
$target = id(new PonderQuestionQuery())
->setViewer($user)
->withPHIDs(array($phid))
->executeOne();
2013-01-16 21:16:37 +01:00
} else if ($this->kind == "answer") {
$target = id(new PonderAnswerQuery())
->setViewer($user)
->withPHIDs(array($phid))
->executeOne();
}
if (!$target) {
return new Aphront404Response();
}
$editor = id(new PonderVoteEditor())
->setVotable($target)
->setActor($user)
->setVote($newvote)
->saveVote();
return id(new AphrontAjaxResponse())->setContent(".");
}
}