-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathticket.controller.php
65 lines (53 loc) · 1.72 KB
/
ticket.controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
use MyApp\Helper\CalculateTicketPrice;
// GET routes
$app->get(
'/tickets', function () use ($app) {
$app->render('tpl_tickets.twig', array('page_template' => 'tpl_tickets'));
}
)->name('tickets');
$app->get(
'/tickets/:plan+', function ($plan) use ($app) {
$app->render('tpl_tickets.twig', array('page_template' => 'tpl_tickets', 'plan' => $plan));
}
)->name('ticket_plan');
// POST routes
// buy
$app->post(
'/tickets', function () use ($app) {
$tickets = R::dispense('tickets');
$plan = $_POST['plan'];
$calc = new CalculateTicketPrice();
foreach ($plan as $yourPlan => $yourCount) {
$calc->add($yourPlan, $yourCount);
}
$ticketsPost = $app->request->post('ticket');
$tickets->email = $ticketsPost['email'];
$tickets->password = $ticketsPost['password'];
$tickets->repassword = $ticketsPost['repassword'];
$tickets->repassword = $ticketsPost['repassword'];
$tickets->firstname = $ticketsPost['firstname'];
$tickets->lastname = $ticketsPost['lastname'];
$tickets->tel = $ticketsPost['tel'];
$tickets->address = $ticketsPost['address'];
$tickets->zip = $ticketsPost['zip'];
$tickets->ip = $app->request->getIp();
$tickets->plan1 = $plan[1];
$tickets->plan2 = $plan[2];
$tickets->plan3 = $plan[3];
$tickets->plan4 = $plan[4];
$tickets->price_total = $calc->getPrice();
// start transaction
R::begin();
try {
R::store($tickets);
R::commit();
$app->flash('success', 'Deine Bestellung wurde gespeichert!');
}
catch (Exception $e) {
R::rollback();
$app->flash('error', 'Oops... seems something goes wrong.');
}
$app->redirect($app->request->getReferrer());
}
)->name('ticket_buy');