Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/ponder/controller/PonderFeedController.php b/src/applications/ponder/controller/PonderFeedController.php
index 40f73ffb35..67a744a47b 100644
--- a/src/applications/ponder/controller/PonderFeedController.php
+++ b/src/applications/ponder/controller/PonderFeedController.php
@@ -1,151 +1,149 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class PonderFeedController extends PonderController {
private $page;
- private $feedOffset;
- private $questionOffset;
private $answerOffset;
- const FEED_PAGE_SIZE = 20;
- const PROFILE_QUESTION_PAGE_SIZE = 10;
const PROFILE_ANSWER_PAGE_SIZE = 10;
public function willProcessRequest(array $data) {
$this->page = idx($data, 'page');
$this->feedOffset = idx($data, 'feedoffset');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
- $this->feedOffset = $request->getInt('off');
- $this->questionOffset = $request->getInt('qoff');
$this->answerOffset = $request->getInt('aoff');
$pages = array(
'feed' => 'All Questions',
'questions' => 'Your Questions',
'answers' => 'Your Answers',
);
$side_nav = $this->buildSideNavView();
$this->page = $side_nav->selectFilter($this->page, 'feed');
$title = $pages[$this->page];
switch ($this->page) {
case 'feed':
case 'questions':
+ $pager = new AphrontPagerView();
+ $pager->setOffset($request->getStr('offset'));
+ $pager->setURI($request->getRequestURI(), 'offset');
+
+ $query = new PonderQuestionQuery();
if ($this->page == 'feed') {
- $questions = PonderQuestionQuery::loadHottest(
- $user,
- $this->feedOffset,
- self::FEED_PAGE_SIZE + 1);
+ $query
+ ->setOrder(PonderQuestionQuery::ORDER_HOTTEST);
} else {
- $questions = PonderQuestionQuery::loadByAuthor(
- $user,
- $user->getPHID(),
- $this->questionOffset,
- self::PROFILE_QUESTION_PAGE_SIZE + 1
- );
+ $query
+ ->setOrder(PonderQuestionQuery::ORDER_CREATED)
+ ->withAuthorPHIDs(array($user->getPHID()));
}
+ $questions = $query->executeWithOffsetPager($pager);
+
$this->loadHandles(mpull($questions, 'getAuthorPHID'));
$view = $this->buildQuestionListView($questions);
+ $view->setPager($pager);
+
$side_nav->appendChild(
id(new PhabricatorHeaderView())->setHeader($title));
$side_nav->appendChild($view);
break;
case 'answers':
$answers = PonderAnswerQuery::loadByAuthorWithQuestions(
$user,
$user->getPHID(),
$this->answerOffset,
self::PROFILE_ANSWER_PAGE_SIZE + 1
);
$phids = array($user->getPHID());
$handles = $this->loadViewerHandles($phids);
$side_nav->appendChild(
id(new PonderUserProfileView())
->setUser($user)
->setAnswers($answers)
->setHandles($handles)
->setAnswerOffset($this->answerOffset)
- ->setPageSize(self::PROFILE_QUESTION_PAGE_SIZE)
+ ->setPageSize(self::PROFILE_ANSWER_PAGE_SIZE)
->setURI(new PhutilURI("/ponder/profile/"), "aoff")
);
break;
}
return $this->buildApplicationPage(
$side_nav,
array(
'device' => true,
'title' => $title,
));
}
private function buildQuestionListView(array $questions) {
assert_instances_of($questions, 'PonderQuestion');
$user = $this->getRequest()->getUser();
$view = new PhabricatorObjectItemListView();
$view->setNoDataString(pht('No matching questions.'));
foreach ($questions as $question) {
$item = new PhabricatorObjectItemView();
$item->setHeader('Q'.$question->getID().' '.$question->getTitle());
$item->setHref('/Q'.$question->getID());
$desc = $question->getContent();
if ($desc) {
$item->addDetail(
pht('Description'),
phutil_escape_html(phutil_utf8_shorten($desc, 128)));
}
$item->addDetail(
pht('Author'),
$this->getHandle($question->getAuthorPHID())->renderLink());
$item->addDetail(
pht('Votes'),
$question->getVoteCount());
$item->addDetail(
pht('Answers'),
$question->getAnswerCount());
$created = pht(
'Created %s',
phabricator_date($question->getDateCreated(), $user));
$item->addAttribute($created);
$view->addItem($item);
}
return $view;
}
}
diff --git a/src/applications/ponder/query/PonderQuestionQuery.php b/src/applications/ponder/query/PonderQuestionQuery.php
index c93bf69c0e..36869bf087 100644
--- a/src/applications/ponder/query/PonderQuestionQuery.php
+++ b/src/applications/ponder/query/PonderQuestionQuery.php
@@ -1,158 +1,117 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class PonderQuestionQuery extends PhabricatorOffsetPagedQuery {
- private $id;
- private $phids;
- private $authorPHID;
- private $orderHottest;
- private $orderNewest;
+ const ORDER_CREATED = 'order-created';
+ const ORDER_HOTTEST = 'order-hottest';
- public function withID($qid) {
- $this->id = $qid;
- return $this;
- }
+ private $ids;
+ private $phids;
+ private $authorPHIDs;
+ private $order = self::ORDER_CREATED;
- public function withPHID($phid) {
- $this->phids = array($phid);
+ public function withIDs(array $ids) {
+ $this->ids = $ids;
return $this;
}
- public function withPHIDs($phids) {
+ public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
- public function withAuthorPHID($phid) {
- $this->authorPHID = $phid;
- return $this;
- }
-
- public function orderByHottest($usethis) {
- $this->orderHottest = $usethis;
+ public function withAuthorPHIDs(array $phids) {
+ $this->authorPHIDs = $phids;
return $this;
}
- public function orderByNewest($usethis) {
- $this->orderNewest = $usethis;
+ public function setOrder($order) {
+ $this->order = $order;
return $this;
}
- public static function loadHottest($viewer, $offset, $count) {
- if (!$viewer) {
- throw new Exception("Must set viewer when calling loadHottest");
- }
-
- return id(new PonderQuestionQuery())
- ->setOffset($offset)
- ->setLimit($count)
- ->orderByHottest(true)
- ->orderByNewest(true)
- ->execute();
- }
-
- public static function loadByAuthor($viewer, $author_phid, $offset, $count) {
- if (!$viewer) {
- throw new Exception("Must set viewer when calling loadByAuthor");
- }
-
- return id(new PonderQuestionQuery())
- ->withAuthorPHID($author_phid)
- ->setOffset($offset)
- ->setLimit($count)
- ->orderByNewest(true)
- ->execute();
- }
-
public static function loadSingle($viewer, $id) {
if (!$viewer) {
throw new Exception("Must set viewer when calling loadSingle");
}
return idx(id(new PonderQuestionQuery())
- ->withID($id)
- ->execute(), $id);
+ ->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())
- ->withPHID($phid)
+ ->withPHIDs(array($phid))
->execute());
}
- private function buildWhereClause($conn_r) {
+ private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
$where = array();
- if ($this->id) {
- $where[] = qsprintf($conn_r, '(id = %d)', $this->id);
+
+ if ($this->ids) {
+ $where[] = qsprintf($conn_r, 'q.id IN (%Ld)', $this->ids);
}
+
if ($this->phids) {
- $where[] = qsprintf($conn_r, '(phid in (%Ls))', $this->phids);
+ $where[] = qsprintf($conn_r, 'q.phid IN (%Ls)', $this->phids);
}
- if ($this->authorPHID) {
- $where[] = qsprintf($conn_r, '(authorPHID = %s)', $this->authorPHID);
+
+ if ($this->authorPHIDs) {
+ $where[] = qsprintf($conn_r, 'q.authorPHID IN (%Ls)', $this->authorPHIDs);
}
- return ($where ? 'WHERE ' . implode(' AND ', $where) : '');
+ return $this->formatWhereClause($where);
}
- private function buildOrderByClause($conn_r) {
- $order = array();
- if ($this->orderHottest) {
- $order[] = qsprintf($conn_r, 'heat DESC');
- }
- if ($this->orderNewest) {
- $order[] = qsprintf($conn_r, 'id DESC');
- }
-
- if (count($order) == 0) {
- $order[] = qsprintf($conn_r, 'id ASC');
+ private function buildOrderByClause(AphrontDatabaseConnection $conn_r) {
+ switch ($this->order) {
+ case self::ORDER_HOTTEST:
+ return qsprintf($conn_r, 'ORDER BY q.heat DESC, q.id DESC');
+ case self::ORDER_CREATED:
+ return qsprintf($conn_r, 'ORDER BY q.id DESC');
+ default:
+ throw new Exception("Unknown order '{$this->order}'!");
}
-
- return ($order ? 'ORDER BY ' . implode(', ', $order) : '');
}
public function execute() {
$question = new PonderQuestion();
$conn_r = $question->establishConnection('r');
- $select = qsprintf(
- $conn_r,
- 'SELECT r.* FROM %T r',
- $question->getTableName());
-
$where = $this->buildWhereClause($conn_r);
$order_by = $this->buildOrderByClause($conn_r);
$limit = $this->buildLimitClause($conn_r);
return $question->loadAllFromArray(
queryfx_all(
$conn_r,
- '%Q %Q %Q %Q',
- $select,
+ 'SELECT q.* FROM %T q %Q %Q %Q',
+ $question->getTableName(),
$where,
$order_by,
$limit));
}
}

File Metadata

Mime Type
text/x-diff
Expires
Thu, Jul 3, 1:55 PM (3 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
165852
Default Alt Text
(10 KB)

Event Timeline