|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PreviewTicketTask.php |
|
4
|
|
|
* |
|
5
|
|
|
* @author Bram de Leeuw |
|
6
|
|
|
* Date: 27/03/17 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Broarm\EventTickets; |
|
10
|
|
|
|
|
11
|
|
|
use BuildTask; |
|
12
|
|
|
use Director; |
|
13
|
|
|
use Dompdf\Dompdf; |
|
14
|
|
|
use SSViewer; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class PreviewTicketTask |
|
18
|
|
|
* Based of the ShopEmailPreviewTask by Anselm Christophersen |
|
19
|
|
|
* |
|
20
|
|
|
* @package Broarm\EventTickets |
|
21
|
|
|
*/ |
|
22
|
|
|
class PreviewTicketTask extends BuildTask |
|
23
|
|
|
{ |
|
24
|
|
|
protected $title = 'Preview Ticket email or pdf'; |
|
25
|
|
|
|
|
26
|
|
|
protected $description = 'Preview Ticket email or pdf'; |
|
27
|
|
|
|
|
28
|
|
|
protected $previews = array( |
|
29
|
|
|
'PrintableTicket', |
|
30
|
|
|
'ReservationMail', |
|
31
|
|
|
'NotificationMail', |
|
32
|
|
|
'AttendeeMail', |
|
33
|
|
|
'MainContactMail' |
|
34
|
|
|
); |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param \SS_HTTPRequest $request |
|
38
|
|
|
*/ |
|
39
|
|
|
public function run($request) |
|
40
|
|
|
{ |
|
41
|
|
|
$preview = $request->remaining(); |
|
42
|
|
|
$params = $request->allParams(); |
|
43
|
|
|
$url = Director::absoluteURL("dev/{$params['Action']}/{$params['TaskName']}", true); |
|
44
|
|
|
|
|
45
|
|
|
if ($preview && in_array($preview, $this->previews)) { |
|
46
|
|
|
//$reservation = Reservation::get()->filter('ReservationCode:not', 'NULL')->last(); |
|
47
|
|
|
$attendee = Attendee::get()->filter('TicketFileID:not', 0)->last(); |
|
48
|
|
|
|
|
49
|
|
|
switch ($preview) { |
|
50
|
|
|
case 'AttendeeMail': |
|
51
|
|
|
case 'PrintableTicket': |
|
52
|
|
|
$data = $attendee; |
|
53
|
|
|
$template = new SSViewer($preview); |
|
54
|
|
|
$html = $template->process($data); |
|
|
|
|
|
|
55
|
|
|
echo $html->getValue(); |
|
56
|
|
|
break; |
|
57
|
|
|
// TODO: preview a real pdf |
|
58
|
|
|
// TODO: preview in a iframe ? |
|
59
|
|
|
default: |
|
60
|
|
|
$template = new SSViewer($preview); |
|
61
|
|
|
$html = $template->process($attendee->Reservation()); |
|
62
|
|
|
\Requirements::block('app.css'); |
|
63
|
|
|
echo $html->getValue(); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
echo '<hr><h2>Choose Preview</h2>'; |
|
68
|
|
|
echo '<ul>'; |
|
69
|
|
|
foreach ($this->previews as $preview) { |
|
70
|
|
|
echo '<li><a href="' . $url . '/' . $preview . '">' . $preview . '</a></li>'; |
|
71
|
|
|
} |
|
72
|
|
|
echo '</ul><hr>'; |
|
73
|
|
|
|
|
74
|
|
|
exit(); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: