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\Extbase\Persistence\QueryInterface; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The repository for GolfCourses |
34
|
|
|
*/ |
35
|
|
|
class GolfCourseRepository extends \TYPO3\CMS\Extbase\Persistence\Repository |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param $countryUid |
40
|
|
|
* |
41
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
42
|
|
|
*/ |
43
|
|
|
public function findAllInCountry($countryUid) |
44
|
|
|
{ |
45
|
|
|
/** @var QueryInterface $query */ |
46
|
|
|
$query = $this->createQuery(); |
47
|
|
|
|
48
|
|
|
$querySettings = $query->getQuerySettings(); |
49
|
|
|
$querySettings->setRespectStoragePage(false); |
50
|
|
|
$querySettings->setIgnoreEnableFields(false); |
51
|
|
|
|
52
|
|
|
$query->matching($query->equals('country', $countryUid)); |
53
|
|
|
$query->setOrderings(['name' => 'ASC']); |
54
|
|
|
$query->setQuerySettings($querySettings); |
55
|
|
|
|
56
|
|
|
return $query->execute(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return array |
61
|
|
|
*/ |
62
|
|
|
public function findCountriesUidsInUse() |
63
|
|
|
{ |
64
|
|
|
$uids = []; |
65
|
|
|
$courses = $this->getDatabaseConnection()->exec_SELECTquery( |
66
|
|
|
'DISTINCT country', |
67
|
|
|
'tx_golfcourses_domain_model_golfcourse', |
68
|
|
|
'' |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
foreach ($courses as $course) { |
|
|
|
|
72
|
|
|
$uids[] = $course['country']; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $uids; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
80
|
|
|
*/ |
81
|
|
|
public function findCountriesWithOutCoordinates() |
82
|
|
|
{ |
83
|
|
|
/** @var QueryInterface $query */ |
84
|
|
|
$query = $this->createQuery(); |
85
|
|
|
$query->setLimit(3); |
86
|
|
|
|
87
|
|
|
$querySettings = $query->getQuerySettings(); |
88
|
|
|
$querySettings->setRespectStoragePage(false); |
89
|
|
|
$querySettings->setIgnoreEnableFields(false); |
90
|
|
|
|
91
|
|
|
//$query->matching($query->equals('longitude', '')); |
|
|
|
|
92
|
|
|
//$query->matching($query->equals('latitude', '')); |
|
|
|
|
93
|
|
|
$query->setQuerySettings($querySettings); |
94
|
|
|
|
95
|
|
|
return $query->execute(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return DatabaseConnection |
100
|
|
|
*/ |
101
|
|
|
protected function getDatabaseConnection() |
|
|
|
|
102
|
|
|
{ |
103
|
|
|
return $GLOBALS['TYPO3_DB']; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
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.