3 final class PhabricatorMacroSearchEngine
4 extends PhabricatorApplicationSearchEngine
{
6 public function getResultTypeDescription() {
10 public function getApplicationClassName() {
11 return 'PhabricatorMacroApplication';
14 public function newQuery() {
15 return id(new PhabricatorMacroQuery())
19 protected function buildCustomSearchFields() {
21 id(new PhabricatorSearchSelectField())
22 ->setLabel(pht('Status'))
24 ->setOptions(PhabricatorMacroQuery
::getStatusOptions()),
25 id(new PhabricatorUsersSearchField())
26 ->setLabel(pht('Authors'))
27 ->setKey('authorPHIDs')
28 ->setAliases(array('author', 'authors')),
29 id(new PhabricatorSearchTextField())
30 ->setLabel(pht('Name Contains'))
32 id(new PhabricatorSearchStringListField())
33 ->setLabel(pht('Exact Names'))
35 id(new PhabricatorSearchSelectField())
36 ->setLabel(pht('Marked with Flag'))
39 ->setOptions(PhabricatorMacroQuery
::getFlagColorsOptions()),
40 id(new PhabricatorSearchDateField())
41 ->setLabel(pht('Created After'))
42 ->setKey('createdStart'),
43 id(new PhabricatorSearchDateField())
44 ->setLabel(pht('Created Before'))
45 ->setKey('createdEnd'),
49 protected function getDefaultFieldOrder() {
57 protected function buildQueryFromParameters(array $map) {
58 $query = $this->newQuery();
60 if ($map['authorPHIDs']) {
61 $query->withAuthorPHIDs($map['authorPHIDs']);
65 $query->withStatus($map['status']);
69 $query->withNames($map['names']);
72 if (strlen($map['nameLike'])) {
73 $query->withNameLike($map['nameLike']);
76 if ($map['createdStart']) {
77 $query->withDateCreatedAfter($map['createdStart']);
80 if ($map['createdEnd']) {
81 $query->withDateCreatedBefore($map['createdEnd']);
84 if ($map['flagColor'] !== null) {
85 $query->withFlagColor($map['flagColor']);
91 protected function getURI($path) {
92 return '/macro/'.$path;
95 protected function getBuiltinQueryNames() {
97 'active' => pht('Active'),
101 if ($this->requireViewer()->isLoggedIn()) {
102 $names['authored'] = pht('Authored');
108 public function buildSavedQueryFromBuiltin($query_key) {
109 $query = $this->newSavedQuery();
110 $query->setQueryKey($query_key);
112 switch ($query_key) {
114 return $query->setParameter(
116 PhabricatorMacroQuery
::STATUS_ACTIVE
);
118 return $query->setParameter(
120 PhabricatorMacroQuery
::STATUS_ANY
);
122 return $query->setParameter(
124 array($this->requireViewer()->getPHID()));
127 return parent
::buildSavedQueryFromBuiltin($query_key);
130 protected function renderResultList(
132 PhabricatorSavedQuery
$query,
135 assert_instances_of($macros, 'PhabricatorFileImageMacro');
136 $viewer = $this->requireViewer();
137 $handles = $viewer->loadHandles(mpull($macros, 'getAuthorPHID'));
139 $xform = PhabricatorFileTransform
::getTransformByKey(
140 PhabricatorFileThumbnailTransform
::TRANSFORM_PINBOARD
);
142 $pinboard = new PHUIPinboardView();
143 foreach ($macros as $macro) {
144 $file = $macro->getFile();
146 $item = id(new PHUIPinboardItemView())
151 $item->setImageURI($file->getURIForTransform($xform));
152 list($x, $y) = $xform->getTransformedDimensions($file);
153 $item->setImageSize($x, $y);
156 if ($macro->getDateCreated()) {
157 $datetime = phabricator_date($macro->getDateCreated(), $viewer);
162 pht('Created on %s', $datetime)));
164 // Very old macros don't have a creation date. Rendering something
165 // keeps all the pins at the same height and avoids flow issues.
170 pht('Created in ages long past')));
173 if ($macro->getAuthorPHID()) {
174 $author_handle = $handles[$macro->getAuthorPHID()];
176 pht('Created by %s', $author_handle->renderLink()));
179 $item->setURI($this->getApplicationURI('/view/'.$macro->getID().'/'));
180 $item->setDisabled($macro->getisDisabled());
181 $item->setHeader($macro->getName());
183 $pinboard->addItem($item);
186 $result = new PhabricatorApplicationSearchResultView();
187 $result->setContent($pinboard);
192 protected function getNewUserBody() {
193 $create_button = id(new PHUIButtonView())
195 ->setText(pht('Create a Macro'))
196 ->setHref('/macro/create/')
197 ->setColor(PHUIButtonView
::GREEN
);
199 $icon = $this->getApplication()->getIcon();
200 $app_name = $this->getApplication()->getName();
201 $view = id(new PHUIBigInfoView())
203 ->setTitle(pht('Welcome to %s', $app_name))
205 pht('Create easy to remember shortcuts to images and memes.'))
206 ->addAction($create_button);