| @@ 9-56 (lines=48) @@ | ||
| 6 | use Ps2alerts\Api\Repository\Metrics\MapRepository; |
|
| 7 | use Ps2alerts\Api\QueryObjects\QueryObject; |
|
| 8 | ||
| 9 | class MapMetricsLoader extends AbstractMetricsLoader |
|
| 10 | { |
|
| 11 | /** |
|
| 12 | * @var \Ps2alerts\Api\Repository\Metrics\MapRepository |
|
| 13 | */ |
|
| 14 | protected $repository; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * Construct |
|
| 18 | * |
|
| 19 | * @param \Ps2alerts\Api\Repository\Metrics\MapRepository $repository |
|
| 20 | */ |
|
| 21 | public function __construct(MapRepository $repository) |
|
| 22 | { |
|
| 23 | $this->repository = $repository; |
|
| 24 | $this->setType('Map'); |
|
| 25 | $this->setCacheNamespace('Metrics:'); |
|
| 26 | } |
|
| 27 | ||
| 28 | /** |
|
| 29 | * Reads latest map result from an alert |
|
| 30 | * |
|
| 31 | * @param string $id |
|
| 32 | * |
|
| 33 | * @return array |
|
| 34 | */ |
|
| 35 | public function readLatest($id) |
|
| 36 | { |
|
| 37 | $redisKey = "{$this->getCacheNamespace()}{$id}:{$this->getType()}:latest"; |
|
| 38 | ||
| 39 | $queryObject = new QueryObject; |
|
| 40 | $queryObject->addWhere([ |
|
| 41 | 'col' => 'result', |
|
| 42 | 'value' => $id |
|
| 43 | ]); |
|
| 44 | ||
| 45 | $queryObject->setOrderBy('result'); |
|
| 46 | $queryObject->setOrderByDirection('desc'); |
|
| 47 | $queryObject->setLimit(1); |
|
| 48 | ||
| 49 | $this->setCacheExpireTime(60); |
|
| 50 | ||
| 51 | return $this->cacheAndReturn( |
|
| 52 | $this->repository->read($queryObject), |
|
| 53 | $redisKey |
|
| 54 | ); |
|
| 55 | } |
|
| 56 | } |
|
| 57 | ||
| @@ 9-52 (lines=44) @@ | ||
| 6 | use Ps2alerts\Api\Repository\Metrics\PlayerRepository; |
|
| 7 | use Ps2alerts\Api\QueryObjects\QueryObject; |
|
| 8 | ||
| 9 | class PlayerMetricsLoader extends AbstractMetricsLoader |
|
| 10 | { |
|
| 11 | /** |
|
| 12 | * @var \Ps2alerts\Api\Repository\Metrics\PlayerRepository |
|
| 13 | */ |
|
| 14 | protected $repository; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * Construct |
|
| 18 | * |
|
| 19 | * @param \Ps2alerts\Api\Repository\Metrics\PlayerRepository $repository |
|
| 20 | */ |
|
| 21 | public function __construct(PlayerRepository $repository) |
|
| 22 | { |
|
| 23 | $this->repository = $repository; |
|
| 24 | $this->setCacheNamespace('Metrics:'); |
|
| 25 | $this->setType('Player'); |
|
| 26 | } |
|
| 27 | ||
| 28 | /** |
|
| 29 | * {@inheritdoc} |
|
| 30 | */ |
|
| 31 | public function readSingle($id) |
|
| 32 | { |
|
| 33 | $redisKey = "{$this->getCacheNamespace()}{$id}:{$this->getType()}"; |
|
| 34 | ||
| 35 | if ($this->checkRedis($redisKey)) { |
|
| 36 | return $this->getFromRedis($redisKey); |
|
| 37 | } |
|
| 38 | ||
| 39 | $queryObject = new QueryObject; |
|
| 40 | $queryObject->addWhere([ |
|
| 41 | 'col' => 'result', |
|
| 42 | 'value' => $id |
|
| 43 | ]); |
|
| 44 | $queryObject->setOrderBy('playerKills'); |
|
| 45 | $queryObject->setOrderByDirection('desc'); |
|
| 46 | ||
| 47 | return $this->cacheAndReturn( |
|
| 48 | $this->repository->read($queryObject), |
|
| 49 | $redisKey |
|
| 50 | ); |
|
| 51 | } |
|
| 52 | } |
|
| 53 | ||