Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
40.54% covered (danger)
40.54%
45 / 111
62.50% covered (warning)
62.50%
5 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
SitesController
40.00% covered (danger)
40.00%
44 / 110
62.50% covered (warning)
62.50%
5 / 8
63.60
0.00% covered (danger)
0.00%
0 / 1
 index
97.14% covered (success)
97.14%
34 / 35
0.00% covered (danger)
0.00%
0 / 1
7
 view
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 impressum
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 websitefunctions
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 gotutorial
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 privacypolicy
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 about
0.00% covered (danger)
0.00%
0 / 63
0.00% covered (danger)
0.00%
0 / 1
6
 blank
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3App::uses('SgfParser', 'Utility');
4
5class SitesController extends AppController
6{
7    public $helpers = ['Html', 'Form'];
8
9    /**
10     * @param mixed $var Variable parameter
11     * @return void
12     */
13    public function index($var = null)
14    {
15        $this->set('_page', 'home');
16        $this->set('_title', 'Tsumego Hero');
17
18        // Set default lastVisit tsumego ID if not already set (for first-time visitors)
19        if (empty($_COOKIE['lastVisit']))
20            Util::setCookie('lastVisit', Constants::$DEFAULT_TSUMEGO_ID);
21
22        $this->loadModel('Tsumego');
23        $this->loadModel('Set');
24        $this->loadModel('TsumegoStatus');
25        $this->loadModel('User');
26        $this->loadModel('DayRecord');
27        $this->loadModel('Schedule');
28        $this->loadModel('Sgf');
29        $this->loadModel('SetConnection');
30        $this->loadModel('PublishDate');
31
32        $uReward = $this->User->find('all', ['limit' => 5, 'order' => 'reward DESC']) ?: [];
33        $urNames = [];
34        foreach ($uReward as $user)
35            $urNames[] = $this->checkPicture($user);
36
37        $today = date('Y-m-d');
38        $dayRecord = $this->DayRecord->find('first', ['conditions' => ['date' => $today]]);
39        if (!$dayRecord)
40            $dayRecord = $this->DayRecord->find('first', ['conditions' => ['date' => date('Y-m-d', strtotime('yesterday'))]]);
41
42        $currentQuote = 'q01';
43
44        $tsumegoFilters = new TsumegoFilters('published');
45        $tsumegoButtonsOfPublishedTsumegos = new TsumegoButtons($tsumegoFilters);
46
47        if ($dayRecord)
48        {
49            $currentQuote = $dayRecord['DayRecord']['quote'];
50            $userOfTheDay = $this->User->find('first', ['conditions' => ['id' => $dayRecord['DayRecord']['user_id']]]);
51            if (!$userOfTheDay)
52                $userOfTheDay = ['User' => ['id' => 0, 'name' => 'Guest']];
53            $this->set('userOfTheDay', $this->checkPictureLarge($userOfTheDay));
54        }
55
56        $this->set('tsumegoButtonsOfPublishedTsumegos', $tsumegoButtonsOfPublishedTsumegos);
57        $this->set('dayRecords', ClassRegistry::init('DayRecord')->find('all', ['order' => 'date ASC']));
58        $this->set('quote', $currentQuote);
59        $this->set('dayRecord', $dayRecord);
60        $this->set('urNames', $urNames);
61    }
62
63    /**
64     * @param string|int|null $id
65     * @return void
66     */
67    public function view($id = null)
68    {
69        $news = $this->Site->find('all');
70        $this->set('news', $news[$id]);
71    }
72
73    /**
74     * @return void
75     */
76    public function impressum()
77    {
78        $this->set('_page', 'about');
79        $this->set('_title', 'Tsumego Hero - Legal Notice');
80    }
81
82    /**
83     * @return void
84     */
85    public function websitefunctions()
86    {
87        $this->set('_page', 'websitefunctions');
88        $this->set('_title', 'Tsumego Hero - Website Functions');
89    }
90
91    /**
92     * @return void
93     */
94    public function gotutorial()
95    {
96        $this->set('_page', 'gotutorial');
97        $this->set('_title', 'Tsumego Hero - Go Tutorial');
98    }
99
100    /**
101     * @return void
102     */
103    public function privacypolicy()
104    {
105        $this->set('_page', 'privacypolicy');
106        $this->set('_title', 'Tsumego Hero - Privacy Policy');
107    }
108
109    /**
110     * @return void
111     */
112    public function about()
113    {
114        $this->loadModel('User');
115        $this->loadModel('Tsumego');
116        $this->loadModel('Set');
117
118        $this->set('_page', 'about');
119        $this->set('_title', 'Tsumego Hero - About');
120
121        $authors = $this->Tsumego->find('all', [
122            'order' => 'created DESC',
123            'conditions' => [
124                'NOT' => [
125                    'author' => ['Joschka Zimdars'],
126                ],
127            ],
128        ]);
129        $set = $this->Set->find('all');
130        $setMap = [];
131        $setMap2 = [];
132        $setCount = count($set);
133        for ($i = 0; $i < $setCount; $i++)
134        {
135            $divider = ' ';
136            $setMap[$set[$i]['Set']['id']] = $set[$i]['Set']['title'] . $divider . $set[$i]['Set']['title2'];
137            $setMap2[$set[$i]['Set']['id']] = $set[$i]['Set']['public'];
138        }
139
140        $count = [];
141        $count[0]['author'] = 'Innokentiy Zabirov';
142        $count[0]['collections'] = 's: <a href="/sets/view/41">Life & Death - Intermediate</a> and <a href="/sets/view/122">Gokyo Shumyo 1-4</a>';
143        $count[0]['count'] = 0;
144        $count[1]['author'] = 'Alexandre Dinerchtein';
145        $count[1]['collections'] = ': <a href="/sets/view/109">Problems from Professional Games</a>';
146        $count[1]['count'] = 0;
147        $count[2]['author'] = 'David Ulbricht';
148        $count[2]['collections'] = ': <a href="/sets/view/41">Life & Death - Intermediate</a>';
149        $count[2]['count'] = 0;
150        $count[3]['author'] = 'Bradford Malbon';
151        $count[3]['collections'] = 's: <a href="/sets/view/104">Easy Life</a> and <a href="/sets/view/105">Easy Kill</a>';
152        $count[3]['count'] = 0;
153        $count[4]['author'] = 'Ryan Smith';
154        $count[4]['collections'] = 's: <a href="/sets/view/67">Korean Problem Academy 1-4</a>';
155        $count[4]['count'] = 0;
156        $count[5]['author'] = 'Fupfv';
157        $count[5]['collections'] = ': <a href="/sets/view/139">Gokyo Shumyo 4</a>';
158        $count[5]['count'] = 0;
159        $count[6]['author'] = 'саша черных';
160        $count[6]['collections'] = ': <a href="/sets/view/137">Tsumego Master</a>';
161        $count[6]['count'] = 0;
162        $count[7]['author'] = 'Timo Kreuzer';
163        $count[7]['collections'] = ': <a href="/sets/view/137">Tsumego Master</a>';
164        $count[7]['count'] = 0;
165        $count[8]['author'] = 'David Mitchell';
166        $count[8]['collections'] = ': <a href="/sets/view/143">Diabolical</a>';
167        $count[8]['count'] = 10;
168        $count[9]['author'] = 'Omicron';
169        $count[9]['collections'] = ': <a href="/sets/view/145">Tesujis in Real Board Positions</a>';
170        $count[9]['count'] = 0;
171        $count[10]['author'] = 'Sadaharu';
172        $count[10]['collections'] = ': <a href="/sets/view/146">Tsumego of Fortitude</a>, <a href="/sets/view/166">Secret Tsumego from Hong Dojo</a>, <a href="/sets/view/158">Beautiful Tsumego</a> and more.';
173        $count[10]['count'] = 0;
174        $count[11]['author'] = 'Jérôme Hubert';
175        $count[11]['collections'] = ': <a href="/sets/view/150">Kanzufu</a> and more.';
176        $count[11]['count'] = 0;
177        $count[12]['author'] = 'Kaan Malçok';
178        $count[12]['collections'] = ': <a href="/sets/view/163">Xuanxuan Qijing</a>';
179        $count[12]['count'] = 0;
180
181        $this->set('count', $count);
182        $this->set('t', $authors);
183    }
184
185    /**
186     * Blank page — renders the default layout with no content.
187     * Used in tests as a lightweight alternative to the homepage.
188     *
189     * @return void
190     */
191    public function blank()
192    {
193        $this->set('_page', 'blank');
194        $this->set('_title', 'Tsumego Hero');
195    }
196
197}