Test Failed
Branch devel (807472)
by Litera
06:16
created

ExportPresenter::renderEvidence()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 40
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 27
nc 6
nop 2
dl 0
loc 40
rs 8.5806
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\Factories\ExcelFactory;
9
use App\Factories\PdfFactory;
10
use Nette\Utils\Strings;
11
use Nette\Http\Request;
12
use Tracy\Debugger;
13
14
/**
15
 * Export Controller
16
 *
17
 * This file handles the retrieval and serving of exports
18
 */
19
class ExportPresenter extends BasePresenter
20
{
21
22
	const TEMPLATE_DIR = __DIR__ . '/../templates/Export/';
23
	const TEMPLATE_EXT = 'latte';
24
25
	/**
26
	 * @var ProgramModel
27
	 */
28
	protected $programModel;
29
30
	protected $blockModel;
31
32
	/**
33
	 * @var mPDF
34
	 */
35
	protected $pdf;
36
37
	/**
38
	 * @var PHPExcel
39
	 */
40
	protected $excel;
41
42
	protected $filename;
43
44
	/**
45
	 * @param ExportModel  $export
46
	 * @param ProgramModel $program
47
	 * @param ExcelFactory $excel
48
	 * @param PdfFactory   $pdf
49
	 * @param Request      $request
50
	 */
51
	public function __construct(
52
		ExportModel $export,
53
		ProgramModel $program,
54
		BlockModel $block,
55
		ExcelFactory $excel,
56
		PdfFactory $pdf,
57
		Request $request
58
	) {
59
		$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...
60
		$this->setProgramModel($program);
61
		$this->setBlockModel($block);
62
		$this->setExcel($excel->create());
63
		$this->setPdf($pdf->create());
64
		$this->setRequest($request);
65
	}
66
67
	/**
68
	 * @return void
69
	 */
70
	public function startup()
71
	{
72
		parent::startup();
73
74
		$this->getProgramModel()->setMeetingId($this->getMeetingId());
75
	}
76
77
	/**
78
	 * @return void
79
	 */
80
	public function renderDefault()
81
	{
82
		$settingsModel = $this->getModel();
83
		$template = $this->getTemplate();
84
85
		$template->graph = $settingsModel->renderGraph();
0 ignored issues
show
Bug introduced by
Accessing graph 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...
86
		$template->graphHeight = $settingsModel->getGraphHeight();
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...
87
		$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...
88
		$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...
89
		$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...
90
		$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...
91
		$template->materials = $settingsModel->getMaterial();
0 ignored issues
show
Bug introduced by
Accessing materials 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...
92
		$template->meals = $settingsModel->renderMealCount();
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...
93
	}
94
95
	public function renderEvidence($type, $id = null)
96
	{
97
		$this->filename = 'faktura.pdf';
98
99
		// summary header
100
		$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...
101
		$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...
102
		$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...
103
104
		$evidences = $this->getModel()->evidence($id);
105
106
		if(!$evidences) {
107
			Debugger::log('No data for evidence export.', Debugger::ERROR);
108
			$this->flashMessage('No data.');
109
			$this->redirect('Export:listing');
110
		}
111
112
		switch($type){
113
			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...
114
				$templateName = 'evidence_summary';
115
				// specific mPDF settings
116
				$this->getPdf()->defaultfooterfontsize = 16;
117
				$this->getPdf()->defaultfooterfontstyle = 'B';
118
				$this->getPdf()->SetHeader($hkvsHeader);
119
				break;
120
			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...
121
				$templateName = 'evidence_confirm';
122
				break;
123
			default:
124
				$templateName = 'evidence';
125
				break;
126
		}
127
128
		$parameters = [
129
			'result' => $evidences,
130
		];
131
132
		$this->forgeView($templateName, $parameters);
133
		$this->publish();
134
	}
135
136
	/**
137
	 * Print Attendance into PDF file
138
	 *
139
	 * @param	void
140
	 * @return	file	PDF file
141
	 */
142 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...
143
	{
144
		// output file name
145
		$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...
146
		$templateName = 'attendance';
147
148
		$attendances = $this->getModel()->attendance();
149
150
		// prepare header
151
		$attendanceHeader = $attendances[0]['place'] . ' ' . $attendances[0]['year'];
152
153
		// set header
154
		$this->getPdf()->SetHeader($attendanceHeader.'|sraz VS|Prezenční listina');
155
156
		$parameters = [
157
			'result' => $attendances,
158
		];
159
160
		$this->forgeView($templateName, $parameters);
161
		$this->publish();
162
	}
163
164
	/**
165
	 * Print meal tickets into PDF file
166
	 *
167
	 * @param	void
168
	 * @return	file	PDF file
169
	 */
170 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...
171
	{
172
		// output file name
173
		$this->filename= 'vlastni_stravenky.pdf';
174
		$templateName = 'meal_ticket';
175
176
		$mealTickets = $this->getModel()->mealTicket();
177
178
		$parameters = [
179
			'result' => $mealTickets,
180
		];
181
182
		$this->forgeView($templateName, $parameters);
183
		$this->publish();
184
	}
185
186
	/**
187
	 * Print name list into PDF file
188
	 *
189
	 * @param	void
190
	 * @return	file	PDF file
191
	 */
192 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...
193
	{
194
		// output file name
195
		$this->filename = 'name_list.pdf';
196
		$templateName = 'name_list';
197
198
		$nameList = $this->getModel()->nameList();
199
200
		// prepare header
201
		$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...
202
203
		// set header
204
		$this->getPdf()->SetHeader($namelistHeader.'|sraz VS|Jméno, Příjmení, Přezdívka');
205
206
		$parameters = [
207
			'result' => $nameList,
208
		];
209
210
		$this->forgeView($templateName, $parameters);
211
		$this->publish();
212
	}
213
214
	/**
215
	 * @param  string  $type
216
	 * @param  integer $id
217
	 * @return void
218
	 */
219
	public function renderProgram($type, $id)
220
	{
221
		$programMethod = 'renderProgram' . Strings::firstUpper($type);
222
223
		call_user_func([$this, $programMethod], $id);
224
	}
225
226
	/**
227
	 * Print program cards into PDF file
228
	 *
229
	 * @param	void
230
	 * @return	file	PDF file
231
	 */
232
	protected function renderProgramCards()
233
	{
234
		$this->filename = 'vlastni_programy.pdf';
235
		$templateName = 'program_cards';
236
237
		$this->getPdf()->SetWatermarkImage(IMG_DIR . 'logos/watermark.jpg', 0.1, '');
238
		$this->getPdf()->showWatermarkImage = true;
239
240
		$parameters = [
241
			'result' => $this->getModel()->programCards(),
242
		];
243
244
		$this->forgeView($templateName, $parameters);
245
		$this->publish();
246
	}
247
248
	/**
249
	 * Print large program into PDF file
250
	 *
251
	 * @param	voide
252
	 * @return	file	PDF file
253
	 */
254 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...
255
	{
256
		$largeProgram = $this->getModel()->largeProgram();
257
258
		$this->filename = Strings::toAscii($largeProgram['place'] . $largeProgram['year'] . '-program') . '.pdf';
259
		$templateName = 'program_large';
260
261
		$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...
262
263
		$this->getPdf()->paperFormat = 'B1';
264
265
		$parameters = [
266
			'header'	=> $meetingHeader,
267
			'export'	=> $this->getModel(),
268
			'program'	=> $this->getProgramModel(),
269
		];
270
271
		$this->forgeView($templateName, $parameters);
272
		$this->publish();
273
274
	}
275
276
	/**
277
	 * Print public program into PDF file
278
	 *
279
	 * @param	void
280
	 * @return	file	PDF file
281
	 */
282 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...
283
	{
284
		$templateName = 'program_public';
285
		$publicProgram = $this->getModel()->publicProgram();
286
		$this->filename = Strings::toAscii($publicProgram['place'] . $publicProgram['year'] . '-program' . '.pdf');
287
288
		$meetingHeader = $publicProgram['place'] . ' ' . $publicProgram['year'];
289
290
		$parameters = [
291
			'header'		=> $meetingHeader,
292
			'export'		=> $this->getModel(),
293
			'program'		=> $this->getProgramModel(),
294
		];
295
296
		$this->forgeView($templateName, $parameters);
297
		$this->publish();
298
	}
299
300
	/**
301
	 * Print program badges into PDF file
302
	 *
303
	 * @param	void
304
	 * @return	file	PDF file
305
	 */
306
	protected function renderProgramBadges()
307
	{
308
		$this->filename = 'program-badge.pdf';
309
		$templateName = 'program_badge';
310
311
		$programBadges = $this->getModel()->programBadges();
312
313
		$this->getPdf()->setMargins(5, 5, 9, 5);
314
315
		$days = [
316
			'PÁTEK',
317
			'SOBOTA',
318
			'NEDĚLE',
319
		];
320
321
		$exportBlocks = [];
322
		foreach ($days as $day) {
323
			$exportBlocks[$day] = $this->getBlockModel()->getExportBlocks($this->meetingId, $day);
324
		}
325
326
		$parameters = [
327
			'meeting_id'	=> $this->meetingId,
328
			'result'		=> $programBadges,
329
			'days'			=> $days,
330
			'exportBlocks'	=> $exportBlocks,
331
		];
332
333
		$this->forgeView($templateName, $parameters);
334
		$this->publish();
335
	}
336
337
	/**
338
	 * Print visitors on program into PDF file
339
	 *
340
	 * @param	int		program id
341
	 * @return	file	PDF file
342
	 */
343
	protected function renderProgramVisitors($id)
344
	{
345
		$this->filename = 'ucastnici-programu.pdf';
346
		$templateName = 'program_visitors';
347
348
		$programs = $this->getModel()->programVisitors($id);
349
350
		$programHeader = $programs[0]['program'];
351
352
		$this->getPdf()->SetHeader($programHeader.'|sraz VS|Účastnící programu');
353
354
		$parameters = [
355
			'result' => $programs,
356
		];
357
358
		$this->forgeView($templateName, $parameters);
359
		$this->publish();
360
	}
361
362
	/**
363
	 * Print details of program into PDF file
364
	 *
365
	 * @param	void
366
	 * @return	file	PDF file
367
	 */
368 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...
369
	{
370
		$this->filename = 'vypis-programu.pdf';
371
		$templateName = 'program_details';
372
373
		$programDetails = $this->getModel()->programDetails();
374
375
		$this->getPdf()->SetHeader('Výpis programů|sraz VS');
376
377
		$parameters = [
378
			'result' => $programDetails,
379
		];
380
381
		$this->forgeView($templateName, $parameters);
382
		$this->publish();
383
	}
384
385
	/**
386
	 * @return void
387
	 */
388
	public function actionNameBadges()
389
	{
390
		$names = $this->getRequest()->getPost()['names'];
391
		$this->renderNameBadges($names);
392
	}
393
394
	/**
395
	 * Print name badges into PDF file
396
	 *
397
	 * @param	string 	comma separated values
398
	 * @return	file	PDF file
399
	 */
400
	public function renderNameBadges($namesStringified)
401
	{
402
		$this->filename = 'jmenovky.pdf';
403
		$templateName = 'name_badge';
404
405
		$badges = [];
406
		if(!$namesStringified) {
407
			$badges = $this->getModel()->nameBadges();
408
		} else {
409
			$namesStringified = preg_replace('/\s+/','',$namesStringified);
410
411
			$names = explode(',',$namesStringified);
412
			foreach($names as $name) {
413
				$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...
414
				$badges[] = $badge;
415
			}
416
		}
417
418
		$this->getPdf()->setMargins(15, 15, 10, 5);
419
		$this->getPdf()->SetWatermarkImage(IMG_DIR . 'logos/watermark-waves.jpg', 0.1, '');
420
		$this->getPdf()->showWatermarkImage = TRUE;
421
422
		$parameters = [
423
			'result' => $badges,
424
		];
425
426
		$this->forgeView($templateName, $parameters);
427
		$this->publish();
428
	}
429
430
	/**
431
	 * Print data of visitors into excel file
432
	 *
433
	 * @return	file	*.xlsx file type
434
	 */
435
	public function renderVisitorsExcel()
436
	{
437
		$excel = $this->getExcel();
438
439
		$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...
440
441
		// Zde si vyvoláme aktivní list (nastavený nahoře) a vyplníme buňky A1 a A2
442
		$list = $excel->setActiveSheetIndex(0);
443
444
		$cells = [
445
			'A1' => 'ID',
446
			'B1' => 'symbol',
447
			'C1' => 'Jméno',
448
			'D1' => 'Příjmení',
449
			'E1' => 'Přezdívka',
450
			'F1' => 'Narození',
451
			'G1' => 'E-mail',
452
			'H1' => 'Adresa',
453
			'I1' => 'Město',
454
			'J1' => 'PSČ',
455
			'K1' => 'Kraj',
456
			'L1' => 'Evidence',
457
			'M1' => 'Středisko/Přístav',
458
			'N1' => 'Oddíl',
459
			'O1' => 'Účet',
460
			'P1' => 'Připomínky',
461
			'Q1' => 'Příjezd',
462
			'R1' => 'Odjezd',
463
			'S1' => 'Otázka',
464
		];
465
466
		foreach($cells as $key => $value) {
467
			$list->setCellValue($key, $value);
468
		}
469
470
		$excel->getActiveSheet()->getStyle('A1:Z1')->getFont()->setBold(true);
471
472
		$dimensions = [
473
			'C' => 15,
474
			'D' => 15,
475
			'F' => 15,
476
			'G' => 30,
477
			'H' => 20,
478
			'I' => 15,
479
			'K' => 20,
480
			'M' => 30,
481
			'N' => 20,
482
			'P' => 20,
483
			'Q' => 20,
484
			'R' => 20,
485
			'S' => 20,
486
		];
487
488
		foreach($dimensions as $key => $value) {
489
			$excel->getActiveSheet()->getColumnDimension($key)->setWidth($value);
490
		}
491
492
		$visitors = $this->getModel()->visitorsExcel();
493
494
		$cellValues = [
495
			'A' => 'id',
496
			'B' => 'code',
497
			'C' => 'name',
498
			'D' => 'surname',
499
			'E' => 'nick',
500
			'F' => 'birthday',
501
			'G' => 'email',
502
			'H' => 'street',
503
			'I' => 'city',
504
			'J' => 'postal_code',
505
			'K' => 'province',
506
			'L' => 'group_num',
507
			'M' => 'group_name',
508
			'N' => 'troop_name',
509
			'O' => 'bill',
510
			'P' => 'comment',
511
			'Q' => 'arrival',
512
			'R' => 'departure',
513
			'S' => 'question',
514
			'S' => 'question2',
515
			'T' => 'all',
516
			'U' => 'fry_dinner',
517
			'V' => 'sat_breakfast',
518
			'W' => 'sat_lunch',
519
			'X' => 'sat_dinner',
520
			'Y' => 'sun_breakfast',
521
			'Z' => 'sun_lunch',
522
		];
523
524
		$i = 2;
525
		foreach($visitors as $data) {
526
			foreach($cellValues as $cell => $value) {
527
				$list->setCellValue($cell . $i, $data[$value]);
528
			}
529
			$i++;
530
		}
531
532
		// stahnuti souboru
533
		$filename = 'export-MS-'.date('Y-m-d',time()).'.xlsx';
534
535
		$excel->setActiveSheetIndex(0);
536
537
		header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
538
		header('Content-Disposition: attachment;filename="'.$filename.'"');
539
		header('Cache-Control: max-age=0');
540
541
		// If you're serving to IE over SSL, then the following may be needed
542
		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
543
		header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
544
		header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
545
		header('Pragma: public'); // HTTP/1.0
546
547
		$ExcelWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
548
		$ExcelWriter->save('php://output');
549
		exit;
550
	}
551
552
	/**
553
	 * @param  string $name
554
	 * @param  array  $parameters
555
	 * @return self
556
	 */
557
	protected function forgeView($name = '', array $parameters = [])
558
	{
559
		$template = $this->getTemplate();
560
561
		foreach ($parameters as $parameter => $value) {
562
			$template->{$parameter} = $value;
563
		}
564
565
		$this->setView($name);
566
		$template->setFile(
567
			sprintf(
568
				'%s%s.%s',
569
				self::TEMPLATE_DIR,
570
				$name,
571
				self::TEMPLATE_EXT
572
			)
573
		);
574
575
		return $this;
576
	}
577
578
	protected function publish()
579
	{
580
		$template = $this->getTemplate();
581
582
		/* debugging */
583
		if($this->debugMode){
584
			echo $template;
585
			exit('DEBUG_MODE');
586
		} else {
587
			// write html
588
			$this->getPdf()->WriteHTML((string) $template, 0);
589
			// download
590
			$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...
591
		exit;
592
		}
593
	}
594
595
	/**
596
	 * @return ProgramModel
597
	 */
598
	protected function getProgramModel()
599
	{
600
		return $this->programModel;
601
	}
602
603
	/**
604
	 * @param  BlockModel $model
605
	 * @return $this
606
	 */
607
	protected function setBlockModel(BlockModel $model)
608
	{
609
		$this->blockModel = $model;
610
		return $this;
611
	}
612
613
	/**
614
	 * @return BlockModel
615
	 */
616
	protected function getBlockModel()
617
	{
618
		return $this->blockModel;
619
	}
620
621
	/**
622
	 * @param  ProgramModel $model
623
	 * @return $this
624
	 */
625
	protected function setProgramModel(ProgramModel $model)
626
	{
627
		$this->programModel = $model;
628
		return $this;
629
	}
630
631
632
	/**
633
	 * @return PHPExcel
634
	 */
635
	protected function getExcel()
636
	{
637
		return $this->excel;
638
	}
639
640
	/**
641
	 * @param  PHPExcel $excel
642
	 * @return $this
643
	 */
644
	protected function setExcel(\PHPExcel $excel)
645
	{
646
		$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...
647
		return $this;
648
	}
649
650
	/**
651
	 * @return mPDF
652
	 */
653
	protected function getPdf()
654
	{
655
		return $this->pdf;
656
	}
657
658
	/**
659
	 * @param  mPDF $pdf
660
	 * @return self
661
	 */
662
	protected function setPdf(\mPDF $pdf)
663
	{
664
		$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...
665
		return $this;
666
	}
667
668
}
669