2011-05-03 10:45:45 -07:00
|
|
|
<?php
|
|
|
|
|
|
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();
|
2012-10-05 13:13:50 -07:00
|
|
|
if ($file) {
|
2012-10-08 13:26:10 -07:00
|
|
|
$item->setImageURI($file->getThumb220x165URI());
|
|
|
|
|
$item->setImageSize(220, 165);
|
2012-10-05 13:13:50 -07:00
|
|
|
if ($file->getAuthorPHID()) {
|
|
|
|
|
$author_handle = $this->getHandle($file->getAuthorPHID());
|
|
|
|
|
$item->appendChild(
|
|
|
|
|
'Created by '.$author_handle->renderLink());
|
|
|
|
|
}
|
|
|
|
|
$datetime = phabricator_date($file->getDateCreated(), $viewer);
|
2012-10-01 14:06:00 -07:00
|
|
|
$item->appendChild(
|
2012-10-05 13:13:50 -07:00
|
|
|
phutil_render_tag(
|
|
|
|
|
'div',
|
|
|
|
|
array(),
|
|
|
|
|
'Created on '.$datetime));
|
|
|
|
|
}
|
|
|
|
|
$item->setURI($this->getApplicationURI('/edit/'.$macro->getID().'/'));
|
|
|
|
|
$item->setHeader($macro->getName());
|
2012-10-01 14:06:00 -07:00
|
|
|
|
|
|
|
|
$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',
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
}
|