mirror of
https://we.phorge.it/source/phorge.git
synced 2025-03-28 20:18:13 +01:00
Summary: Just a bad merge for the edit history, I think. We need to pass $user or we fatal trying to render timestamps. https://secure.phabricator.com/herald/all/view/differential/ Test Plan: Looked at Herald admin view. Reviewers: jungejason, xela, nh, btrahan, fratrik Reviewed By: fratrik CC: aran, epriestley Differential Revision: https://secure.phabricator.com/D1611
173 lines
4.4 KiB
PHP
173 lines
4.4 KiB
PHP
<?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.
|
|
*/
|
|
|
|
class HeraldAllRulesController extends HeraldController {
|
|
|
|
private $view;
|
|
private $viewPHID;
|
|
private $filter;
|
|
|
|
public function getFilter() {
|
|
return $this->filter;
|
|
}
|
|
public function setFilter($filter) {
|
|
$this->filter = 'all/view/'.$filter;
|
|
return $this;
|
|
}
|
|
|
|
public function shouldRequireAdmin() {
|
|
return true;
|
|
}
|
|
|
|
public function willProcessRequest(array $data) {
|
|
$this->view = idx($data, 'view');
|
|
$this->setFilter($this->view);
|
|
}
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
$user = $request->getUser();
|
|
$this->viewPHID = nonempty($request->getStr('phid'), null);
|
|
|
|
if ($request->isFormPost()) {
|
|
$phid_arr = $request->getArr('view_user');
|
|
$view_target = head($phid_arr);
|
|
return id(new AphrontRedirectResponse())
|
|
->setURI($request->getRequestURI()->alter('phid', $view_target));
|
|
}
|
|
|
|
$map = HeraldContentTypeConfig::getContentTypeMap();
|
|
if (empty($map[$this->view])) {
|
|
reset($map);
|
|
$this->view = key($map);
|
|
}
|
|
|
|
$offset = $request->getInt('offset', 0);
|
|
$pager = new AphrontPagerView();
|
|
$pager->setPageSize(50);
|
|
$pager->setOffset($offset);
|
|
$pager->setURI($request->getRequestURI(), 'offset');
|
|
|
|
list($rules, $handles) = $this->queryRules($pager);
|
|
|
|
if (!$this->viewPHID) {
|
|
$view_users = array();
|
|
} else {
|
|
$view_users = array(
|
|
$this->viewPHID => $handles[$this->viewPHID]->getFullName(),
|
|
);
|
|
}
|
|
|
|
$filter_form = id(new AphrontFormView())
|
|
->setUser($user)
|
|
->appendChild(
|
|
id(new AphrontFormTokenizerControl())
|
|
->setDatasource('/typeahead/common/users/')
|
|
->setLabel('View User')
|
|
->setName('view_user')
|
|
->setValue($view_users)
|
|
->setLimit(1));
|
|
$filter_view = new AphrontListFilterView();
|
|
$filter_view->appendChild($filter_form);
|
|
|
|
$list_view = id(new HeraldRuleListView())
|
|
->setRules($rules)
|
|
->setHandles($handles)
|
|
->setMap($map)
|
|
->setShowType(true)
|
|
->setAllowCreation(false)
|
|
->setUser($user)
|
|
->setView($this->view);
|
|
$panel = $list_view->render();
|
|
$panel->appendChild($pager);
|
|
|
|
$sidenav = new AphrontSideNavView();
|
|
$sidenav->appendChild($filter_view);
|
|
$sidenav->appendChild($panel);
|
|
|
|
$query = '';
|
|
if ($this->viewPHID) {
|
|
$query = '?phid='.$this->viewPHID;
|
|
}
|
|
|
|
foreach ($map as $key => $value) {
|
|
$sidenav->addNavItem(
|
|
phutil_render_tag(
|
|
'a',
|
|
array(
|
|
'href' => '/herald/all/view/'.$key.'/'.$query,
|
|
'class' => ($key == $this->view)
|
|
? 'aphront-side-nav-selected'
|
|
: null,
|
|
),
|
|
phutil_escape_html($value)));
|
|
}
|
|
|
|
return $this->buildStandardPageResponse(
|
|
array(
|
|
$filter_view,
|
|
$panel
|
|
),
|
|
array(
|
|
'title' => 'Herald',
|
|
'tab' => 'all',
|
|
));
|
|
}
|
|
|
|
private function queryRules(AphrontPagerView $pager) {
|
|
$rule = new HeraldRule();
|
|
$conn_r = $rule->establishConnection('r');
|
|
|
|
$where_clause = qsprintf(
|
|
$conn_r,
|
|
'WHERE contentType = %s',
|
|
$this->view);
|
|
|
|
if ($this->viewPHID) {
|
|
$where_clause .= qsprintf(
|
|
$conn_r,
|
|
' AND authorPHID = %s',
|
|
$this->viewPHID);
|
|
}
|
|
|
|
$data = queryfx_all(
|
|
$conn_r,
|
|
'SELECT * FROM %T
|
|
%Q
|
|
ORDER BY id DESC
|
|
LIMIT %d, %d',
|
|
$rule->getTableName(),
|
|
$where_clause,
|
|
$pager->getOffset(),
|
|
$pager->getPageSize() + 1);
|
|
$data = $pager->sliceResults($data);
|
|
$rules = $rule->loadAllFromArray($data);
|
|
|
|
$need_phids = mpull($rules, 'getAuthorPHID');
|
|
if ($this->viewPHID) {
|
|
$need_phids[] = $this->viewPHID;
|
|
}
|
|
|
|
$handles = id(new PhabricatorObjectHandleData($need_phids))
|
|
->loadHandles();
|
|
|
|
return array($rules, $handles);
|
|
}
|
|
}
|
|
|