[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

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

   1  <?php
   2  
   3  final class PhabricatorApplicationQuery
   4    extends PhabricatorCursorPagedPolicyAwareQuery {
   5  
   6    private $installed;
   7    private $prototypes;
   8    private $firstParty;
   9    private $nameContains;
  10    private $unlisted;
  11    private $classes;
  12    private $launchable;
  13    private $phids;
  14  
  15    const ORDER_APPLICATION = 'order:application';
  16    const ORDER_NAME = 'order:name';
  17  
  18    private $order = self::ORDER_APPLICATION;
  19  
  20    public function withNameContains($name_contains) {
  21      $this->nameContains = $name_contains;
  22      return $this;
  23    }
  24  
  25    public function withInstalled($installed) {
  26      $this->installed = $installed;
  27      return $this;
  28    }
  29  
  30    public function withPrototypes($prototypes) {
  31      $this->prototypes = $prototypes;
  32      return $this;
  33    }
  34  
  35    public function withFirstParty($first_party) {
  36      $this->firstParty = $first_party;
  37      return $this;
  38    }
  39  
  40    public function withUnlisted($unlisted) {
  41      $this->unlisted = $unlisted;
  42      return $this;
  43    }
  44  
  45    public function withLaunchable($launchable) {
  46      $this->launchable = $launchable;
  47      return $this;
  48    }
  49  
  50    public function withClasses(array $classes) {
  51      $this->classes = $classes;
  52      return $this;
  53    }
  54  
  55    public function withPHIDs(array $phids) {
  56      $this->phids = $phids;
  57      return $this;
  58    }
  59  
  60    public function setOrder($order) {
  61      $this->order = $order;
  62      return $this;
  63    }
  64  
  65    public function loadPage() {
  66      $apps = PhabricatorApplication::getAllApplications();
  67  
  68      if ($this->classes) {
  69        $classes = array_fuse($this->classes);
  70        foreach ($apps as $key => $app) {
  71          if (empty($classes[get_class($app)])) {
  72            unset($apps[$key]);
  73          }
  74        }
  75      }
  76  
  77      if ($this->phids) {
  78        $phids = array_fuse($this->phids);
  79        foreach ($apps as $key => $app) {
  80          if (empty($phids[$app->getPHID()])) {
  81            unset($apps[$key]);
  82          }
  83        }
  84      }
  85  
  86      if (strlen($this->nameContains)) {
  87        foreach ($apps as $key => $app) {
  88          if (stripos($app->getName(), $this->nameContains) === false) {
  89            unset($apps[$key]);
  90          }
  91        }
  92      }
  93  
  94      if ($this->installed !== null) {
  95        foreach ($apps as $key => $app) {
  96          if ($app->isInstalled() != $this->installed) {
  97            unset($apps[$key]);
  98          }
  99        }
 100      }
 101  
 102      if ($this->prototypes !== null) {
 103        foreach ($apps as $key => $app) {
 104          if ($app->isPrototype() != $this->prototypes) {
 105            unset($apps[$key]);
 106          }
 107        }
 108      }
 109  
 110      if ($this->firstParty !== null) {
 111        foreach ($apps as $key => $app) {
 112          if ($app->isFirstParty() != $this->firstParty) {
 113            unset($apps[$key]);
 114          }
 115        }
 116      }
 117  
 118      if ($this->unlisted !== null) {
 119        foreach ($apps as $key => $app) {
 120          if ($app->isUnlisted() != $this->unlisted) {
 121            unset($apps[$key]);
 122          }
 123        }
 124      }
 125  
 126      if ($this->launchable !== null) {
 127        foreach ($apps as $key => $app) {
 128          if ($app->isLaunchable() != $this->launchable) {
 129            unset($apps[$key]);
 130          }
 131        }
 132      }
 133  
 134  
 135      switch ($this->order) {
 136        case self::ORDER_NAME:
 137          $apps = msort($apps, 'getName');
 138          break;
 139        case self::ORDER_APPLICATION:
 140          $apps = $apps;
 141          break;
 142        default:
 143          throw new Exception(
 144            pht('Unknown order "%s"!', $this->order));
 145      }
 146  
 147      return $apps;
 148    }
 149  
 150  
 151    public function getQueryApplicationClass() {
 152      // NOTE: Although this belongs to the "Applications" application, trying
 153      // to filter its results just leaves us recursing indefinitely. Users
 154      // always have access to applications regardless of other policy settings
 155      // anyway.
 156      return null;
 157    }
 158  
 159  }


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