ListController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 57
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A listAction() 0 28 4
1
<?php
2
namespace TNM\GolfCourses\Controller;
3
4
/***************************************************************
5
 *
6
 *  Copyright notice
7
 *
8
 *  (c) 2017 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 SJBR\StaticInfoTables\Domain\Model\Country;
30
use TNM\GolfCourses\Domain\Model\GolfCourse;
31
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
32
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
33
34
/**
35
 * GolfCourseController
36
 */
37
class ListController extends ActionController
38
{
39
40
    /**
41
     * golfCourseRepository
42
     *
43
     * @var \TNM\GolfCourses\Domain\Repository\GolfCourseRepository
44
     * @TYPO3\CMS\Extbase\Annotation\Inject
45
     */
46
    protected $golfCourseRepository = null;
47
48
    /**
49
     * @var \SJBR\StaticInfoTables\Domain\Repository\CountryRepository
50
     * @TYPO3\CMS\Extbase\Annotation\Inject
51
     */
52
    protected $countryRepository = null;
53
54
    /**
55
     * @var \TYPO3\CMS\Core\Configuration\ExtensionConfiguration
56
     * @TYPO3\CMS\Extbase\Annotation\Inject
57
     */
58
    protected $extensionConfiguration = null;
59
60
    /**
61
     * action list
62
     *
63
     * @return void
64
     */
65
    public function listAction()
66
    {
67
        $countryAndCourses = [];
68
        $coursesTotal = 0;
69
        $countriesUidsInUse = $this->golfCourseRepository->findCountriesUidsInUse();
70
71
        foreach ($countriesUidsInUse as $countryUid) {
72
            /** @var Country $country */
73
            $country = $this->countryRepository->findByUid($countryUid);
74
            $countryName = $country->getShortNameEn();
75
            $coursesInCountry = $this->golfCourseRepository->findAllInCountry($countryUid);
76
            if (!count($coursesInCountry)) {
77
                continue;
78
            }
79
            $countryAndCourses[$countryName]['name'] = $countryName;
80
            /** @var GolfCourse $course */
81
            foreach ($coursesInCountry as $course) {
82
                $countryAndCourses[$countryName]['courses'][$course->getUid()] = $course;
83
                $coursesTotal++;
84
            }
85
            $countryAndCourses[$countryName]['coursesPlayed'] = $coursesInCountry->count();
86
        }
87
88
        $this->view->assign('mapsApiKey', $this->extensionConfiguration->get('golf_courses', 'apiKey'));
89
        $this->view->assign('countryAndCourses', $countryAndCourses);
90
        $this->view->assign('coursesCount', $coursesTotal);
91
        $this->view->assign('countriesCount', count($countryAndCourses));
92
    }
93
}
94