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

ExportPresenter::setBlockModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Presenters;
4
5
use App\Models\ExportModel;
6
use App\Models\ProgramModel;
7
use App\Models\BlockModel;
8
use App\Models\MealModel;
9
use App\Factories\ExcelFactory;
10
use App\Factories\PdfFactory;
11
use App\Components\RegistrationGraphControl;
12
use App\Components\MaterialsControl;
13
use App\Components\MealControl;
14
use Nette\Utils\Strings;
15
use Tracy\Debugger;
16
17
/**
18
 * Export Controller
19
 *
20
 * This file handles the retrieval and serving of exports
21
 */
22
class ExportPresenter extends BasePresenter
23
{
24
25
	const TEMPLATE_DIR = __DIR__ . '/../templates/Export/';
26
	const TEMPLATE_EXT = 'latte';
27
28
	/**
29
	 * @var ProgramModel
30
	 */
31
	protected $programModel;
32
33
	protected $blockModel;
34
35
	/**
36
	 * @var mPDF
37
	 */
38
	protected $pdf;
39
40
	/**
41
	 * @var PHPExcel
42
	 */
43
	protected $excel;
44
45
	protected $filename;
46
47
	/**
48
	 * @var RegistrationGraphControl
49
	 */
50
	private $registrationGraphControl;
51
52
	/**
53
	 * @var MaterialsControl
54
	 */
55
	private $materialControl;
56
57
	/**
58
	 * @var MealControl
59
	 */
60
	private $mealControl;
61
62
	/**
63
	 * @param ExportModel              $export
64
	 * @param ProgramModel             $program
65
	 * @param ExcelFactory             $excel
66
	 * @param PdfFactory               $pdf
67
	 * @param RegistrationGraphControl $control
68
	 * @param MaterialsControl          $materialControl
69
	 */
70
	public function __construct(
71
		ExportModel $export,
72
		ProgramModel $program,
73
		BlockModel $block,
74
		ExcelFactory $excel,
75
		PdfFactory $pdf,
76
		RegistrationGraphControl $control,
77
		MaterialsControl $materialControl,
78
		MealControl $mealControl
79
	) {
80
		$this->setModel($export);
0 ignored issues
show
Documentation introduced by
$export is of type object<App\Models\ExportModel>, but the function expects a object<App\Model>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
81
		$this->setProgramModel($program);
82
		$this->setBlockModel($block);
83
		$this->setExcel($excel->create());
84
		$this->setPdf($pdf->create());
85
		$this->setRegistrationGraphControl($control);
86
		$this->setMaterialControl($materialControl);
87
		$this->setMealControl($mealControl);
88
	}
89
90
	/**
91
	 * @return void
92
	 */
93
	public function startup()
94
	{
95
		parent::startup();
96
97
		$this->getProgramModel()->setMeetingId($this->getMeetingId());
98
	}
99
100
	/**
101
	 * @return void
102
	 */
103
	public function renderDefault()
104
	{
105
		$settingsModel = $this->getModel();
106
		$template = $this->getTemplate();
107
108
		$template->graphHeight = $this->calculateGraphHeight();
0 ignored issues
show
Bug introduced by
Accessing graphHeight on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
109
		$template->account = $settingsModel->getMoney('account');
0 ignored issues
show
Bug introduced by
Accessing account on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
110
		$template->balance = $settingsModel->getMoney('balance');
0 ignored issues
show
Bug introduced by
Accessing balance on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
111
		$template->suma = $settingsModel->getMoney('suma');
0 ignored issues
show
Bug introduced by
Accessing suma on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
112
		$template->programs = $this->getProgramModel()->renderExportPrograms();
0 ignored issues
show
Bug introduced by
Accessing programs on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
113
		$template->meals = MealModel::$dayMeal;
0 ignored issues
show
Bug introduced by
Accessing meals on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
Deprecated Code introduced by
The property App\Models\MealModel::$dayMeal has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
114
	}
115
116
	public function renderEvidence($type, $id = null)
117
	{
118
		$this->filename = 'faktura.pdf';
119
120
		// summary header
121
		$hkvsHeader = "Junák - český skaut, Kapitanát vodních skautů, z. s. | ";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Junák - český skaut, ...ních skautů, z. s. | 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...
122
		$hkvsHeader .= "Senovážné náměstí 977/24, Praha 1, 110 00 | ";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Senovážné náměstí .../24, Praha 1, 110 00 | 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...
123
		$hkvsHeader .= "IČ: 65991753, ČÚ: 2300183549/2010";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal IČ: 65991753, ČÚ: 2300183549/2010 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...
124
125
		$evidences = $this->getModel()->evidence($id);
126
127
		if(!$evidences) {
128
			Debugger::log('No data for evidence export.', Debugger::ERROR);
129
			$this->flashMessage('No data.');
130
			$this->redirect('Export:listing');
131
		}
132
133
		switch($type){
134
			case "summary":
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal summary 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...
135
				$templateName = 'evidence_summary';
136
				// specific mPDF settings
137
				$this->getPdf()->defaultfooterfontsize = 16;
138
				$this->getPdf()->defaultfooterfontstyle = 'B';
139
				$this->getPdf()->SetHeader($hkvsHeader);
140
				break;
141
			case "confirm":
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal confirm 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...
142
				$templateName = 'evidence_confirm';
143
				break;
144
			default:
145
				$templateName = 'evidence';
146
				break;
147
		}
148
149
		$parameters = [
150
			'result' => $evidences,
151
		];
152
153
		$this->forgeView($templateName, $parameters);
154
		$this->publish();
155
	}
156
157
	/**
158
	 * Print Attendance into PDF file
159
	 *
160
	 * @param	void
161
	 * @return	file	PDF file
162
	 */
163 View Code Duplication
	public function renderAttendance()
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...
164
	{
165
		// output file name
166
		$this->filename = "attendance_list.pdf";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal attendance_list.pdf 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...
167
		$templateName = 'attendance';
168
169
		$attendances = $this->getModel()->attendance();
170
171
		// prepare header
172
		$attendanceHeader = $attendances[0]['place'] . ' ' . $attendances[0]['year'];
173
174
		// set header
175
		$this->getPdf()->SetHeader($attendanceHeader.'|sraz VS|Prezenční listina');
176
177
		$parameters = [
178
			'result' => $attendances,
179
		];
180
181
		$this->forgeView($templateName, $parameters);
182
		$this->publish();
183
	}
184
185
	/**
186
	 * Print meal tickets into PDF file
187
	 *
188
	 * @param	void
189
	 * @return	file	PDF file
190
	 */
191 View Code Duplication
	public function renderMealTicket()
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...
192
	{
193
		// output file name
194
		$this->filename= 'vlastni_stravenky.pdf';
195
		$templateName = 'meal_ticket';
196
197
		$mealTickets = $this->getModel()->mealTicket();
198
199
		$parameters = [
200
			'result' => $mealTickets,
201
		];
202
203
		$this->forgeView($templateName, $parameters);
204
		$this->publish();
205
	}
206
207
	/**
208
	 * Print name list into PDF file
209
	 *
210
	 * @param	void
211
	 * @return	file	PDF file
212
	 */
213 View Code Duplication
	public function renderNameList()
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...
214
	{
215
		// output file name
216
		$this->filename = 'name_list.pdf';
217
		$templateName = 'name_list';
218
219
		$nameList = $this->getModel()->nameList();
220
221
		// prepare header
222
		$namelistHeader = $nameList[0]['place'] . " " . $nameList[0]['year'];
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...
223
224
		// set header
225
		$this->getPdf()->SetHeader($namelistHeader.'|sraz VS|Jméno, Příjmení, Přezdívka');
226
227
		$parameters = [
228
			'result' => $nameList,
229
		];
230
231
		$this->forgeView($templateName, $parameters);
232
		$this->publish();
233
	}
234
235
	/**
236
	 * @param  string  $type
237
	 * @param  integer $id
238
	 * @return void
239
	 */
240
	public function renderProgram($type, $id)
241
	{
242
		$programMethod = 'renderProgram' . Strings::firstUpper($type);
243
244
		call_user_func([$this, $programMethod], $id);
245
	}
246
247
	/**
248
	 * Print program cards into PDF file
249
	 *
250
	 * @param	void
251
	 * @return	file	PDF file
252
	 */
253
	protected function renderProgramCards()
254
	{
255
		$this->filename = 'vlastni_programy.pdf';
256
		$templateName = 'program_cards';
257
258
		$this->getPdf()->SetWatermarkImage(IMG_DIR . 'logos/watermark.jpg', 0.1, '');
259
		$this->getPdf()->showWatermarkImage = true;
260
261
		$parameters = [
262
			'result' => $this->getModel()->programCards(),
263
		];
264
265
		$this->forgeView($templateName, $parameters);
266
		$this->publish();
267
	}
268
269
	/**
270
	 * Print large program into PDF file
271
	 *
272
	 * @param	voide
273
	 * @return	file	PDF file
274
	 */
275 View Code Duplication
	protected function renderProgramLarge()
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...
276
	{
277
		$largeProgram = $this->getModel()->largeProgram();
278
279
		$this->filename = Strings::toAscii($largeProgram['place'] . $largeProgram['year'] . '-program') . '.pdf';
280
		$templateName = 'program_large';
281
282
		$meetingHeader = $largeProgram['place']." ".$largeProgram['year'];
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...
283
284
		$this->getPdf()->paperFormat = 'B1';
285
286
		$parameters = [
287
			'header'	=> $meetingHeader,
288
			'export'	=> $this->getModel(),
289
			'program'	=> $this->getProgramModel(),
290
		];
291
292
		$this->forgeView($templateName, $parameters);
293
		$this->publish();
294
295
	}
296
297
	/**
298
	 * Print public program into PDF file
299
	 *
300
	 * @param	void
301
	 * @return	file	PDF file
302
	 */
303 View Code Duplication
	protected function renderProgramPublic()
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...
304
	{
305
		$templateName = 'program_public';
306
		$publicProgram = $this->getModel()->publicProgram();
307
		$this->filename = Strings::toAscii($publicProgram['place'] . $publicProgram['year'] . '-program' . '.pdf');
308
309
		$meetingHeader = $publicProgram['place'] . ' ' . $publicProgram['year'];
310
311
		$parameters = [
312
			'header'		=> $meetingHeader,
313
			'export'		=> $this->getModel(),
314
			'program'		=> $this->getProgramModel(),
315
		];
316
317
		$this->forgeView($templateName, $parameters);
318
		$this->publish();
319
	}
320
321
	/**
322
	 * Print program badges into PDF file
323
	 *
324
	 * @param	void
325
	 * @return	file	PDF file
326
	 */
327
	protected function renderProgramBadges()
328
	{
329
		$this->filename = 'program-badge.pdf';
330
		$templateName = 'program_badge';
331
332
		$programBadges = $this->getModel()->programBadges();
333
334
		$this->getPdf()->setMargins(5, 5, 9, 5);
335
336
		$days = [
337
			'PÁTEK',
338
			'SOBOTA',
339
			'NEDĚLE',
340
		];
341
342
		$exportBlocks = [];
343
		foreach ($days as $day) {
344
			$exportBlocks[$day] = $this->getBlockModel()->getExportBlocks($this->meetingId, $day);
345
		}
346
347
		$parameters = [
348
			'meeting_id'	=> $this->meetingId,
349
			'result'		=> $programBadges,
350
			'days'			=> $days,
351
			'exportBlocks'	=> $exportBlocks,
352
		];
353
354
		$this->forgeView($templateName, $parameters);
355
		$this->publish();
356
	}
357
358
	/**
359
	 * Print visitors on program into PDF file
360
	 *
361
	 * @param	int		program id
362
	 * @return	file	PDF file
363
	 */
364
	protected function renderProgramVisitors($id)
365
	{
366
		$this->filename = 'ucastnici-programu.pdf';
367
		$templateName = 'program_visitors';
368
369
		$programs = $this->getModel()->programVisitors($id);
370
371
		$programHeader = $programs[0]['program'];
372
373
		$this->getPdf()->SetHeader($programHeader.'|sraz VS|Účastnící programu');
374
375
		$parameters = [
376
			'result' => $programs,
377
		];
378
379
		$this->forgeView($templateName, $parameters);
380
		$this->publish();
381
	}
382
383
	/**
384
	 * Print details of program into PDF file
385
	 *
386
	 * @param	void
387
	 * @return	file	PDF file
388
	 */
389 View Code Duplication
	protected function renderProgramDetails()
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...
390
	{
391
		$this->filename = 'vypis-programu.pdf';
392
		$templateName = 'program_details';
393
394
		$programDetails = $this->getModel()->programDetails();
395
396
		$this->getPdf()->SetHeader('Výpis programů|sraz VS');
397
398
		$parameters = [
399
			'result' => $programDetails,
400
		];
401
402
		$this->forgeView($templateName, $parameters);
403
		$this->publish();
404
	}
405
406
	/**
407
	 * @return void
408
	 */
409
	public function actionNameBadges()
410
	{
411
		$names = $this->getHttpRequest()->getPost()['names'];
412
		$this->renderNameBadges($names);
413
	}
414
415
	/**
416
	 * Print name badges into PDF file
417
	 *
418
	 * @param	string 	comma separated values
419
	 * @return	file	PDF file
420
	 */
421
	public function renderNameBadges($namesStringified)
422
	{
423
		$this->filename = 'jmenovky.pdf';
424
		$templateName = 'name_badge';
425
426
		$badges = [];
427
		if(!$namesStringified) {
428
			$badges = $this->getModel()->nameBadges();
429
		} else {
430
			$namesStringified = preg_replace('/\s+/','',$namesStringified);
431
432
			$names = explode(',',$namesStringified);
433
			foreach($names as $name) {
434
				$badge['nick'] = $name;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$badge was never initialized. Although not strictly required by PHP, it is generally a good practice to add $badge = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
435
				$badges[] = $badge;
436
			}
437
		}
438
439
		$this->getPdf()->setMargins(15, 15, 10, 5);
440
		$this->getPdf()->SetWatermarkImage(IMG_DIR . 'logos/watermark-waves.jpg', 0.1, '');
441
		$this->getPdf()->showWatermarkImage = TRUE;
442
443
		$parameters = [
444
			'result' => $badges,
445
		];
446
447
		$this->forgeView($templateName, $parameters);
448
		$this->publish();
449
	}
450
451
	/**
452
	 * Print data of visitors into excel file
453
	 *
454
	 * @return	file	*.xlsx file type
455
	 */
456
	public function renderVisitorsExcel()
457
	{
458
		$excel = $this->getExcel();
459
460
		$excel->getProperties()->setCreator("HKVS Srazy K + K")->setTitle("Návštěvníci");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal HKVS Srazy K + K 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 Návštěvníci 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...
461
462
		// Zde si vyvoláme aktivní list (nastavený nahoře) a vyplníme buňky A1 a A2
463
		$list = $excel->setActiveSheetIndex(0);
464
465
		$cells = [
466
			'A1' => 'ID',
467
			'B1' => 'symbol',
468
			'C1' => 'Jméno',
469
			'D1' => 'Příjmení',
470
			'E1' => 'Přezdívka',
471
			'F1' => 'Narození',
472
			'G1' => 'E-mail',
473
			'H1' => 'Adresa',
474
			'I1' => 'Město',
475
			'J1' => 'PSČ',
476
			'K1' => 'Kraj',
477
			'L1' => 'Evidence',
478
			'M1' => 'Středisko/Přístav',
479
			'N1' => 'Oddíl',
480
			'O1' => 'Účet',
481
			'P1' => 'Připomínky',
482
			'Q1' => 'Příjezd',
483
			'R1' => 'Odjezd',
484
			'S1' => 'Otázka',
485
		];
486
487
		foreach($cells as $key => $value) {
488
			$list->setCellValue($key, $value);
489
		}
490
491
		$excel->getActiveSheet()->getStyle('A1:Z1')->getFont()->setBold(true);
492
493
		$dimensions = [
494
			'C' => 15,
495
			'D' => 15,
496
			'F' => 15,
497
			'G' => 30,
498
			'H' => 20,
499
			'I' => 15,
500
			'K' => 20,
501
			'M' => 30,
502
			'N' => 20,
503
			'P' => 20,
504
			'Q' => 20,
505
			'R' => 20,
506
			'S' => 20,
507
		];
508
509
		foreach($dimensions as $key => $value) {
510
			$excel->getActiveSheet()->getColumnDimension($key)->setWidth($value);
511
		}
512
513
		$visitors = $this->getModel()->visitorsExcel();
514
515
		$cellValues = [
516
			'A' => 'id',
517
			'B' => 'code',
518
			'C' => 'name',
519
			'D' => 'surname',
520
			'E' => 'nick',
521
			'F' => 'birthday',
522
			'G' => 'email',
523
			'H' => 'street',
524
			'I' => 'city',
525
			'J' => 'postal_code',
526
			'K' => 'province',
527
			'L' => 'group_num',
528
			'M' => 'group_name',
529
			'N' => 'troop_name',
530
			'O' => 'bill',
531
			'P' => 'comment',
532
			'Q' => 'arrival',
533
			'R' => 'departure',
534
			'S' => 'question',
535
			'S' => 'question2',
536
			'T' => 'all',
537
			'U' => 'fry_dinner',
538
			'V' => 'sat_breakfast',
539
			'W' => 'sat_lunch',
540
			'X' => 'sat_dinner',
541
			'Y' => 'sun_breakfast',
542
			'Z' => 'sun_lunch',
543
		];
544
545
		$i = 2;
546
		foreach($visitors as $data) {
547
			foreach($cellValues as $cell => $value) {
548
				$list->setCellValue($cell . $i, $data[$value]);
549
			}
550
			$i++;
551
		}
552
553
		// stahnuti souboru
554
		$filename = 'export-MS-'.date('Y-m-d',time()).'.xlsx';
555
556
		$excel->setActiveSheetIndex(0);
557
558
		header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
559
		header('Content-Disposition: attachment;filename="'.$filename.'"');
560
		header('Cache-Control: max-age=0');
561
562
		// If you're serving to IE over SSL, then the following may be needed
563
		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
564
		header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
565
		header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
566
		header('Pragma: public'); // HTTP/1.0
567
568
		$ExcelWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
569
		$ExcelWriter->save('php://output');
570
		exit;
571
	}
572
573
	/**
574
	 * @param  string $name
575
	 * @param  array  $parameters
576
	 * @return self
577
	 */
578
	protected function forgeView($name = '', array $parameters = [])
579
	{
580
		$template = $this->getTemplate();
581
582
		foreach ($parameters as $parameter => $value) {
583
			$template->{$parameter} = $value;
584
		}
585
586
		$this->setView($name);
587
		$template->setFile(
588
			sprintf(
589
				'%s%s.%s',
590
				self::TEMPLATE_DIR,
591
				$name,
592
				self::TEMPLATE_EXT
593
			)
594
		);
595
596
		return $this;
597
	}
598
599
	protected function publish()
600
	{
601
		$template = $this->getTemplate();
602
603
		/* debugging */
604
		if($this->debugMode){
605
			echo $template;
606
			exit('DEBUG_MODE');
607
		} else {
608
			// write html
609
			$this->getPdf()->WriteHTML((string) $template, 0);
610
			// download
611
			$this->getPdf()->Output($this->filename, "D");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal D 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...
612
			exit;
613
		}
614
	}
615
616
	/**
617
	 * @return RegistrationGraphControl
618
	 */
619
	protected function createComponentRegistrationGraph()
620
	{
621
		return $this->registrationGraphControl->setMeetingId($this->getMeetingId());
622
	}
623
624
	/**
625
	 * @param  RegistrationGraphControl $control
626
	 * @return $this
627
	 */
628
	protected function setRegistrationGraphControl(RegistrationGraphControl $control)
629
	{
630
		$this->registrationGraphControl = $control;
631
632
		return $this;
633
	}
634
635
	/**
636
	 * @return MaterialControl
637
	 */
638
	protected function createComponentMaterials()
639
	{
640
		return $this->materialControl->setMeetingId($this->getMeetingId());
641
	}
642
643
	/**
644
	 * @param  MaterialControl $control
645
	 * @return $this
646
	 */
647
	protected function setMaterialControl(MaterialsControl $control)
648
	{
649
		$this->materialControl = $control;
650
651
		return $this;
652
	}
653
654
	/**
655
	 * @return MealControl
656
	 */
657
	protected function createComponentMeal()
658
	{
659
		return $this->mealControl->setMeetingId($this->getMeetingId());
660
	}
661
662
	/**
663
	 * @param  MealControl $control
664
	 * @return $this
665
	 */
666
	protected function setMealControl(MealControl $control)
667
	{
668
		$this->mealControl = $control;
669
670
		return $this;
671
	}
672
673
	/**
674
	 * @return integer
675
	 */
676
	protected function calculateGraphHeight()
677
	{
678
		$graphHeight = RegistrationGraphControl::GRAPH_HEIGHT_INIT;
679
680
		foreach($this->getModel()->graph() as $graph) {
681
			$graphHeight += RegistrationGraphControl::GRAPH_HEIGHT_STEP;
682
		}
683
684
		if($graphHeight < RegistrationGraphControl::GRAPH_HEIGHT_MIN) {
685
			$graphHeight = RegistrationGraphControl::GRAPH_HEIGHT_MIN;
686
		}
687
688
		return $graphHeight;
689
	}
690
691
	/**
692
	 * @return ProgramModel
693
	 */
694
	protected function getProgramModel()
695
	{
696
		return $this->programModel;
697
	}
698
699
	/**
700
	 * @param  BlockModel $model
701
	 * @return $this
702
	 */
703
	protected function setBlockModel(BlockModel $model)
704
	{
705
		$this->blockModel = $model;
706
		return $this;
707
	}
708
709
	/**
710
	 * @return BlockModel
711
	 */
712
	protected function getBlockModel()
713
	{
714
		return $this->blockModel;
715
	}
716
717
	/**
718
	 * @param  ProgramModel $model
719
	 * @return $this
720
	 */
721
	protected function setProgramModel(ProgramModel $model)
722
	{
723
		$this->programModel = $model;
724
		return $this;
725
	}
726
727
728
	/**
729
	 * @return PHPExcel
730
	 */
731
	protected function getExcel()
732
	{
733
		return $this->excel;
734
	}
735
736
	/**
737
	 * @param  PHPExcel $excel
738
	 * @return $this
739
	 */
740
	protected function setExcel(\PHPExcel $excel)
741
	{
742
		$this->excel = $excel;
0 ignored issues
show
Documentation Bug introduced by
It seems like $excel of type object<PHPExcel> is incompatible with the declared type object<App\Presenters\PHPExcel> of property $excel.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
743
		return $this;
744
	}
745
746
	/**
747
	 * @return mPDF
748
	 */
749
	protected function getPdf()
750
	{
751
		return $this->pdf;
752
	}
753
754
	/**
755
	 * @param  mPDF $pdf
756
	 * @return self
757
	 */
758
	protected function setPdf(\mPDF $pdf)
759
	{
760
		$this->pdf = $pdf;
0 ignored issues
show
Documentation Bug introduced by
It seems like $pdf of type object<mPDF> is incompatible with the declared type object<App\Presenters\mPDF> of property $pdf.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
761
		return $this;
762
	}
763
764
}
765