Overview

Namespaces

  • App
    • Components
    • Interfaces
    • Lib
      • Files
      • Forms
        • Controls
      • Html
      • Repair
      • Statics
    • Model
    • Modules
      • BaseModule
        • Presenters
      • PartnersModule
        • Presenters
      • ProductModule
        • Presenters
      • SaleModule
        • Model
        • Presenters
      • SettingsModule
        • Model
        • Presenters
      • StoreModule
        • Model
        • Presenters
    • Presenters
    • Router
  • PHP

Classes

  • DateTime
  • SplFileInfo

Interfaces

  • ArrayAccess
  • Countable
  • Exception
  • Iterator
  • Traversable
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Download
  1: <?php
  2: 
  3: /**
  4:  * Project sberp
  5:  *
  6:  * @file ComponentPresenter 
  7:  * @author Jaromír Polášek
  8:  * @version 0.7.1.FORM
  9:  * Encoding UTF-8
 10:  */
 11: 
 12: namespace App\Presenters;
 13: 
 14: use Nette\Application\UI\Form,
 15:     App\Components\ITreeControlFactory,
 16:     App\Components\IMenuControlFactory,
 17:     App\Components\ITableControlFactory,
 18:     App\Lib\Forms\FormFactory,
 19:     App\Lib\Statics\Cons;
 20: 
 21: /**
 22:  * Presenter pro zpřístupnění základních komponent
 23:  * @persistent(menuControl)
 24:  */
 25: class ComponentPresenter extends SecurePresenter {
 26: 
 27:     /** @var \App\Component\MenuControl */
 28:     private $menu;
 29: 
 30:     /** @var \App\Component\TableControl */
 31:     private $table;
 32: 
 33:     /** @var \App\Component\FormControl */
 34:     //private $form;
 35: 
 36:     /** @var \App\Component\TreeControl */
 37:     private $tree;
 38: 
 39:     public function __construct() {
 40:     parent::__construct();
 41:     }
 42: 
 43:     /**
 44:      * Získání závislosti Menu
 45:      * @param \App\Components\IMenuControlFactory
 46:      */
 47:     public function injectMenu(IMenuControlFactory $factory) {
 48:     $this->menu = $factory->create();
 49:     }
 50: 
 51:     /**
 52:      * Získání závislosti Table
 53:      * @param \App\Components\ITableControlFactory
 54:      */
 55:     public function injectTable(ITableControlFactory $factory) {
 56:     $this->table = $factory->create();
 57:     }
 58: 
 59:     /**
 60:      * Získání závislosti Tree
 61:      * @param \App\Components\ITreeControlFactory
 62:      */
 63:     public function injectTree(ITreeControlFactory $factory) {
 64:     $this->tree = $factory->create();
 65:     }
 66:     
 67:     /**
 68:      * Vytvoří komponentu Menu
 69:      * @return \App\Components\MenuControl
 70:      */
 71:     public function createComponentMenu() {
 72:     return $this->menu;
 73:     }
 74: 
 75:     /**
 76:      * Vytvoří komponentu datagrid
 77:      * @return \App\Components\TableControl
 78:      */
 79:     public function createComponentTable() {
 80:     $this->table->params = $this->link('show', array('source' => $this->source));
 81:     return $this->table;
 82:     }
 83: 
 84:     /**
 85:      * Vytvoří komponentu Sub datagrid
 86:      * @return \App\Components\TableControl
 87:      */
 88:     public function createComponentSubTable() {
 89:     $this->table->params = array('link' => $this->subrequest());
 90:     return $this->table;
 91:     }
 92: 
 93:     /**
 94:      * Vytvoří komponentu strom
 95:      * @return \App\Component\TreeControl
 96:      */
 97:     protected function createComponentTree() {
 98:     $this->tree->params = $this->link('show', array('source' => $this->source));
 99:     return $this->tree;
100:     }
101: 
102:     /**
103:      * Smazat form factory.
104:      * @return Form
105:      */
106:     public function createComponentDeleteForm() {
107:     $form = new Form;
108:     $form->addSubmit('delete', 'Smazat')
109:             ->setAttribute('class', 'default button')
110:         ->onClick[] = array($this, 'deleteFormSucceeded');
111:     $form->addSubmit('cancel', 'Zrušit')
112:             ->setAttribute('class', 'button')
113:         ->onClick[] = array($this, 'formCancel');
114:     $form->addProtection();
115:     return $form;
116:     }
117: 
118:     /**
119:      * V případě úspěšného smazání
120:      */
121:     public function deleteFormSucceeded() {
122:     $result = $this->action->delete($this->action->data);
123:     if (!$result) {
124:         $this->flashMessage('Nemáte potřebná oprávnění');
125:     } else if ($result == 1) {
126:         $this->flashMessage('Záznam byl nenávratně Smazán');
127:     } else {
128:         $this->flashMessage('Nejprve je nutné smazat všechny záznamy, které se na tento záznam odkazují');
129:     }
130:     $this->restoreRequest($this->backlink);
131:     $this->redirectDefault();
132:     }
133: 
134:     /**
135:      * Vytváří komponentu Nádhledu formuláře s tlačítky upravit a smazat
136:      * @return App\Lib\Forms\FormFactory
137:      */
138:     public function createComponentShowForm() {
139:     $this->action->params = $this->params;
140:     $form = New FormFactory($this->action);
141:     $form->addButons($this, FALSE);
142:     $form->addState(FALSE);
143:     $form->addDesc(FALSE);
144:     $form->create(FALSE);
145:     return $form;
146:     }
147: 
148:     /**
149:      * Vytváří komponentu Formuláře s tlačítky uložit a zrušit
150:      * @return AApp\Lib\Forms\FormFactory
151:      */
152:     public function createComponentEditForm() {
153:     $this->action->params = $this->params;
154:     $form = New FormFactory($this->action);
155:     $form->addButons($this, TRUE);
156:     $form->addState(TRUE);
157:     $form->addDesc(TRUE);
158:     $form->create(TRUE);
159:     return $form;
160:     }
161: 
162:     /**
163:      * V připadě úspěšné validace zapíše data do Databáze
164:      * @param type $button
165:      */
166:     public function formSend($button) {
167:     $values = $button->form->values;
168:     $data = $values['form'];
169:     (!isset($values->state)) ? : $data[Cons::COLUMN_STATE] = $values->state;    
170:     $id = (int) $this->getParameter('id');
171:     $finalData = $this->beforeProcess($data);
172:     $result = $this->action->update(\App\Lib\Statics\Vars::setNULL($finalData), $id);
173:     if ($result === FALSE) {
174:         $this->flashMessage('Nemáte potřebná oprávnění');
175:     } else if ($result) {
176:         if ($result instanceof \Nette\Database\Table\ActiveRow){
177:         $this->afterProcess($result[Cons::COLUMN_ID]);
178:         }else {
179:         $this->afterProcess($id);
180:         }
181:         ($id) ? $this->flashMessage('Záznam byl upraven.') : $this->flashMessage('Záznam byl přidán.');
182:     } else {
183:         $this->flashMessage('Záznam se nepodařilo uložit');
184:     }
185:     $this->restoreRequest($this->backlink);     
186:     $this->redirect('show', $this->source, ($id) ? $id : $result[Cons::COLUMN_ID]);
187:     }
188:     
189:     /**
190:      * V případě zrušení úprav
191:      */
192:     public function formCancel() {
193:     $this->restoreRequest($this->backlink);
194:     $this->redirectDefault();
195:     }
196: }
197: 
sberp API API documentation generated by ApiGen