1: <?php
2: namespace Budovy;
3:
4: class ContactbindingPresenter extends BasePresenter {
5:
6: public $contactBindingRepository;
7:
8:
9: public $contactBindingFactory;
10:
11: protected function createComponentGrid() {
12: $session = $this->getSession()->getSection('history');
13: $session->seccontactb = (string)$this->getHttpRequest()->getUrl();
14:
15: return $this->contactBindingFactory->createDataGrid();
16: }
17:
18: public function actionEdit($id_contact, $id_unit, $id_operation) {
19: $item = $this->contactBindingRepository->findById(array('id_contact' => $id_contact, 'id_unit' => $id_unit, 'id_operation' => $id_operation));
20:
21: if ($item !== false) {
22: $this['editForm']->setDefaults($item);
23: }
24:
25: $this->template->id = $id_contact;
26: }
27:
28: protected function createComponentEditForm() {
29: $session = $this->getSession()->getSection('history');
30:
31: if (isset($session->seccontactb)) {
32: $backlink = $session->seccontactb;
33: } else {
34: $backlink = $this->link('default');
35: }
36:
37: $form = $this->contactBindingFactory->createEditForm($backlink);
38: $form->onSuccess[] = $this->editFormSubmitted;
39:
40: return $form;
41: }
42:
43: public function editFormSubmitted($form) {
44: $fdata = $form->getValues();
45:
46: $id_contact = $this->getParameter('id_contact');
47: $id_unit = $this->getParameter('id_unit');
48: $id_operation = $this->getParameter('id_operation');
49:
50: try {
51: if ($id_contact == 0 && $id_unit == 0 && $id_operation == 0) {
52: $this->contactBindingRepository->insertData($fdata);
53:
54: $this->flashMessage("Záznam byl vložen.", "success");
55: } else {
56: $this->contactBindingRepository->updateById(array('id_contact' => $id_contact, 'id_unit' => $id_unit, 'id_operation' => $id_operation), $fdata);
57:
58: $this->flashMessage("Záznam byl upraven.", "success");
59: }
60: } catch (\PDOException $e) {
61: if ($id_contact == 0 && $id_unit == 0 && $id_operation == 0) {
62: $this->flashMessage("Záznam neni možno vložit", "error");
63: } else {
64: $this->flashMessage("Záznam neni možno změnit", "error");
65: }
66:
67: $this->redirect('this');
68:
69: return;
70: }
71:
72: $session = $this->getSession()->getSection('history');
73:
74: if (isset($session->seccontactb)) {
75: $backlink = $session->seccontactb;
76: } else {
77: $backlink = $this->link('default');
78: }
79:
80: $this->redirectUrl($backlink);
81: }
82:
83: public function handleDelete($id_contact, $id_unit, $id_operation) {
84: try {
85: $this->contactBindingRepository->delete($id_contact, $id_unit, $id_operation);
86: $this->flashMessage("Záznam byl smazán.", "success");
87: } catch (\PDOException $e) {
88: $this->flashMessage("Záznam nelze smazat!", "error");
89: }
90:
91: $this->redirect('this');
92: }
93: }