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

ListController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 22.22%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 4
c 3
b 0
f 1
lcom 1
cbo 1
dl 0
loc 49
ccs 4
cts 18
cp 0.2222
rs 10

1 Method

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