[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/files/query/ -> PhabricatorFileSearchEngine.php (source)

   1  <?php
   2  
   3  final class PhabricatorFileSearchEngine
   4    extends PhabricatorApplicationSearchEngine {
   5  
   6    public function getResultTypeDescription() {
   7      return pht('Files');
   8    }
   9  
  10    public function getApplicationClassName() {
  11      return 'PhabricatorFilesApplication';
  12    }
  13  
  14    public function buildSavedQueryFromRequest(AphrontRequest $request) {
  15      $saved = new PhabricatorSavedQuery();
  16      $saved->setParameter(
  17        'authorPHIDs',
  18        $this->readUsersFromRequest($request, 'authors'));
  19  
  20      $saved->setParameter('explicit', $request->getBool('explicit'));
  21      $saved->setParameter('createdStart', $request->getStr('createdStart'));
  22      $saved->setParameter('createdEnd', $request->getStr('createdEnd'));
  23  
  24      return $saved;
  25    }
  26  
  27    public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
  28      $query = id(new PhabricatorFileQuery())
  29        ->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()));
  30  
  31      if ($saved->getParameter('explicit')) {
  32        $query->showOnlyExplicitUploads(true);
  33      }
  34  
  35      $start = $this->parseDateTime($saved->getParameter('createdStart'));
  36      $end = $this->parseDateTime($saved->getParameter('createdEnd'));
  37  
  38      if ($start) {
  39        $query->withDateCreatedAfter($start);
  40      }
  41  
  42      if ($end) {
  43        $query->withDateCreatedBefore($end);
  44      }
  45  
  46      return $query;
  47    }
  48  
  49    public function buildSearchForm(
  50      AphrontFormView $form,
  51      PhabricatorSavedQuery $saved_query) {
  52  
  53      $phids = $saved_query->getParameter('authorPHIDs', array());
  54      $author_handles = id(new PhabricatorHandleQuery())
  55        ->setViewer($this->requireViewer())
  56        ->withPHIDs($phids)
  57        ->execute();
  58  
  59      $explicit = $saved_query->getParameter('explicit');
  60  
  61      $form
  62        ->appendChild(
  63          id(new AphrontFormTokenizerControl())
  64            ->setDatasource(new PhabricatorPeopleDatasource())
  65            ->setName('authors')
  66            ->setLabel(pht('Authors'))
  67            ->setValue($author_handles))
  68        ->appendChild(
  69          id(new AphrontFormCheckboxControl())
  70            ->addCheckbox(
  71              'explicit',
  72              1,
  73              pht('Show only manually uploaded files.'),
  74              $explicit));
  75  
  76      $this->buildDateRange(
  77        $form,
  78        $saved_query,
  79        'createdStart',
  80        pht('Created After'),
  81        'createdEnd',
  82        pht('Created Before'));
  83    }
  84  
  85    protected function getURI($path) {
  86      return '/file/'.$path;
  87    }
  88  
  89    public function getBuiltinQueryNames() {
  90      $names = array();
  91  
  92      if ($this->requireViewer()->isLoggedIn()) {
  93        $names['authored'] = pht('Authored');
  94      }
  95  
  96      $names += array(
  97        'all' => pht('All'),
  98      );
  99  
 100      return $names;
 101    }
 102  
 103    public function buildSavedQueryFromBuiltin($query_key) {
 104      $query = $this->newSavedQuery();
 105      $query->setQueryKey($query_key);
 106  
 107      switch ($query_key) {
 108        case 'all':
 109          return $query;
 110        case 'authored':
 111          $author_phid = array($this->requireViewer()->getPHID());
 112          return $query
 113            ->setParameter('authorPHIDs', $author_phid)
 114            ->setParameter('explicit', true);
 115      }
 116  
 117      return parent::buildSavedQueryFromBuiltin($query_key);
 118    }
 119  
 120    protected function getRequiredHandlePHIDsForResultList(
 121      array $files,
 122      PhabricatorSavedQuery $query) {
 123      return mpull($files, 'getAuthorPHID');
 124    }
 125  
 126    protected function renderResultList(
 127      array $files,
 128      PhabricatorSavedQuery $query,
 129      array $handles) {
 130  
 131      assert_instances_of($files, 'PhabricatorFile');
 132  
 133      $request = $this->getRequest();
 134      if ($request) {
 135        $highlighted_ids = $request->getStrList('h');
 136      } else {
 137        $highlighted_ids = array();
 138      }
 139  
 140      $viewer = $this->requireViewer();
 141  
 142      $highlighted_ids = array_fill_keys($highlighted_ids, true);
 143  
 144      $list_view = id(new PHUIObjectItemListView())
 145        ->setUser($viewer);
 146  
 147      foreach ($files as $file) {
 148        $id = $file->getID();
 149        $phid = $file->getPHID();
 150        $name = $file->getName();
 151        $file_uri = $this->getApplicationURI("/info/{$phid}/");
 152  
 153        $date_created = phabricator_date($file->getDateCreated(), $viewer);
 154        $author_phid = $file->getAuthorPHID();
 155        if ($author_phid) {
 156          $author_link = $handles[$author_phid]->renderLink();
 157          $uploaded = pht('Uploaded by %s on %s', $author_link, $date_created);
 158        } else {
 159          $uploaded = pht('Uploaded on %s', $date_created);
 160        }
 161  
 162        $item = id(new PHUIObjectItemView())
 163          ->setObject($file)
 164          ->setObjectName("F{$id}")
 165          ->setHeader($name)
 166          ->setHref($file_uri)
 167          ->addAttribute($uploaded)
 168          ->addIcon('none', phutil_format_bytes($file->getByteSize()));
 169  
 170        $ttl = $file->getTTL();
 171        if ($ttl !== null) {
 172          $item->addIcon('blame', pht('Temporary'));
 173        }
 174  
 175        if (isset($highlighted_ids[$id])) {
 176          $item->setEffect('highlighted');
 177        }
 178  
 179        $list_view->addItem($item);
 180      }
 181  
 182      $list_view->appendChild(id(new PhabricatorGlobalUploadTargetView())
 183        ->setUser($viewer));
 184  
 185      return $list_view;
 186    }
 187  
 188  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1