FeatureRepository.php 2.17 KB
Newer Older
Christian Knauf's avatar
Christian Knauf committed
1
<?php
Thomas Löffler's avatar
Thomas Löffler committed
2
declare(strict_types=1);
Christian Knauf's avatar
Christian Knauf committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
namespace T3o\Typo3Roadmap\Domain\Repository;

/**
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */

Thomas Löffler's avatar
Thomas Löffler committed
18
19
20
21
22
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use TYPO3\CMS\Extbase\Persistence\Repository;


Christian Knauf's avatar
Christian Knauf committed
23
24
25
/**
 * The repository for Features
 */
Thomas Löffler's avatar
Thomas Löffler committed
26
class FeatureRepository extends Repository
Christian Knauf's avatar
Christian Knauf committed
27
28
29
30
31
{

    /**
     * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
     */
Thomas Löffler's avatar
Thomas Löffler committed
32
    public function findAll(): QueryResultInterface
Christian Knauf's avatar
Christian Knauf committed
33
34
35
    {
        $query = $this->createQuery();
        $query->getQuerySettings()->setRespectStoragePage(false);
Thomas Löffler's avatar
Thomas Löffler committed
36
37
        $query->setOrderings(['typo3releaseminorversion.version' => QueryInterface::ORDER_DESCENDING]);

Christian Knauf's avatar
Christian Knauf committed
38
39
40
41
        return $query->execute();
    }

    /**
Thomas Löffler's avatar
Thomas Löffler committed
42
     * @param array $setting
Christian Knauf's avatar
Christian Knauf committed
43
44
     * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
     */
Thomas Löffler's avatar
Thomas Löffler committed
45
    public function findByFilter(array $setting): QueryResultInterface
Christian Knauf's avatar
Christian Knauf committed
46
47
48
    {
        $query = $this->createQuery();
        $query->getQuerySettings()->setRespectStoragePage(false);
Thomas Löffler's avatar
Thomas Löffler committed
49
        $query->setOrderings(['typo3releaseminorversion.version' => QueryInterface::ORDER_DESCENDING]);
Christian Knauf's avatar
Christian Knauf committed
50
51
52
53

        //We need at least min 1 filterConstraint
        $constraints[] = $query->greaterThan('uid', 0);

Thomas Löffler's avatar
Thomas Löffler committed
54
        if ($setting['majorversion'] !== '') {
Christian Knauf's avatar
Christian Knauf committed
55
56
            $constraints[] = $query->equals('typo3releasemajorversion', (int)$setting['majorversion']);
        }
Thomas Löffler's avatar
Thomas Löffler committed
57
        if ($setting['minorversion'] !== '') {
Christian Knauf's avatar
Christian Knauf committed
58
59
60
            $constraints[] = $query->equals('typo3releaseminorversion', (int)$setting['minorversion']);
        }

Thomas Löffler's avatar
Thomas Löffler committed
61
        if ($setting['featurearea'] !== '') {
Christian Knauf's avatar
Christian Knauf committed
62
63
64
65
66
67
68
69
            $constraints[] = $query->equals('featureArea', (int)$setting['featurearea']);
        }

        $query->matching($query->logicalAnd($constraints));

        return $query->execute();
    }
}