|
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\Database\DatabaseConnection; |
|
31
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
32
|
|
|
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager; |
|
33
|
|
|
use TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface; |
|
34
|
|
|
use TYPO3\CMS\Extbase\Persistence\QueryInterface; |
|
35
|
|
|
use TYPO3\CMS\Extbase\Persistence\Repository; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The repository for GolfCourses |
|
39
|
|
|
*/ |
|
40
|
|
|
class GolfCourseRepository extends Repository |
|
41
|
|
|
{ |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param $countryUid |
|
45
|
|
|
* |
|
46
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
|
47
|
|
|
*/ |
|
48
|
|
|
public function findAllInCountry($countryUid) |
|
49
|
|
|
{ |
|
50
|
|
|
/** @var QueryInterface $query */ |
|
51
|
|
|
$query = $this->createQuery(); |
|
52
|
|
|
|
|
53
|
|
|
$querySettings = $query->getQuerySettings(); |
|
54
|
|
|
$querySettings->setRespectStoragePage(false); |
|
55
|
|
|
$querySettings->setIgnoreEnableFields(false); |
|
56
|
|
|
|
|
57
|
|
|
$query->matching($query->equals('country', $countryUid)); |
|
58
|
|
|
$query->setOrderings(['name' => 'ASC']); |
|
59
|
|
|
$query->setQuerySettings($querySettings); |
|
60
|
|
|
|
|
61
|
|
|
return $query->execute(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return array |
|
66
|
|
|
*/ |
|
67
|
|
|
public function findCountriesUidsInUse() |
|
68
|
|
|
{ |
|
69
|
|
|
$uids = []; |
|
70
|
|
|
|
|
71
|
|
|
$courses = $this->findAllActive(); |
|
72
|
|
|
/** @var GolfCourse $course */ |
|
73
|
|
|
foreach ($courses as $course) { |
|
74
|
|
|
array_push($uids, $course->getCountry()); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return array_unique($uids); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param int $limit |
|
82
|
|
|
* |
|
83
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
|
84
|
|
|
*/ |
|
85
|
|
|
public function findCountriesWithOutCoordinates(int $limit = 10) |
|
86
|
|
|
{ |
|
87
|
|
|
/** @var QueryInterface $query */ |
|
88
|
|
|
$query = $this->createQuery(); |
|
89
|
|
|
$query->setLimit($limit); |
|
90
|
|
|
|
|
91
|
|
|
$querySettings = $query->getQuerySettings(); |
|
92
|
|
|
$querySettings->setRespectStoragePage(false); |
|
93
|
|
|
$querySettings->setIgnoreEnableFields(false); |
|
94
|
|
|
|
|
95
|
|
|
$query->matching($query->equals('longitude', '')); |
|
96
|
|
|
$query->matching($query->equals('latitude', '')); |
|
97
|
|
|
$query->setQuerySettings($querySettings); |
|
98
|
|
|
|
|
99
|
|
|
return $query->execute(); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
|
104
|
|
|
*/ |
|
105
|
|
|
public function findAllActive() |
|
106
|
|
|
{ |
|
107
|
|
|
$query = $this->createQuery(); |
|
108
|
|
|
|
|
109
|
|
|
$querySettings = $query->getQuerySettings(); |
|
110
|
|
|
$querySettings->setRespectStoragePage(false); |
|
111
|
|
|
$querySettings->setIgnoreEnableFields(true); |
|
112
|
|
|
$query->setQuerySettings($querySettings); |
|
113
|
|
|
|
|
114
|
|
|
return $query->execute(); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Persist All |
|
119
|
|
|
*/ |
|
120
|
|
|
public function persistAll() |
|
121
|
|
|
{ |
|
122
|
|
|
/** @var PersistenceManager $persistenceManager */ |
|
123
|
|
|
$persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class); |
|
124
|
|
|
$persistenceManager->persistAll(); |
|
125
|
|
|
|
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|