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

GolfCourseRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 17.65%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 3
c 3
b 0
f 1
lcom 0
cbo 0
dl 0
loc 42
ccs 3
cts 17
cp 0.1765
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A findAllInCountry() 0 15 1
A findCountriesUidsInUse() 0 14 2
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
}