3 final class PhabricatorFileSearchEngine
4 extends PhabricatorApplicationSearchEngine
{
6 public function getResultTypeDescription() {
10 public function getApplicationClassName() {
11 return 'PhabricatorFilesApplication';
14 public function canUseInPanelContext() {
18 public function newQuery() {
19 $query = new PhabricatorFileQuery();
20 $query->withIsDeleted(false);
24 protected function buildCustomSearchFields() {
26 id(new PhabricatorUsersSearchField())
27 ->setKey('authorPHIDs')
28 ->setAliases(array('author', 'authors'))
29 ->setLabel(pht('Authors')),
30 id(new PhabricatorSearchThreeStateField())
32 ->setLabel(pht('Upload Source'))
35 pht('Show Only Manually Uploaded Files'),
36 pht('Hide Manually Uploaded Files')),
37 id(new PhabricatorSearchDateField())
38 ->setKey('createdStart')
39 ->setLabel(pht('Created After')),
40 id(new PhabricatorSearchDateField())
41 ->setKey('createdEnd')
42 ->setLabel(pht('Created Before')),
43 id(new PhabricatorSearchTextField())
44 ->setLabel(pht('Name Contains'))
46 ->setDescription(pht('Search for files by name substring.')),
50 protected function getDefaultFieldOrder() {
58 protected function buildQueryFromParameters(array $map) {
59 $query = $this->newQuery();
61 if ($map['authorPHIDs']) {
62 $query->withAuthorPHIDs($map['authorPHIDs']);
65 if ($map['explicit'] !== null) {
66 $query->showOnlyExplicitUploads($map['explicit']);
69 if ($map['createdStart']) {
70 $query->withDateCreatedAfter($map['createdStart']);
73 if ($map['createdEnd']) {
74 $query->withDateCreatedBefore($map['createdEnd']);
77 if ($map['name'] !== null) {
78 $query->withNameNgrams($map['name']);
84 protected function getURI($path) {
85 return '/file/'.$path;
88 protected function getBuiltinQueryNames() {
91 if ($this->requireViewer()->isLoggedIn()) {
92 $names['authored'] = pht('Authored');
102 public function buildSavedQueryFromBuiltin($query_key) {
103 $query = $this->newSavedQuery();
104 $query->setQueryKey($query_key);
106 switch ($query_key) {
110 $author_phid = array($this->requireViewer()->getPHID());
112 ->setParameter('authorPHIDs', $author_phid)
113 ->setParameter('explicit', true);
116 return parent
::buildSavedQueryFromBuiltin($query_key);
119 protected function getRequiredHandlePHIDsForResultList(
121 PhabricatorSavedQuery
$query) {
122 return mpull($files, 'getAuthorPHID');
125 protected function renderResultList(
127 PhabricatorSavedQuery
$query,
130 assert_instances_of($files, 'PhabricatorFile');
132 $request = $this->getRequest();
134 $highlighted_ids = $request->getStrList('h');
136 $highlighted_ids = array();
139 $viewer = $this->requireViewer();
141 $highlighted_ids = array_fill_keys($highlighted_ids, true);
143 $list_view = id(new PHUIObjectItemListView())
146 foreach ($files as $file) {
147 $id = $file->getID();
148 $phid = $file->getPHID();
149 $name = $file->getName();
150 $file_uri = $this->getApplicationURI("/info/{$phid}/");
152 $date_created = phabricator_date($file->getDateCreated(), $viewer);
153 $author_phid = $file->getAuthorPHID();
155 $author_link = $handles[$author_phid]->renderLink();
156 $uploaded = pht('Uploaded by %s on %s', $author_link, $date_created);
158 $uploaded = pht('Uploaded on %s', $date_created);
161 $item = id(new PHUIObjectItemView())
163 ->setObjectName("F{$id}")
166 ->addAttribute($uploaded)
167 ->addIcon('none', phutil_format_bytes($file->getByteSize()));
169 $ttl = $file->getTTL();
171 $item->addIcon('blame', pht('Temporary'));
174 if ($file->getIsPartial()) {
175 $item->addIcon('fa-exclamation-triangle orange', pht('Partial'));
178 if (isset($highlighted_ids[$id])) {
179 $item->setEffect('highlighted');
182 $list_view->addItem($item);
185 $list_view->appendChild(id(new PhabricatorGlobalUploadTargetView())
189 $result = new PhabricatorApplicationSearchResultView();
190 $result->setContent($list_view);
195 protected function getNewUserBody() {
196 $create_button = id(new PHUIButtonView())
198 ->setText(pht('Upload a File'))
199 ->setHref('/file/upload/')
200 ->setColor(PHUIButtonView
::GREEN
);
202 $icon = $this->getApplication()->getIcon();
203 $app_name = $this->getApplication()->getName();
204 $view = id(new PHUIBigInfoView())
206 ->setTitle(pht('Welcome to %s', $app_name))
208 pht('Just a place for files.'))
209 ->addAction($create_button);