This repository has been archived by the owner on Mar 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
DownloadController.php
97 lines (82 loc) · 2.91 KB
/
DownloadController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* DownloadController.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
namespace AppBundle\Controller;
use eZ\Publish\Core\MVC\Symfony\View\ContentView;
use eZ\Publish\API\Repository\SearchService as SearchServiceInterface;
use AppBundle\QueryType\LatestReleasesQueryType;
/**
* Class DownloadController.
*/
class DownloadController
{
/** @var int */
private $releasesFolderLocationId;
/** @var int */
private $betasFolderLocationId;
/** @var \eZ\Publish\API\Repository\SearchService */
private $searchService;
/** @var \AppBundle\QueryType\LatestReleasesQueryType */
private $latestReleasesQueryType;
/**
* @param \eZ\Publish\API\Repository\SearchService $searchService
* @param \AppBundle\QueryType\LatestReleasesQueryType $latestReleasesQueryType
* @param int $releasesFolderLocationId
* @param int $betasFolderLocationId
*/
public function __construct(
SearchServiceInterface $searchService,
LatestReleasesQueryType $latestReleasesQueryType,
int $releasesFolderLocationId,
int $betasFolderLocationId
) {
$this->searchService = $searchService;
$this->latestReleasesQueryType = $latestReleasesQueryType;
$this->releasesFolderLocationId = $releasesFolderLocationId;
$this->betasFolderLocationId = $betasFolderLocationId;
}
/**
* Renders view for the Download section including all the eZ Platform releases.
*
* @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view
*
* @return \eZ\Publish\Core\MVC\Symfony\View\ContentView
*
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*/
public function showAction(ContentView $view): ContentView
{
$view->addParameters([
'releases' => $this->getSearchResults($this->releasesFolderLocationId),
'betas' => $this->getSearchResults($this->betasFolderLocationId),
]);
return $view;
}
/**
* Returns releases search results for the given $parentLocationId.
*
* @param int $parentLocationId
*
* @return array
*
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*/
private function getSearchResults(int $parentLocationId): array
{
$query = $this->latestReleasesQueryType->getQuery([
'parent_location_id' => $parentLocationId,
]);
$searchResults = $this->searchService->findContent($query);
$results = [];
foreach ($searchResults->searchHits as $hit) {
$results[$hit->valueObject->getFieldValue('release_version')->__toString()] = $hit->valueObject;
}
uksort($results, 'version_compare');
return array_reverse($results);
}
}