2011-05-03 10:45:45 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/*
|
2012-01-10 14:48:55 -08:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-05-03 10:45:45 -07:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-10-01 14:04:03 -07:00
|
|
|
final class PhabricatorMacroListController
|
|
|
|
|
extends PhabricatorMacroController {
|
2012-03-09 15:46:25 -08:00
|
|
|
|
2011-05-03 10:45:45 -07:00
|
|
|
public function processRequest() {
|
|
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
2012-10-01 14:06:00 -07:00
|
|
|
$viewer = $request->getUser();
|
2011-05-03 10:45:45 -07:00
|
|
|
|
2011-06-02 17:13:25 -07:00
|
|
|
$macro_table = new PhabricatorFileImageMacro();
|
2012-10-01 14:06:00 -07:00
|
|
|
|
|
|
|
|
$filter = $request->getStr('name');
|
|
|
|
|
if (strlen($filter)) {
|
2012-04-13 11:30:01 -07:00
|
|
|
$macros = $macro_table->loadAllWhere(
|
|
|
|
|
'name LIKE %~',
|
2012-10-01 14:06:00 -07:00
|
|
|
$filter);
|
|
|
|
|
|
|
|
|
|
$nodata = pht(
|
|
|
|
|
'There are no macros matching the filter "%s".',
|
|
|
|
|
phutil_escape_html($filter));
|
2012-04-13 11:30:01 -07:00
|
|
|
} else {
|
|
|
|
|
$pager = new AphrontPagerView();
|
|
|
|
|
$pager->setOffset($request->getInt('page'));
|
|
|
|
|
|
|
|
|
|
$macros = $macro_table->loadAllWhere(
|
|
|
|
|
'1 = 1 ORDER BY id DESC LIMIT %d, %d',
|
|
|
|
|
$pager->getOffset(),
|
|
|
|
|
$pager->getPageSize());
|
|
|
|
|
|
|
|
|
|
// Get an exact count since the size here is reasonably going to be a few
|
|
|
|
|
// thousand at most in any reasonable case.
|
|
|
|
|
$count = queryfx_one(
|
|
|
|
|
$macro_table->establishConnection('r'),
|
|
|
|
|
'SELECT COUNT(*) N FROM %T',
|
|
|
|
|
$macro_table->getTableName());
|
|
|
|
|
$count = $count['N'];
|
|
|
|
|
|
|
|
|
|
$pager->setCount($count);
|
|
|
|
|
$pager->setURI($request->getRequestURI(), 'page');
|
2012-10-01 14:06:00 -07:00
|
|
|
|
|
|
|
|
$nodata = pht('There are no image macros yet.');
|
2012-04-13 11:30:01 -07:00
|
|
|
}
|
2011-05-03 10:45:45 -07:00
|
|
|
|
2011-10-04 23:05:40 -07:00
|
|
|
$file_phids = mpull($macros, 'getFilePHID');
|
2011-10-28 08:06:30 -07:00
|
|
|
|
|
|
|
|
$files = array();
|
|
|
|
|
if ($file_phids) {
|
|
|
|
|
$files = id(new PhabricatorFile())->loadAllWhere(
|
|
|
|
|
"phid IN (%Ls)",
|
|
|
|
|
$file_phids);
|
|
|
|
|
$author_phids = mpull($files, 'getAuthorPHID', 'getPHID');
|
2011-10-04 23:05:40 -07:00
|
|
|
|
2012-10-01 14:06:00 -07:00
|
|
|
$this->loadHandles($author_phids);
|
2011-05-03 10:45:45 -07:00
|
|
|
}
|
2012-10-01 14:06:00 -07:00
|
|
|
$files_map = mpull($files, null, 'getPHID');
|
2011-05-03 10:45:45 -07:00
|
|
|
|
2012-04-13 11:30:01 -07:00
|
|
|
$filter_form = id(new AphrontFormView())
|
|
|
|
|
->setMethod('GET')
|
|
|
|
|
->setUser($request->getUser())
|
|
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
|
->setName('name')
|
|
|
|
|
->setLabel('Name')
|
2012-10-01 14:06:00 -07:00
|
|
|
->setValue($filter))
|
2012-04-13 11:30:01 -07:00
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
|
->setValue('Filter Image Macros'));
|
|
|
|
|
|
|
|
|
|
$filter_view = new AphrontListFilterView();
|
|
|
|
|
$filter_view->appendChild($filter_form);
|
|
|
|
|
|
2012-10-01 14:04:03 -07:00
|
|
|
$nav = $this->buildSideNavView();
|
|
|
|
|
$nav->selectFilter('/');
|
2011-12-14 22:37:23 -08:00
|
|
|
|
2012-10-01 14:04:03 -07:00
|
|
|
$nav->appendChild($filter_view);
|
2012-10-01 14:06:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($macros) {
|
|
|
|
|
$pinboard = new PhabricatorPinboardView();
|
|
|
|
|
foreach ($macros as $macro) {
|
|
|
|
|
$file_phid = $macro->getFilePHID();
|
|
|
|
|
$file = idx($files_map, $file_phid);
|
|
|
|
|
|
|
|
|
|
$item = new PhabricatorPinboardItemView();
|
|
|
|
|
$item->setImageURI($file->getThumb160x120URI());
|
|
|
|
|
$item->setImageSize(160, 120);
|
|
|
|
|
$item->setURI($this->getApplicationURI('/edit/'.$macro->getID().'/'));
|
|
|
|
|
$item->setHeader($macro->getName());
|
|
|
|
|
|
|
|
|
|
if ($file->getAuthorPHID()) {
|
|
|
|
|
$author_handle = $this->getHandle($file->getAuthorPHID());
|
|
|
|
|
$item->appendChild(
|
|
|
|
|
'Created by '.$author_handle->renderLink());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$datetime = phabricator_date($file->getDateCreated(), $viewer);
|
|
|
|
|
$item->appendChild(
|
|
|
|
|
phutil_render_tag(
|
|
|
|
|
'div',
|
|
|
|
|
array(),
|
|
|
|
|
'Created on '.$datetime));
|
|
|
|
|
|
|
|
|
|
$pinboard->addItem($item);
|
|
|
|
|
}
|
|
|
|
|
$nav->appendChild($pinboard);
|
|
|
|
|
} else {
|
|
|
|
|
$list = new PhabricatorObjectItemListView();
|
|
|
|
|
$list->setNoDataString($nodata);
|
|
|
|
|
$nav->appendChild($list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($filter === null) {
|
|
|
|
|
$nav->appendChild($pager);
|
|
|
|
|
}
|
2012-10-01 14:04:03 -07:00
|
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
|
$nav,
|
2011-05-03 10:45:45 -07:00
|
|
|
array(
|
2012-10-01 14:06:00 -07:00
|
|
|
'device' => true,
|
2011-05-03 10:45:45 -07:00
|
|
|
'title' => 'Image Macros',
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
}
|