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 TYPO3\CMS\Core\Database\DatabaseConnection; |
30
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
31
|
|
|
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager; |
32
|
|
|
use TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface; |
33
|
|
|
use TYPO3\CMS\Extbase\Persistence\QueryInterface; |
34
|
|
|
use TYPO3\CMS\Extbase\Persistence\Repository; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* The repository for GolfCourses |
38
|
|
|
*/ |
39
|
|
|
class GolfCourseRepository extends Repository |
40
|
|
|
{ |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param $countryUid |
44
|
|
|
* |
45
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
46
|
|
|
*/ |
47
|
|
|
public function findAllInCountry($countryUid) |
48
|
|
|
{ |
49
|
|
|
/** @var QueryInterface $query */ |
50
|
|
|
$query = $this->createQuery(); |
51
|
|
|
|
52
|
|
|
$querySettings = $query->getQuerySettings(); |
53
|
|
|
$querySettings->setRespectStoragePage(false); |
54
|
|
|
$querySettings->setIgnoreEnableFields(false); |
55
|
|
|
|
56
|
|
|
$query->matching($query->equals('country', $countryUid)); |
57
|
|
|
$query->setOrderings(['name' => 'ASC']); |
58
|
|
|
$query->setQuerySettings($querySettings); |
59
|
|
|
|
60
|
|
|
return $query->execute(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return array |
65
|
|
|
*/ |
66
|
|
|
public function findCountriesUidsInUse() |
67
|
|
|
{ |
68
|
|
|
$uids = []; |
69
|
|
|
$courses = $this->getDatabaseConnection()->exec_SELECTquery( |
70
|
|
|
'DISTINCT country', |
71
|
|
|
'tx_golfcourses_domain_model_golfcourse', |
72
|
|
|
'' |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
foreach ($courses as $course) { |
|
|
|
|
76
|
|
|
$uids[] = $course['country']; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return $uids; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
84
|
|
|
*/ |
85
|
|
|
public function findCountriesWithOutCoordinates() |
86
|
|
|
{ |
87
|
|
|
/** @var QueryInterface $query */ |
88
|
|
|
$query = $this->createQuery(); |
89
|
|
|
$query->setLimit(5); |
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
|
|
|
/** |
129
|
|
|
* @return DatabaseConnection |
130
|
|
|
*/ |
131
|
|
|
protected function getDatabaseConnection() |
|
|
|
|
132
|
|
|
{ |
133
|
|
|
return $GLOBALS['TYPO3_DB']; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.