mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-25 22:18:19 +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 {
|
extends PonderController {
|
||||||
|
|
||||||
public function processRequest() {
|
public function processRequest() {
|
||||||
|
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$user = $request->getUser();
|
$viewer = $request->getUser();
|
||||||
$question_id = $request->getInt('question_id');
|
$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) {
|
if (!$question) {
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
|
|
||||||
$author_phid = $user->getPHID();
|
$author_phid = $viewer->getPHID();
|
||||||
$object_phids = array($author_phid);
|
$object_phids = array($author_phid);
|
||||||
$handles = $this->loadViewerHandles($object_phids);
|
$handles = $this->loadViewerHandles($object_phids);
|
||||||
|
|
||||||
|
@ -27,7 +29,7 @@ final class PonderAnswerPreviewController
|
||||||
->setQuestion($question)
|
->setQuestion($question)
|
||||||
->setTarget($answer)
|
->setTarget($answer)
|
||||||
->setPreview(true)
|
->setPreview(true)
|
||||||
->setUser($user)
|
->setUser($viewer)
|
||||||
->setHandles($handles)
|
->setHandles($handles)
|
||||||
->setAction(PonderLiterals::LITERAL_ANSWERED);
|
->setAction(PonderLiterals::LITERAL_ANSWERED);
|
||||||
|
|
||||||
|
|
|
@ -4,29 +4,31 @@ final class PonderAnswerSaveController extends PonderController {
|
||||||
|
|
||||||
public function processRequest() {
|
public function processRequest() {
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
$viewer = $request->getUser();
|
||||||
|
|
||||||
if (!$request->isFormPost()) {
|
if (!$request->isFormPost()) {
|
||||||
return new Aphront400Response();
|
return new Aphront400Response();
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $request->getUser();
|
|
||||||
$question_id = $request->getInt('question_id');
|
$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) {
|
if (!$question) {
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
|
|
||||||
$answer = $request->getStr('answer');
|
$answer = $request->getStr('answer');
|
||||||
|
|
||||||
// Only want answers with some non whitespace content
|
|
||||||
if (!strlen(trim($answer))) {
|
if (!strlen(trim($answer))) {
|
||||||
$dialog = new AphrontDialogView();
|
$dialog = id(new AphrontDialogView())
|
||||||
$dialog->setUser($request->getUser());
|
->setUser($viewer)
|
||||||
$dialog->setTitle(pht('Empty Answer'));
|
->setTitle(pht('Empty Answer'))
|
||||||
$dialog->appendChild(
|
->appendChild(
|
||||||
phutil_tag('p', array(), pht(
|
phutil_tag('p', array(), pht(
|
||||||
'Your answer must not be empty.')));
|
'Your answer must not be empty.')))
|
||||||
$dialog->addCancelButton('/Q'.$question_id);
|
->addCancelButton('/Q'.$question_id);
|
||||||
|
|
||||||
return id(new AphrontDialogResponse())->setDialog($dialog);
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
||||||
}
|
}
|
||||||
|
@ -40,13 +42,13 @@ final class PonderAnswerSaveController extends PonderController {
|
||||||
$res = new PonderAnswer();
|
$res = new PonderAnswer();
|
||||||
$res
|
$res
|
||||||
->setContent($answer)
|
->setContent($answer)
|
||||||
->setAuthorPHID($user->getPHID())
|
->setAuthorPHID($viewer->getPHID())
|
||||||
->setVoteCount(0)
|
->setVoteCount(0)
|
||||||
->setQuestionID($question_id)
|
->setQuestionID($question_id)
|
||||||
->setContentSource($content_source);
|
->setContentSource($content_source);
|
||||||
|
|
||||||
id(new PonderAnswerEditor())
|
id(new PonderAnswerEditor())
|
||||||
->setActor($user)
|
->setActor($viewer)
|
||||||
->setQuestion($question)
|
->setQuestion($question)
|
||||||
->setAnswer($res)
|
->setAnswer($res)
|
||||||
->saveAnswer();
|
->saveAnswer();
|
||||||
|
|
|
@ -10,8 +10,10 @@ final class PonderCommentSaveController extends PonderController {
|
||||||
|
|
||||||
$user = $request->getUser();
|
$user = $request->getUser();
|
||||||
$question_id = $request->getInt('question_id');
|
$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) {
|
if (!$question) {
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,10 @@ final class PonderQuestionViewController extends PonderController {
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$user = $request->getUser();
|
$user = $request->getUser();
|
||||||
|
|
||||||
$question = PonderQuestionQuery::loadSingle($user, $this->questionID);
|
$question = id(new PonderQuestionQuery())
|
||||||
|
->setViewer($user)
|
||||||
|
->withIDs(array($this->questionID))
|
||||||
|
->executeOne();
|
||||||
if (!$question) {
|
if (!$question) {
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,10 @@ final class PonderVoteSaveController extends PonderController {
|
||||||
$target = null;
|
$target = null;
|
||||||
|
|
||||||
if ($this->kind == "question") {
|
if ($this->kind == "question") {
|
||||||
$target = PonderQuestionQuery::loadSingleByPHID($user, $phid);
|
$target = id(new PonderQuestionQuery())
|
||||||
|
->setViewer($user)
|
||||||
|
->withPHIDs(array($phid))
|
||||||
|
->executeOne();
|
||||||
} else if ($this->kind == "answer") {
|
} else if ($this->kind == "answer") {
|
||||||
$target = id(new PonderAnswerQuery())
|
$target = id(new PonderAnswerQuery())
|
||||||
->setViewer($user)
|
->setViewer($user)
|
||||||
|
|
|
@ -47,28 +47,6 @@ final class PonderQuestionQuery
|
||||||
return $this;
|
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) {
|
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
||||||
$where = array();
|
$where = array();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue