Completed
Pull Request — devel (#146)
by Litera
24:35 queued 19:02
created

ExportPresenter::setMealControl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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