[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/meta/query/ -> PhabricatorAppSearchEngine.php (source)

   1  <?php
   2  
   3  final class PhabricatorAppSearchEngine
   4    extends PhabricatorApplicationSearchEngine {
   5  
   6    public function getResultTypeDescription() {
   7      return pht('Applications');
   8    }
   9  
  10    public function getApplicationClassName() {
  11      return 'PhabricatorApplicationsApplication';
  12    }
  13  
  14    public function getPageSize(PhabricatorSavedQuery $saved) {
  15      return INF;
  16    }
  17  
  18    public function buildSavedQueryFromRequest(AphrontRequest $request) {
  19      $saved = new PhabricatorSavedQuery();
  20  
  21      $saved->setParameter('name', $request->getStr('name'));
  22  
  23      $saved->setParameter(
  24        'installed',
  25        $this->readBoolFromRequest($request, 'installed'));
  26      $saved->setParameter(
  27        'prototypes',
  28        $this->readBoolFromRequest($request, 'prototypes'));
  29      $saved->setParameter(
  30        'firstParty',
  31        $this->readBoolFromRequest($request, 'firstParty'));
  32      $saved->setParameter(
  33        'launchable',
  34        $this->readBoolFromRequest($request, 'launchable'));
  35  
  36      return $saved;
  37    }
  38  
  39    public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
  40      $query = id(new PhabricatorApplicationQuery())
  41        ->setOrder(PhabricatorApplicationQuery::ORDER_NAME)
  42        ->withUnlisted(false);
  43  
  44      $name = $saved->getParameter('name');
  45      if (strlen($name)) {
  46        $query->withNameContains($name);
  47      }
  48  
  49      $installed = $saved->getParameter('installed');
  50      if ($installed !== null) {
  51        $query->withInstalled($installed);
  52      }
  53  
  54      $prototypes = $saved->getParameter('prototypes');
  55  
  56      if ($prototypes === null) {
  57        // NOTE: This is the old name of the 'prototypes' option, see T6084.
  58        $prototypes = $saved->getParameter('beta');
  59        $saved->setParameter('prototypes', $prototypes);
  60      }
  61  
  62      if ($prototypes !== null) {
  63        $query->withPrototypes($prototypes);
  64      }
  65  
  66      $first_party = $saved->getParameter('firstParty');
  67      if ($first_party !== null) {
  68        $query->withFirstParty($first_party);
  69      }
  70  
  71      $launchable = $saved->getParameter('launchable');
  72      if ($launchable !== null) {
  73        $query->withLaunchable($launchable);
  74      }
  75  
  76      return $query;
  77    }
  78  
  79    public function buildSearchForm(
  80      AphrontFormView $form,
  81      PhabricatorSavedQuery $saved) {
  82  
  83      $form
  84        ->appendChild(
  85          id(new AphrontFormTextControl())
  86            ->setLabel(pht('Name Contains'))
  87            ->setName('name')
  88            ->setValue($saved->getParameter('name')))
  89        ->appendChild(
  90          id(new AphrontFormSelectControl())
  91            ->setLabel(pht('Installed'))
  92            ->setName('installed')
  93            ->setValue($this->getBoolFromQuery($saved, 'installed'))
  94            ->setOptions(
  95              array(
  96                '' => pht('Show All Applications'),
  97                'true' => pht('Show Installed Applications'),
  98                'false' => pht('Show Uninstalled Applications'),
  99              )))
 100        ->appendChild(
 101          id(new AphrontFormSelectControl())
 102            ->setLabel(pht('Prototypes'))
 103            ->setName('prototypes')
 104            ->setValue($this->getBoolFromQuery($saved, 'prototypes'))
 105            ->setOptions(
 106              array(
 107                '' => pht('Show All Applications'),
 108                'true' => pht('Show Prototype Applications'),
 109                'false' => pht('Show Released Applications'),
 110              )))
 111        ->appendChild(
 112          id(new AphrontFormSelectControl())
 113            ->setLabel(pht('Provenance'))
 114            ->setName('firstParty')
 115            ->setValue($this->getBoolFromQuery($saved, 'firstParty'))
 116            ->setOptions(
 117              array(
 118                '' => pht('Show All Applications'),
 119                'true' => pht('Show First-Party Applications'),
 120                'false' => pht('Show Third-Party Applications'),
 121              )))
 122        ->appendChild(
 123          id(new AphrontFormSelectControl())
 124            ->setLabel(pht('Launchable'))
 125            ->setName('launchable')
 126            ->setValue($this->getBoolFromQuery($saved, 'launchable'))
 127            ->setOptions(
 128              array(
 129                '' => pht('Show All Applications'),
 130                'true' => pht('Show Launchable Applications'),
 131                'false' => pht('Show Non-Launchable Applications'),
 132              )));
 133    }
 134  
 135    protected function getURI($path) {
 136      return '/applications/'.$path;
 137    }
 138  
 139    public function getBuiltinQueryNames() {
 140      return array(
 141        'launcher' => pht('Launcher'),
 142        'all' => pht('All Applications'),
 143      );
 144    }
 145  
 146    public function buildSavedQueryFromBuiltin($query_key) {
 147      $query = $this->newSavedQuery();
 148      $query->setQueryKey($query_key);
 149  
 150      switch ($query_key) {
 151        case 'launcher':
 152          return $query
 153            ->setParameter('installed', true)
 154            ->setParameter('launchable', true);
 155        case 'all':
 156          return $query;
 157      }
 158  
 159      return parent::buildSavedQueryFromBuiltin($query_key);
 160    }
 161  
 162    protected function renderResultList(
 163      array $all_applications,
 164      PhabricatorSavedQuery $query,
 165      array $handle) {
 166      assert_instances_of($all_applications, 'PhabricatorApplication');
 167  
 168      $all_applications = msort($all_applications, 'getName');
 169  
 170      if ($query->getQueryKey() == 'launcher') {
 171        $groups = mgroup($all_applications, 'getApplicationGroup');
 172      } else {
 173        $groups = array($all_applications);
 174      }
 175  
 176      $group_names = PhabricatorApplication::getApplicationGroups();
 177      $groups = array_select_keys($groups, array_keys($group_names)) + $groups;
 178  
 179      $results = array();
 180      foreach ($groups as $group => $applications) {
 181        if (count($groups) > 1) {
 182          $results[] = phutil_tag(
 183            'h1',
 184            array(
 185              'class' => 'launcher-header',
 186            ),
 187            idx($group_names, $group, $group));
 188        }
 189  
 190        $list = new PHUIObjectItemListView();
 191        $list->addClass('phui-object-item-launcher-list');
 192  
 193        foreach ($applications as $application) {
 194          $icon = $application->getIconName();
 195          if (!$icon) {
 196            $icon = 'application';
 197          }
 198  
 199          // TODO: This sheet doesn't work the same way other sheets do so it
 200          // ends up with the wrong classes if we try to use PHUIIconView. This
 201          // is probably all changing in the redesign anyway.
 202  
 203          $icon_view = javelin_tag(
 204            'span',
 205            array(
 206              'class' => 'phui-icon-view '.
 207                         'sprite-apps-large apps-'.$icon.'-dark-large',
 208              'aural' => false,
 209            ),
 210            '');
 211  
 212          $description = phutil_tag(
 213            'div',
 214            array(
 215              'style' => 'white-space: nowrap; '.
 216                         'overflow: hidden; '.
 217                         'text-overflow: ellipsis;',
 218            ),
 219            $application->getShortDescription());
 220  
 221          $item = id(new PHUIObjectItemView())
 222            ->setHeader($application->getName())
 223            ->setImageIcon($icon_view)
 224            ->addAttribute($description)
 225            ->addAction(
 226              id(new PHUIListItemView())
 227                ->setName(pht('Help/Options'))
 228                ->setIcon('fa-cog')
 229                ->setHref('/applications/view/'.get_class($application).'/'));
 230  
 231          if ($application->getBaseURI()) {
 232            $item->setHref($application->getBaseURI());
 233          }
 234  
 235          if (!$application->isInstalled()) {
 236            $item->addIcon('fa-times', pht('Uninstalled'));
 237          }
 238  
 239          if ($application->isPrototype()) {
 240            $item->addIcon('fa-bomb grey', pht('Prototype'));
 241          }
 242  
 243          if (!$application->isFirstParty()) {
 244            $item->addIcon('fa-puzzle-piece', pht('Extension'));
 245          }
 246  
 247          $list->addItem($item);
 248        }
 249  
 250        $results[] = $list;
 251      }
 252  
 253      return $results;
 254    }
 255  
 256  }


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