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