1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace App\Presenters;
13:
14: use App\Interfaces\IPresenter;
15:
16: 17: 18:
19: class RenderPresenter extends ComponentPresenter implements IPresenter {
20:
21: 22: 23: 24: 25:
26: public function renderDefault($source) {
27: $this->source = $source;
28: if ($this->params['id']){
29: $this->redirect('show', $source, $this->params['id']);
30: }
31: $this->template->dataType = $this->action->table->type;
32: $this->template->name = $this->action->name;
33: $this->template->source = $this->action->source;
34: }
35:
36: 37: 38: 39: 40:
41: public function renderAdd($source) {
42: $this->source = $source;
43: $this->id = NULL;
44: $form = $this['editForm'];
45: $form['save']->caption = 'Přidat';
46: $form->addProtection();
47: $this->template->data = $form;
48: }
49:
50: 51: 52: 53: 54: 55:
56: public function renderEdit($source, $id) {
57: $template = $this->template;
58: $template->source = $this->source = $source;
59: $template->id = $this->id = $id;
60: $template->foot = $this->action->jidash;
61: $form = $this['editForm'];
62: if (!$form->isSubmitted()) {
63: $row = $this->action->data;
64: if (!$row) {
65: $this->error('Záznam nenalezen');
66: } else if ($row instanceof \Nette\Database\Table\ActiveRow) {
67: $form['form']->setDefaults($row);
68: (!isset($form['state']))? : $form->setDefaults(array('state' => $row['state']));
69: }
70:
71: }
72: $form->addProtection();
73: $template->data = $form;
74: }
75:
76: 77: 78: 79: 80: 81:
82: public function renderShow($source, $id) {
83: $template = $this->template;
84: $template->source = $this->source = $source;
85: $template->id = $this->id = $id;
86: $template->foot = $this->action->jidash;
87: $template->delete = TRUE;
88: $form = $this['showForm'];
89: if (!$form->isSubmitted()) {
90: $row = $this->action->data;
91: if (!$row) {
92: $this->error('Záznam nenalezen');
93: } else if ($row instanceof \Nette\Database\Table\ActiveRow) {
94: $form['form']->setDefaults($row);
95: (!isset($form['state']))? : $form->setDefaults(array('state' => $row['state']));
96: }
97: }
98: $template->data = $form;
99: }
100:
101: 102: 103: 104: 105: 106:
107: public function renderDelete($source, $id) {
108: $this->source = $source;
109: $this->id = $id;
110: $row = $this->action->data;
111: if (!$row) {
112: $this->error('Požadovaný záznam nebyl nalezen');
113: }
114:
115:
116: $this->template->data = $row;
117: }
118:
119: }
120: