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