mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-11 15:21:03 +01:00
Clean up more PonderQuestionQuery cruft
Summary: Ref T3578. Unroll these static methods for consistency. Test Plan: grep Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T3578 Differential Revision: https://secure.phabricator.com/D6602
This commit is contained in:
parent
5a3e3994f5
commit
e6967ed2ec
6 changed files with 34 additions and 44 deletions
|
@ -4,17 +4,19 @@ final class PonderAnswerPreviewController
|
|||
extends PonderController {
|
||||
|
||||
public function processRequest() {
|
||||
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
$viewer = $request->getUser();
|
||||
$question_id = $request->getInt('question_id');
|
||||
|
||||
$question = PonderQuestionQuery::loadSingle($user, $question_id);
|
||||
$question = id(new PonderQuestionQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($question_id))
|
||||
->executeOne();
|
||||
if (!$question) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$author_phid = $user->getPHID();
|
||||
$author_phid = $viewer->getPHID();
|
||||
$object_phids = array($author_phid);
|
||||
$handles = $this->loadViewerHandles($object_phids);
|
||||
|
||||
|
@ -27,7 +29,7 @@ final class PonderAnswerPreviewController
|
|||
->setQuestion($question)
|
||||
->setTarget($answer)
|
||||
->setPreview(true)
|
||||
->setUser($user)
|
||||
->setUser($viewer)
|
||||
->setHandles($handles)
|
||||
->setAction(PonderLiterals::LITERAL_ANSWERED);
|
||||
|
||||
|
|
|
@ -4,29 +4,31 @@ final class PonderAnswerSaveController extends PonderController {
|
|||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$viewer = $request->getUser();
|
||||
|
||||
if (!$request->isFormPost()) {
|
||||
return new Aphront400Response();
|
||||
}
|
||||
|
||||
$user = $request->getUser();
|
||||
$question_id = $request->getInt('question_id');
|
||||
$question = PonderQuestionQuery::loadSingle($user, $question_id);
|
||||
|
||||
$question = id(new PonderQuestionQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($question_id))
|
||||
->executeOne();
|
||||
if (!$question) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$answer = $request->getStr('answer');
|
||||
|
||||
// Only want answers with some non whitespace content
|
||||
if (!strlen(trim($answer))) {
|
||||
$dialog = new AphrontDialogView();
|
||||
$dialog->setUser($request->getUser());
|
||||
$dialog->setTitle(pht('Empty Answer'));
|
||||
$dialog->appendChild(
|
||||
phutil_tag('p', array(), pht(
|
||||
'Your answer must not be empty.')));
|
||||
$dialog->addCancelButton('/Q'.$question_id);
|
||||
$dialog = id(new AphrontDialogView())
|
||||
->setUser($viewer)
|
||||
->setTitle(pht('Empty Answer'))
|
||||
->appendChild(
|
||||
phutil_tag('p', array(), pht(
|
||||
'Your answer must not be empty.')))
|
||||
->addCancelButton('/Q'.$question_id);
|
||||
|
||||
return id(new AphrontDialogResponse())->setDialog($dialog);
|
||||
}
|
||||
|
@ -40,13 +42,13 @@ final class PonderAnswerSaveController extends PonderController {
|
|||
$res = new PonderAnswer();
|
||||
$res
|
||||
->setContent($answer)
|
||||
->setAuthorPHID($user->getPHID())
|
||||
->setAuthorPHID($viewer->getPHID())
|
||||
->setVoteCount(0)
|
||||
->setQuestionID($question_id)
|
||||
->setContentSource($content_source);
|
||||
|
||||
id(new PonderAnswerEditor())
|
||||
->setActor($user)
|
||||
->setActor($viewer)
|
||||
->setQuestion($question)
|
||||
->setAnswer($res)
|
||||
->saveAnswer();
|
||||
|
|
|
@ -10,8 +10,10 @@ final class PonderCommentSaveController extends PonderController {
|
|||
|
||||
$user = $request->getUser();
|
||||
$question_id = $request->getInt('question_id');
|
||||
$question = PonderQuestionQuery::loadSingle($user, $question_id);
|
||||
|
||||
$question = id(new PonderQuestionQuery())
|
||||
->setViewer($user)
|
||||
->withIDs(array($question_id))
|
||||
->executeOne();
|
||||
if (!$question) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
|
|
@ -13,7 +13,10 @@ final class PonderQuestionViewController extends PonderController {
|
|||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$question = PonderQuestionQuery::loadSingle($user, $this->questionID);
|
||||
$question = id(new PonderQuestionQuery())
|
||||
->setViewer($user)
|
||||
->withIDs(array($this->questionID))
|
||||
->executeOne();
|
||||
if (!$question) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
|
|
@ -21,7 +21,10 @@ final class PonderVoteSaveController extends PonderController {
|
|||
$target = null;
|
||||
|
||||
if ($this->kind == "question") {
|
||||
$target = PonderQuestionQuery::loadSingleByPHID($user, $phid);
|
||||
$target = id(new PonderQuestionQuery())
|
||||
->setViewer($user)
|
||||
->withPHIDs(array($phid))
|
||||
->executeOne();
|
||||
} else if ($this->kind == "answer") {
|
||||
$target = id(new PonderAnswerQuery())
|
||||
->setViewer($user)
|
||||
|
|
|
@ -47,28 +47,6 @@ final class PonderQuestionQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
public static function loadSingle($viewer, $id) {
|
||||
if (!$viewer) {
|
||||
throw new Exception("Must set viewer when calling loadSingle");
|
||||
}
|
||||
|
||||
return idx(id(new PonderQuestionQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->execute(), $id);
|
||||
}
|
||||
|
||||
public static function loadSingleByPHID($viewer, $phid) {
|
||||
if (!$viewer) {
|
||||
throw new Exception("Must set viewer when calling loadSingle");
|
||||
}
|
||||
|
||||
return array_shift(id(new PonderQuestionQuery())
|
||||
->withPHIDs(array($phid))
|
||||
->setViewer($viewer)
|
||||
->execute());
|
||||
}
|
||||
|
||||
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
||||
$where = array();
|
||||
|
||||
|
|
Loading…
Reference in a new issue