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