GolfCourseRepository::findAllActive()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
namespace TNM\GolfCourses\Domain\Repository;
3
4
/***************************************************************
5
 *
6
 *  Copyright notice
7
 *
8
 *  (c) 2016 Tomas Norre Mikkelsen <[email protected]>
9
 *
10
 *  All rights reserved
11
 *
12
 *  This script is part of the TYPO3 project. The TYPO3 project is
13
 *  free software; you can redistribute it and/or modify
14
 *  it under the terms of the GNU General Public License as published by
15
 *  the Free Software Foundation; either version 3 of the License, or
16
 *  (at your option) any later version.
17
 *
18
 *  The GNU General Public License can be found at
19
 *  http://www.gnu.org/copyleft/gpl.html.
20
 *
21
 *  This script is distributed in the hope that it will be useful,
22
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 *  GNU General Public License for more details.
25
 *
26
 *  This copyright notice MUST APPEAR in all copies of the script!
27
 ***************************************************************/
28
29
use TNM\GolfCourses\Domain\Model\GolfCourse;
30
use TYPO3\CMS\Core\Utility\GeneralUtility;
31
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
32
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
33
use TYPO3\CMS\Extbase\Persistence\Repository;
34
35
/**
36
 * The repository for GolfCourses
37
 */
38
class GolfCourseRepository extends Repository
39
{
40
41
    /**
42
     * @param $countryUid
43
     *
44
     * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
45
     */
46
    public function findAllInCountry($countryUid)
47
    {
48
        /** @var QueryInterface $query */
49
        $query = $this->createQuery();
50
51
        $querySettings = $query->getQuerySettings();
52
        $querySettings->setRespectStoragePage(false);
53
        $querySettings->setIgnoreEnableFields(false);
54
55
        $query->matching($query->equals('country', $countryUid));
56
        $query->setOrderings(['name' => 'ASC']);
57
        $query->setQuerySettings($querySettings);
58
59
        return $query->execute();
60
    }
61
62
    /**
63
     * @return array
64
     */
65
    public function findCountriesUidsInUse()
66
    {
67
        $uids = [];
68
69
        $courses = $this->findAllActive();
70
        /** @var GolfCourse $course */
71
        foreach ($courses as $course) {
72
            array_push($uids, $course->getCountry());
73
        }
74
75
        return array_unique($uids);
76
    }
77
78
    /**
79
     * @param int $limit
80
     *
81
     * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
82
     */
83
    public function findCountriesWithOutCoordinates(int $limit = 10)
84
    {
85
        /** @var QueryInterface $query */
86
        $query = $this->createQuery();
87
        $query->setLimit($limit);
88
89
        $querySettings = $query->getQuerySettings();
90
        $querySettings->setRespectStoragePage(false);
91
        $querySettings->setIgnoreEnableFields(false);
92
93
        $query->matching($query->equals('longitude', ''));
94
        $query->matching($query->equals('latitude', ''));
95
        $query->setQuerySettings($querySettings);
96
97
        return $query->execute();
98
    }
99
100
    /**
101
     * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
102
     */
103
    public function findAllActive()
104
    {
105
        $query = $this->createQuery();
106
107
        $querySettings = $query->getQuerySettings();
108
        $querySettings->setRespectStoragePage(false);
109
        $querySettings->setIgnoreEnableFields(false);
110
        $query->setQuerySettings($querySettings);
111
112
        return $query->execute();
113
    }
114
115
    /**
116
     * Persist All
117
     */
118
    public function persistAll()
119
    {
120
        /** @var PersistenceManager $persistenceManager */
121
        $persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class);
122
        $persistenceManager->persistAll();
123
    }
124
}
125