1: <?php
2: namespace Budovy;
3:
4: 5: 6:
7: class PlacePresenter extends BasePresenter {
8:
9: public $placeRepository;
10:
11:
12: public $scheduledTaskRepository;
13:
14:
15: public $breakdownRepository;
16:
17:
18: public $periodicTaskRepository;
19:
20:
21: public $placeFactory;
22:
23: protected function createComponentGrid() {
24: $session = $this->getSession()->getSection('history');
25: $session->secplace = (string)$this->getHttpRequest()->getUrl();
26:
27: return $this->placeFactory->createDataGrid();
28: }
29:
30: public function actionEdit($id) {
31: $item = $this->placeRepository->findById($id);
32:
33: if ($id > 0 && $item === false) {
34: $this->redirect('default');
35: }
36:
37: if ($id > 0) {
38: $this['editForm']->setDefaults($item);
39: }
40:
41: $this->template->id = $id;
42: }
43:
44: public function renderPreview($id) {
45: $item = $this->placeRepository->findById($id);
46:
47: if ($item === false) {
48: $this->redirect('default');
49: }
50:
51: $this->template->periodicTaskRepository = $this->periodicTaskRepository;
52: $this->template->scheduledtasks = $this->scheduledTaskRepository->findBy(array('id_place' => $item->id));
53: $this->template->periodictasks = $this->periodicTaskRepository->findBy(array('id_place' => $item->id));
54: $this->template->breakdowns = $this->breakdownRepository->findBy(array('id_place' => $item->id));
55: $this->template->data = $item;
56: }
57:
58: protected function createComponentEditForm() {
59: $session = $this->getSession()->getSection('history');
60:
61: if (isset($session->secplace)) {
62: $backlink = $session->secplace;
63: } else {
64: $backlink = $this->link('default');
65: }
66:
67: $form = $this->placeFactory->createEditForm($backlink);
68: $form->onSuccess[] = $this->editFormSubmitted;
69:
70: return $form;
71: }
72:
73: public function editFormSubmitted($form) {
74: $fdata = $form->getValues();
75:
76: $id = $this->getParameter('id');
77:
78: if ($id > 0) {
79: $this->placeRepository->updateById($id, $fdata);
80:
81: $this->flashMessage("Záznam byl upraven.", "success");
82: } else {
83: $this->placeRepository->insertData($fdata);
84:
85: $this->flashMessage("Záznam byl vložen.", "success");
86: }
87:
88: $session = $this->getSession()->getSection('history');
89:
90: if (isset($session->secplace)) {
91: $backlink = $session->secplace;
92: } else {
93: $backlink = $this->link('default');
94: }
95:
96: $this->redirectUrl($backlink);
97: }
98:
99: public function handleDelete($id) {
100: try {
101: $this->placeRepository->deleteById($id);
102: $this->flashMessage("Záznam byl smazán.", "success");
103: } catch (\PDOException $e) {
104: $this->flashMessage("Záznam nelze smazat!", "error");
105: }
106:
107: $this->redirect('this');
108: }
109: }