Page MenuHomePhorge

No OneTemporary

diff --git a/src/applications/slowvote/controller/list/PhabricatorSlowvoteListController.php b/src/applications/slowvote/controller/list/PhabricatorSlowvoteListController.php
index b3cc4f2987..cbd4b39ad9 100644
--- a/src/applications/slowvote/controller/list/PhabricatorSlowvoteListController.php
+++ b/src/applications/slowvote/controller/list/PhabricatorSlowvoteListController.php
@@ -1,167 +1,184 @@
<?php
/*
* Copyright 2011 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.
*/
class PhabricatorSlowvoteListController
extends PhabricatorSlowvoteController {
private $view;
const VIEW_ALL = 'all';
const VIEW_CREATED = 'created';
const VIEW_VOTED = 'voted';
public function willProcessRequest(array $data) {
$this->view = idx($data, 'view');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
- $filters = array(
+ $views = array(
self::VIEW_ALL => 'All Slowvotes',
self::VIEW_CREATED => 'Created',
self::VIEW_VOTED => 'Voted In',
);
- $view = isset($filters[$this->view])
+ $view = isset($views[$this->view])
? $this->view
: self::VIEW_ALL;
- $side_nav = new AphrontSideNavView();
- foreach ($filters as $key => $name) {
- $side_nav->addNavItem(
+ $side_nav = $this->renderSideNav($views, $view);
+
+ $pager = new AphrontPagerView();
+ $pager->setOffset($request->getInt('page'));
+ $pager->setURI($request->getRequestURI(), 'page');
+
+ $polls = $this->loadPolls($pager, $view);
+
+ $phids = mpull($polls, 'getAuthorPHID');
+ $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
+
+ $rows = array();
+ foreach ($polls as $poll) {
+ $rows[] = array(
+ $handles[$poll->getAuthorPHID()]->renderLink(),
phutil_render_tag(
'a',
array(
- 'href' => '/vote/view/'.$key.'/',
- 'class' => ($view == $key) ? 'aphront-side-nav-selected' : null,
+ 'href' => '/V'.$poll->getID(),
),
- phutil_escape_html($name)));
+ phutil_escape_html('V'.$poll->getID().' '.$poll->getQuestion())),
+ phabricator_date($poll->getDateCreated(), $user),
+ phabricator_time($poll->getDateCreated(), $user),
+ );
}
+ $table = new AphrontTableView($rows);
+ $table->setColumnClasses(
+ array(
+ '',
+ 'pri wide',
+ '',
+ 'right',
+ ));
+ $table->setHeaders(
+ array(
+ 'Author',
+ 'Poll',
+ 'Date',
+ 'Time',
+ ));
+
+ $panel = new AphrontPanelView();
+ $panel->setHeader($this->getTableHeader($view));
+ $panel->setCreateButton('Create Slowvote', '/vote/create/');
+ $panel->appendChild($table);
+ $panel->appendChild($pager);
+
+ $side_nav->appendChild($panel);
+
+ return $this->buildStandardPageResponse(
+ $side_nav,
+ array(
+ 'title' => 'Slowvotes',
+ ));
+ }
+
+ private function loadPolls(AphrontPagerView $pager, $view) {
+ $request = $this->getRequest();
+ $user = $request->getUser();
$poll = new PhabricatorSlowvotePoll();
- $conn = $poll->establishConnection('r');
- $pager = new AphrontPagerView();
- $pager->setOffset($request->getInt('page'));
- $pager->setURI($request->getRequestURI(), 'page');
+ $conn = $poll->establishConnection('r');
$offset = $pager->getOffset();
$limit = $pager->getPageSize() + 1;
switch ($view) {
case self::VIEW_ALL:
$data = queryfx_all(
$conn,
'SELECT * FROM %T ORDER BY id DESC LIMIT %d, %d',
$poll->getTableName(),
$offset,
$limit);
break;
case self::VIEW_CREATED:
$data = queryfx_all(
$conn,
'SELECT * FROM %T WHERE authorPHID = %s ORDER BY id DESC
LIMIT %d, %d',
$poll->getTableName(),
$user->getPHID(),
$offset,
$limit);
break;
case self::VIEW_VOTED:
$choice = new PhabricatorSlowvoteChoice();
$data = queryfx_all(
$conn,
'SELECT p.* FROM %T p JOIN %T o
ON o.pollID = p.id
WHERE o.authorPHID = %s
GROUP BY p.id
ORDER BY p.id DESC
LIMIT %d, %d',
$poll->getTableName(),
$choice->getTableName(),
$user->getPHID(),
$offset,
$limit);
break;
}
$data = $pager->sliceResults($data);
- $polls = $poll->loadAllFromArray($data);
-
- $phids = mpull($polls, 'getAuthorPHID');
- $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
+ return $poll->loadAllFromArray($data);
+ }
- $rows = array();
- foreach ($polls as $poll) {
- $rows[] = array(
- $handles[$poll->getAuthorPHID()]->renderLink(),
+ private function renderSideNav(array $views, $view) {
+ $side_nav = new AphrontSideNavView();
+ foreach ($views as $key => $name) {
+ $side_nav->addNavItem(
phutil_render_tag(
'a',
array(
- 'href' => '/V'.$poll->getID(),
+ 'href' => '/vote/view/'.$key.'/',
+ 'class' => ($view == $key)
+ ? 'aphront-side-nav-selected'
+ : null,
),
- phutil_escape_html('V'.$poll->getID().' '.$poll->getQuestion())),
- phabricator_date($poll->getDateCreated(), $user),
- phabricator_time($poll->getDateCreated(), $user),
- );
+ phutil_escape_html($name)));
}
+ return $side_nav;
+ }
- $table = new AphrontTableView($rows);
- $table->setColumnClasses(
- array(
- '',
- 'pri wide',
- '',
- 'right',
- ));
- $table->setHeaders(
- array(
- 'Author',
- 'Poll',
- 'Date',
- 'Time',
- ));
-
- $headers = array(
+ private function getTableHeader($view) {
+ static $headers = array(
self::VIEW_ALL
=> 'Slowvotes Not Yet Consumed by the Ravages of Time',
self::VIEW_CREATED
=> 'Slowvotes Birthed from Your Noblest of Great Minds',
self::VIEW_VOTED
=> 'Slowvotes Within Which You Express Your Mighty Opinion',
);
-
- $panel = new AphrontPanelView();
- $panel->setHeader(idx($headers, $view));
- $panel->setCreateButton('Create Slowvote', '/vote/create/');
- $panel->appendChild($table);
- $panel->appendChild($pager);
-
- $side_nav->appendChild($panel);
-
- return $this->buildStandardPageResponse(
- $side_nav,
- array(
- 'title' => 'Slowvotes',
- ));
+ return idx($headers, $view);
}
}

File Metadata

Mime Type
text/x-diff
Expires
Jan 19 2025, 23:24 (6 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1129868
Default Alt Text
(7 KB)

Event Timeline