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
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The repository for GolfCourses |
37
|
|
|
*/ |
38
|
|
|
class GolfCourseRepository extends \TYPO3\CMS\Extbase\Persistence\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
|
|
|
$courses = $this->getDatabaseConnection()->exec_SELECTquery( |
69
|
|
|
'DISTINCT country', |
70
|
|
|
'tx_golfcourses_domain_model_golfcourse', |
71
|
|
|
'' |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
foreach ($courses as $course) { |
|
|
|
|
75
|
|
|
$uids[] = $course['country']; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $uids; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
83
|
|
|
*/ |
84
|
|
|
public function findCountriesWithOutCoordinates() |
85
|
|
|
{ |
86
|
|
|
/** @var QueryInterface $query */ |
87
|
|
|
$query = $this->createQuery(); |
88
|
|
|
$query->setLimit(5); |
89
|
|
|
|
90
|
|
|
$querySettings = $query->getQuerySettings(); |
91
|
|
|
$querySettings->setRespectStoragePage(false); |
92
|
|
|
$querySettings->setIgnoreEnableFields(false); |
93
|
|
|
|
94
|
|
|
$query->matching($query->equals('longitude', '')); |
95
|
|
|
$query->matching($query->equals('latitude', '')); |
96
|
|
|
$query->setQuerySettings($querySettings); |
97
|
|
|
|
98
|
|
|
return $query->execute(); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Persist All |
103
|
|
|
*/ |
104
|
|
|
public function persistAll() |
105
|
|
|
{ |
106
|
|
|
/** @var PersistenceManager $persistenceManager */ |
107
|
|
|
$persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class); |
108
|
|
|
$persistenceManager->persistAll(); |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return DatabaseConnection |
114
|
|
|
*/ |
115
|
|
|
protected function getDatabaseConnection() |
|
|
|
|
116
|
|
|
{ |
117
|
|
|
return $GLOBALS['TYPO3_DB']; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
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.