Completed
Push — master ( 8d56df...175407 )
by Tomas Norre
05:50
created

GolfCourseRepository::findCountriesUidsInUse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.9765

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 3
cts 8
cp 0.375
rs 9.4285
cc 2
eloc 8
nc 2
nop 0
crap 2.9765
1
<?php
2
namespace TNM\GolfCourses\Domain\Repository;
3
4
5
/***************************************************************
6
 *
7
 *  Copyright notice
8
 *
9
 *  (c) 2016 Tomas Norre Mikkelsen <[email protected]>
10
 *
11
 *  All rights reserved
12
 *
13
 *  This script is part of the TYPO3 project. The TYPO3 project is
14
 *  free software; you can redistribute it and/or modify
15
 *  it under the terms of the GNU General Public License as published by
16
 *  the Free Software Foundation; either version 3 of the License, or
17
 *  (at your option) any later version.
18
 *
19
 *  The GNU General Public License can be found at
20
 *  http://www.gnu.org/copyleft/gpl.html.
21
 *
22
 *  This script is distributed in the hope that it will be useful,
23
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 *  GNU General Public License for more details.
26
 *
27
 *  This copyright notice MUST APPEAR in all copies of the script!
28
 ***************************************************************/
29
30
use TNM\GolfCourses\Domain\Model\GolfCourse;
31
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
32
33
/**
34
 * The repository for GolfCourses
35
 */
36
class GolfCourseRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
37
{
38
39
    /**
40
     * @param $countryUid
41
     *
42
     * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
43
     */
44
    public function findAllInCountry($countryUid)
45
    {
46
        /** @var QueryInterface $query */
47
        $query = $this->createQuery();
48
49
        $querySettings = $query->getQuerySettings();
50
        $querySettings->setRespectStoragePage(false);
51
        $querySettings->setIgnoreEnableFields(false);
52
53
        $query->matching($query->equals('country', $countryUid));
54
        $query->setOrderings(['name' => 'ASC']);
55
        $query->setQuerySettings($querySettings);
56
57
        return $query->execute();
58
    }
59
60
    /**
61
     * @return array
62
     */
63 1
    public function findCountriesUidsInUse()
64
    {
65 1
        $uids = [];
66 1
        $courses = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
67
            'DISTINCT country',
68
            'tx_golfcourses_domain_model_golfcourse'
69
        );
70
71
        foreach ($courses as $course) {
72
            $uids[] = $course['country'];
73
        }
74
75
        return $uids;
76
    }
77
}