Join
6 years ago
ComputedMetricFactory.php
6 years ago
Dimension.php
6 years ago
DimensionMetricFactory.php
6 years ago
DimensionsProvider.php
6 years ago
Discriminator.php
6 years ago
Join.php
6 years ago
MetricsList.php
6 years ago
Updater.php
6 years ago
DimensionsProvider.php
62 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Piwik - free/libre analytics platform |
| 4 | * |
| 5 | * @link https://matomo.org |
| 6 | * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 7 | * |
| 8 | */ |
| 9 | namespace Piwik\Columns; |
| 10 | |
| 11 | use Piwik\CacheId; |
| 12 | use Piwik\Cache as PiwikCache; |
| 13 | |
| 14 | class DimensionsProvider |
| 15 | { |
| 16 | /** |
| 17 | * @param $dimensionId |
| 18 | * @return Dimension |
| 19 | */ |
| 20 | public function factory($dimensionId) |
| 21 | { |
| 22 | $listDimensions = self::getMapOfNameToDimension(); |
| 23 | |
| 24 | if (empty($listDimensions) || !is_array($listDimensions) || !$dimensionId || !array_key_exists($dimensionId, $listDimensions)) { |
| 25 | return null; |
| 26 | } |
| 27 | |
| 28 | return $listDimensions[$dimensionId]; |
| 29 | } |
| 30 | |
| 31 | private static function getMapOfNameToDimension() |
| 32 | { |
| 33 | $cacheId = CacheId::siteAware(CacheId::pluginAware('DimensionFactoryMap')); |
| 34 | |
| 35 | $cache = PiwikCache::getTransientCache(); |
| 36 | if ($cache->contains($cacheId)) { |
| 37 | $mapIdToDimension = $cache->fetch($cacheId); |
| 38 | } else { |
| 39 | $dimensions = new static(); |
| 40 | $dimensions = $dimensions->getAllDimensions(); |
| 41 | |
| 42 | $mapIdToDimension = array(); |
| 43 | foreach ($dimensions as $dimension) { |
| 44 | $mapIdToDimension[$dimension->getId()] = $dimension; |
| 45 | } |
| 46 | |
| 47 | $cache->save($cacheId, $mapIdToDimension); |
| 48 | } |
| 49 | |
| 50 | return $mapIdToDimension; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Returns a list of all available dimensions. |
| 55 | * @return Dimension[] |
| 56 | */ |
| 57 | public function getAllDimensions() |
| 58 | { |
| 59 | return Dimension::getAllDimensions(); |
| 60 | } |
| 61 | |
| 62 | } |