Completed
Pull Request — master (#102)
by Litera
11:03
created

ExportModel   A

Complexity

Total Complexity 31

Size/Duplication

Total Lines 539
Duplicated Lines 4.82 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 0
Metric Value
dl 26
loc 539
c 0
b 0
f 0
rs 9.8
wmc 31
lcom 2
cbo 5

22 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setGraphHeight() 0 6 1
A getGraphHeight() 0 4 1
B mealTicket() 0 37 1
A attendance() 0 20 1
A nameList() 0 20 1
B evidence() 0 33 3
B getPdfBlocks() 0 34 5
B programCards() 0 39 1
A getLargeProgramData() 0 15 1
A largeProgram() 13 13 1
A publicProgram() 13 13 1
A programBadges() 0 8 1
A nameBadges() 0 10 1
A graph() 0 12 1
A graphMax() 0 15 1
A materials() 0 13 1
B getMoney() 0 26 4
A getMealCount() 0 13 1
A programVisitors() 0 12 1
A programDetails() 0 13 1
B visitorsExcel() 0 39 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace App\Models;
4
5
use Nette\Database\Context;
6
7
/**
8
 * Export Model
9
 *
10
 * class for exporting materials for printing
11
 *
12
 * @created 2012-09-21
13
 * @author Tomas Litera <[email protected]>
14
 */
15
class ExportModel extends BaseModel
16
{
17
18
	/**
19
	 * @var integer
20
	 */
21
	private $graphHeight;
22
23
	/**
24
	 * @var Context
25
	 */
26
	private static $connection;
27
28
	/**
29
	 * @param Context  $database
30
	 */
31
	public function __construct(Context $database)
32
	{
33
		$this->setDatabase($database);
34
		self::$connection = $this->getDatabase();
35
	}
36
37
	/**
38
	 * @param  integer $height
39
	 * @return $this
40
	 */
41
	public function setGraphHeight($height)
42
	{
43
		$this->graphHeight = $height;
44
45
		return $this;
46
	}
47
48
	/**
49
	 * @return integer
50
	 */
51
	public function getGraphHeight()
52
	{
53
		return $this->graphHeight;
54
	}
55
56
	/**
57
	 * Return data for meal tickets
58
	 *
59
	 * @param	void
60
	 * @return	array
61
	 */
62
	public function mealTicket()
63
	{
64
		return $this->getDatabase()->query('SELECT	vis.id AS id,
65
				name,
66
				surname,
67
				nick,
68
				DATE_FORMAT(birthday, "%Y-%m-%d") AS birthday,
69
				street,
70
				city,
71
				postal_code,
72
				province,
73
				province_name,
74
				group_num,
75
				group_name,
76
				troop_name,
77
				comment,
78
				arrival,
79
				departure,
80
				question,
81
				question2,
82
				fry_dinner,
83
				sat_breakfast,
84
				sat_lunch,
85
				sat_dinner,
86
				sun_breakfast,
87
				sun_lunch,
88
				bill,
89
				place,
90
				DATE_FORMAT(start_date, "%d. -") AS start_date,
91
				DATE_FORMAT(end_date, "%d. %m. %Y") AS end_date
92
		FROM kk_visitors AS vis
93
		LEFT JOIN kk_meals AS meals ON meals.visitor = vis.id
94
		LEFT JOIN kk_provinces AS provs ON vis.province = provs.id
95
		LEFT JOIN kk_meetings AS meets ON meets.id = vis.meeting
96
		WHERE meeting = ? AND vis.deleted = ?
97
		', $this->getMeetingId(), '0')->fetchAll();
98
	}
99
100
	/**
101
	 * Print Attendance into PDF file
102
	 *
103
	 * @param	void
104
	 * @return	file	PDF file
105
	 */
106
	public function attendance()
107
	{
108
		return $this->getDatabase()->query('SELECT	vis.id AS id,
109
						name,
110
						surname,
111
						nick,
112
						DATE_FORMAT(birthday, "%d. %m. %Y") AS birthday,
113
						street,
114
						city,
115
						postal_code,
116
						group_num,
117
						group_name,
118
						place,
119
						DATE_FORMAT(start_date, "%Y") AS year
120
				FROM kk_visitors AS vis
121
				LEFT JOIN kk_meetings AS meets ON meets.id = vis.meeting
122
				WHERE meeting = ? AND vis.deleted = ?
123
				ORDER BY surname ASC',
124
				$this->getMeetingId(), '0')->fetchAll();
125
	}
126
127
	/**
128
	 * Return data for name list
129
	 *
130
	 * @param	void
131
	 * @return	array    data
132
	 */
133
	public function nameList()
134
	{
135
		return $this->getDatabase()->query('SELECT	vis.id AS id,
136
						name,
137
						surname,
138
						nick,
139
						DATE_FORMAT(birthday, "%d. %m. %Y") AS birthday,
140
						street,
141
						city,
142
						postal_code,
143
						group_num,
144
						group_name,
145
						place,
146
						DATE_FORMAT(start_date, "%Y") AS year
147
				FROM kk_visitors AS vis
148
				LEFT JOIN kk_meetings AS meets ON meets.id = vis.meeting
149
				WHERE meeting = ? AND vis.deleted = ?
150
				ORDER BY nick ASC
151
				', $this->getMeetingId(), '0')->fetchAll();
152
	}
153
154
	/**
155
	 * Return data for evidence
156
	 *
157
	 * @param	int		$visitroId		ID of visitor
0 ignored issues
show
Bug introduced by
There is no parameter named $visitroId. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
158
	 * @return	array	data from database
159
	 */
160
	public function evidence($visitorId = null)
161
	{
162
		$evidenceLimit = '';
163
		$specificVisitor = '';
164
165
		if(isset($visitorId) && $visitorId != NULL) {
166
			$evidenceLimit = 'LIMIT 1';
167
			$specificVisitor = "vis.id IN (" . $visitorId . ") AND";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal vis.id IN ( does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal ) AND does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
168
		}
169
170
171
172
		return $this->getDatabase()->query('SELECT	vis.id AS id,
173
					name,
174
					surname,
175
					street,
176
					city,
177
					postal_code,
178
					bill,
179
					place,
180
					UPPER(LEFT(place, 2)) AS abbr_place,
181
					DATE_FORMAT(start_date, "%d. %m. %Y") AS date,
182
					DATE_FORMAT(start_date, "%Y") AS year,
183
					vis.cost - bill AS balance,
184
					DATE_FORMAT(birthday, "%d. %m. %Y") AS birthday,
185
					group_num,
186
					numbering
187
			FROM kk_visitors AS vis
188
			LEFT JOIN kk_meetings AS meets ON meets.id = vis.meeting
189
			WHERE ' . $specificVisitor . ' meeting = ? AND vis.deleted = ?
190
			ORDER BY surname, name
191
			' . $evidenceLimit, $this->getMeetingId(), '0')->fetchAll();
192
	}
193
194
	public static function getPdfBlocks($vid, $database)
0 ignored issues
show
Unused Code introduced by
The parameter $database is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
getPdfBlocks uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
195
	{
196
		$programs = "<tr>";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal <tr> does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
197
		$programs .= " <td class='progPart'>";
198
199
		$data = self::$connection->query('SELECT 	id,
200
							day,
201
							DATE_FORMAT(`from`, "%H:%i") AS `from`,
202
							DATE_FORMAT(`to`, "%H:%i") AS `to`,
203
							name,
204
							program
205
					FROM kk_blocks
206
					WHERE deleted = ? AND program = ? AND meeting = ?
207
					ORDER BY `day` ASC', '0', '1', $_SESSION['meetingID'])->fetchAll();
208
209
		if(!$data){
0 ignored issues
show
Bug Best Practice introduced by
The expression $data of type Nette\Database\IRow[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
210
			$programs .= "<div class='emptyTable' style='width:400px;'>Nejsou žádná aktuální data.</div>\n";
211
		} else {
212
			foreach($data as $progData) {
213
				// zbaveni se predsnemovni diskuse
214
				if($progData['id'] == 63) $programs .= "";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
215
				else {
216
					$programs .= "<div class='block'>".$progData['day'].", ".$progData['from']." - ".$progData['to']." : ".$progData['name']."</div>\n";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal , does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal - does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal : does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
217
218
					if($progData['program'] == 1) $programs .= "<div>".ProgramModel::getPdfPrograms($progData['id'], $vid, self::$connection)."</div>";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal <div> does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal </div> does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
219
				}
220
			}
221
		}
222
223
		$programs .= "</td>";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal </td> does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
224
		$programs .= "</tr>";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal </tr> does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
225
226
		return $programs;
227
	}
228
229
	/**
230
	 * Return data for program cards
231
	 *
232
	 * @param	void
233
	 * @return	array	data
234
	 */
235
	public function programCards()
236
	{
237
		return $this->getDatabase()->query('SELECT	vis.id AS id,
238
						name,
239
						surname,
240
						nick,
241
						DATE_FORMAT(birthday, "%Y-%m-%d") AS birthday,
242
						street,
243
						city,
244
						postal_code,
245
						province,
246
						province_name,
247
						group_num,
248
						group_name,
249
						troop_name,
250
						comment,
251
						arrival,
252
						departure,
253
						question,
254
						question2,
255
						fry_dinner,
256
						sat_breakfast,
257
						sat_lunch,
258
						sat_dinner,
259
						sun_breakfast,
260
						sun_lunch,
261
						bill,
262
						place,
263
						DATE_FORMAT(start_date, "%d. -") AS start_date,
264
						DATE_FORMAT(end_date, "%d. %m. %Y") AS end_date,
265
						DATE_FORMAT(start_date, "%Y") AS year
266
				FROM kk_visitors AS vis
267
				LEFT JOIN kk_meals AS meals ON meals.visitor = vis.id
268
				LEFT JOIN kk_provinces AS provs ON vis.province = provs.id
269
				LEFT JOIN kk_meetings AS meets ON meets.id = vis.meeting
270
				WHERE meeting = ? AND vis.deleted = ?
271
				ORDER BY nick ASC
272
				', $this->meetingId, '0')->fetchAll();
273
	}
274
275
	public function getLargeProgramData($day)
276
	{
277
		return $this->getDatabase()->query('SELECT 	blocks.id AS id,
278
						day,
279
						DATE_FORMAT(`from`, "%H:%i") AS `from`,
280
						DATE_FORMAT(`to`, "%H:%i") AS `to`,
281
						blocks.name AS name,
282
						program,
283
						display_progs,
284
						style
285
			FROM kk_blocks AS blocks
286
			LEFT JOIN kk_categories AS cat ON cat.id = blocks.category
287
			WHERE blocks.deleted = ? AND day = ? AND meeting = ?
288
			ORDER BY `from` ASC', '0', $day, $this->getMeetingId())->fetchAll();
289
	}
290
291
	/**
292
	 * Return data for large program
293
	 *
294
	 * @param	void
295
	 * @return	array	data
296
	 */
297 View Code Duplication
	public function largeProgram()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
298
	{
299
		return $this->getDatabase()
300
			->table('kk_meetings')
301
			->select('id, place')
302
			->select('DATE_FORMAT(start_date, "%Y") AS year')
303
			->select('UNIX_TIMESTAMP(open_reg) AS open_reg')
304
			->select('UNIX_TIMESTAMP(close_reg) AS close_reg')
305
			->where('id = ?', $this->getMeetingId())
306
			->order('id DESC')
307
			->limit(1)
308
			->fetchField();
309
	}
310
311
	/**
312
	 * Return data for public program
313
	 *
314
	 * @param	void
315
	 * @return	array	data
316
	 */
317 View Code Duplication
	public function publicProgram()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
318
	{
319
		return $this->getDatabase()
320
			->table('kk_meetings')
321
			->select('id, place')
322
			->select('DATE_FORMAT(start_date, "%Y") AS year')
323
			->select('UNIX_TIMESTAMP(open_reg) AS open_reg')
324
			->select('UNIX_TIMESTAMP(close_reg) AS close_reg')
325
			->where('id = ?', $this->getMeetingId())
326
			->order('id DESC')
327
			->limit(1)
328
			->fetchField();
329
	}
330
331
	/**
332
	 * Return data for program badges
333
	 *
334
	 * @param	void
335
	 * @return	array	data
336
	 */
337
	public function programBadges()
338
	{
339
		return $this->getDatabase()
340
			->table('kk_visitors')
341
			->where('meeting', $this->getMeetingId())
342
			->where('deleted', '0')
343
			->fetchAll();
344
	}
345
346
	/**
347
	 * Return data for name badges
348
	 *
349
	 * @param	void
350
	 * @return	array	data
351
	 */
352
	public function nameBadges()
353
	{
354
		return $this->getDatabase()
355
			->table('kk_visitors')
356
			->select('id')
357
			->select('nick')
358
			->where('meeting', $this->getMeetingId())
359
			->where('deleted', '0')
360
			->fetchAll();
361
	}
362
363
	/**
364
	 * @return ActiveRow
365
	 */
366
	public function graph()
367
	{
368
		return $this->getDatabase()
369
			->query('SELECT DATE_FORMAT(reg_daytime, "%d. %m. %Y") AS day,
370
							   COUNT(reg_daytime) AS reg_count
371
						FROM `kk_visitors` AS vis
372
						LEFT JOIN kk_meetings AS meet ON meet.id = vis.meeting
373
						WHERE meet.id = ? AND vis.deleted = ?
374
						GROUP BY day
375
						ORDER BY reg_daytime ASC',
376
						$this->getMeetingId(), '0')->fetchAll();
377
	}
378
379
	/**
380
	 * @return integer
381
	 */
382
	public function graphMax()
383
	{
384
		return $this->getDatabase()
385
			->query('SELECT MAX( reg_count ) AS max
386
					  FROM (
387
						SELECT DATE_FORMAT( reg_daytime, "%d. %m. %Y" ) AS
388
							DAY , COUNT( reg_daytime ) AS reg_count
389
						FROM `kk_visitors` AS vis
390
						LEFT JOIN kk_meetings AS meet ON meet.id = vis.meeting
391
						WHERE meet.id = ?
392
							AND vis.deleted = ?
393
						GROUP BY DAY
394
					  ) AS cnt',
395
					  $this->getMeetingId(), '0')->fetchField();
396
	}
397
398
	/**
399
	 * @return ActiveRow
400
	 */
401
	public function materials()
402
	{
403
		return $this->getDatabase()
404
			->query('SELECT	progs.id AS id,
405
						progs.name AS name,
406
						progs.material AS material
407
				FROM `kk_programs` AS progs
408
				LEFT JOIN `kk_blocks` AS bls ON progs.block = bls.id
409
				WHERE progs.deleted = ?
410
					AND bls.meeting = ?
411
					AND bls.deleted = ?',
412
					'0', $this->getMeetingId(), '0')->fetchAll();
413
	}
414
415
	/**
416
	 * Get materials for each program
417
	 *
418
	 * @param	string	type of money (account|balance|suma)
419
	 * @return	mixed	amount of money or false if error
420
	 */
421
	public function getMoney($type)
422
	{
423
		$data = $this->getDatabase()
424
			->query('SELECT SUM(bill) AS account,
425
							COUNT(bill) * vis.cost AS suma,
426
							COUNT(bill) * vis.cost - SUM(bill) AS balance
427
					FROM kk_visitors AS vis
428
					LEFT JOIN kk_meetings AS meets ON vis.meeting = meets.id
429
					WHERE meeting = ? AND vis.deleted = ?',
430
					$this->getMeetingId(), '0')->fetch();
431
432
		switch($type){
433
			case "account":
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal account does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
434
				return $data['account'];
435
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
436
			case "balance":
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal balance does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
437
				return $data['balance'];
438
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
439
			case "suma":
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal suma does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
440
				return $data['suma'];
441
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
442
			default:
443
				return FALSE;
444
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
445
		}
446
	}
447
448
	/**
449
	 * Get count of meals
450
	 *
451
	 * @param	string	name of meal
452
	 * @return	array	meal name => count
453
	 */
454
	public function getMealCount($meal)
455
	{
456
		$data = $this->getDatabase()
457
			->query('SELECT count(?) AS ?
458
				FROM `kk_meals` AS mls
459
				LEFT JOIN `kk_visitors` AS vis ON vis.id = mls.visitor
460
				WHERE vis.deleted = ?
461
					AND vis.meeting = ?
462
					AND ' . $meal . ' = ?',
463
					$meal, $meal, '0', $this->getMeetingId(), 'ano')->fetch();
464
465
		return $data[$meal];
466
	}
467
468
	/**
469
	 * Return data for visitors's program
470
	 *
471
	 * @param	int		program id
472
	 * @return	file	PDF file
473
	 */
474
	public function programVisitors($programId)
475
	{
476
		return $this->getDatabase()
477
			->query('SELECT vis.name AS name,
478
							vis.surname AS surname,
479
							vis.nick AS nick,
480
							prog.name AS program
481
					FROM kk_visitors AS vis
482
					LEFT JOIN `kk_visitor-program` AS visprog ON vis.id = visprog.visitor
483
					LEFT JOIN `kk_programs` AS prog ON prog.id = visprog.program
484
					WHERE visprog.program = ? AND vis.deleted = ?', $programId, '0')->fetchAll();
485
	}
486
487
	/**
488
	 * Return data for details of program
489
	 *
490
	 * @param	void
491
	 * @return	array	data
492
	 */
493
	public function programDetails()
494
	{
495
		return $this->getDatabase()
496
			->query('SELECT prog.name AS name,
497
						 prog.description AS description,
498
						 prog.tutor AS tutor,
499
						 prog.email AS email
500
					FROM kk_programs AS prog
501
					LEFT JOIN `kk_blocks` AS block ON block.id = prog.block
502
					WHERE block.meeting = ?
503
						AND prog.deleted = ?
504
						AND block.deleted = ?', $this->getMeetingId(), '0', '0')->fetchAll();
505
	}
506
507
	/**
508
	 * Return data for visitor excel
509
	 *
510
	 * @param   void
511
	 * @return	array	data
512
	 */
513
	public function visitorsExcel()
514
	{
515
		return $this->getDatabase()
516
			->query('
517
		SELECT vis.id AS id,
518
			code,
519
			vis.name,
520
			surname,
521
			nick,
522
			DATE_FORMAT(birthday, "%d. %m. %Y") AS birthday,
523
			vis.email,
524
			street,
525
			city,
526
			postal_code,
527
			province_name AS province,
528
			group_num,
529
			group_name,
530
			troop_name,
531
			bill,
532
			`comment`,
533
			arrival,
534
			departure,
535
			question,
536
			question2,
537
			`all`,
538
			fry_dinner,
539
			sat_breakfast,
540
			sat_lunch,
541
			sat_dinner,
542
			sun_breakfast,
543
			sun_lunch,
544
			meeting
545
		FROM `kk_visitors` AS vis
546
		LEFT JOIN `kk_provinces` AS provs ON provs.id = vis.province
547
		/*LEFT JOIN `kk_visitor-program` AS visprog ON visprog.visitor = vis.id
548
		LEFT JOIN `kk_programs` AS progs ON visprog.program = progs.id*/
549
		LEFT JOIN `kk_meals` AS mls ON mls.visitor = vis.id
550
		WHERE vis.deleted = ? AND meeting = ?', '0', $this->getMeetingId())->fetchAll();
551
	}
552
553
}
554