1: <?php
2: namespace Budovy;
3:
4: use Nette\Object;
5: use Nette\Utils\Paginator;
6: use Nette\Utils\Html;
7: use Nette\Application\UI;
8: use Kdyby\BootstrapFormRenderer\BootstrapRenderer;
9:
10: class BreakdownFactory extends Object {
11: 12: 13:
14: protected $documenttypeRepository;
15:
16: 17: 18:
19: protected $breakdownRepository;
20:
21: 22: 23:
24: protected $unitRepository;
25:
26: 27: 28:
29: protected $operationRepository;
30:
31: 32: 33:
34: private $placeRepository;
35:
36: 37: 38:
39: protected $contactRepository;
40:
41: function __construct(BreakdownRepository $breakdownRepository, UnitRepository $unitRepository, OperationRepository $operationRepository, ContactRepository $contactRepository, PlaceRepository $placeRepository, DocumenttypeRepository $documenttypeRepository) {
42: $this->breakdownRepository = $breakdownRepository;
43: $this->unitRepository = $unitRepository;
44: $this->operationRepository = $operationRepository;
45: $this->contactRepository = $contactRepository;
46: $this->placeRepository = $placeRepository;
47: $this->documenttypeRepository = $documenttypeRepository;
48: }
49:
50: function createDataGrid() {
51: $grid = new \Nextras\Datagrid\Datagrid;
52:
53: $grid->addColumn('name', 'Název úkolu')->enableSort();
54: $grid->addColumn('date', 'Datum')->enableSort();
55: $grid->addColumn('price', 'Cena úkonu')->enableSort();
56: $grid->addColumn('place', 'Umístění')->enableSort();
57: $grid->addColumn('unit', 'Jednotka')->enableSort();
58: $grid->addColumn('operation', 'Operace')->enableSort();
59: $grid->addColumn('contact', 'Kontakt')->enableSort();
60:
61: $grid->setRowPrimaryKey('id');
62:
63: $grid->setDatasourceCallback(function ($filter, $order, Paginator $paginator = null) {
64: return $this->breakdownRepository->getGridSelection($filter, $order, $paginator->page, $paginator->itemsPerPage);
65: });
66:
67: $grid->setFilterFormFactory(function () {
68: $form = new \Nette\Forms\Container;
69:
70: $form->addText('name');
71: $form->addText('date')->setAttribute('data-dateinput-type', 'date');
72: $form->addText('price');
73: $form->addSelect('place', 'Umístění', array('' => '') + $this->placeRepository->getPairData());
74: $form->addSelect('unit', 'Jednotka', array('' => '') + $this->unitRepository->getPairData());
75: $form->addSelect('operation', 'Operace', array('' => '') + $this->operationRepository->getPairData());
76: $form->addSelect('contact', 'Kontakt', array('' => '') + $this->contactRepository->getPairData());
77:
78: $form->addSubmit('filter', 'Hledej');
79: $form->addSubmit('cancel', 'Zrušit');
80:
81: $pretyp = $form['filter']->getControlPrototype();
82: $pretyp->setName("button");
83: $pretyp->type = 'submit';
84: $pretyp->class = 'ico-btn';
85: $pretyp->create('i class="fa fa-search"');
86:
87: $pretyp = $form['cancel']->getControlPrototype();
88: $pretyp->setName("button");
89: $pretyp->type = 'submit';
90: $pretyp->class = 'ico-btn';
91: $pretyp->create('i class="fa fa-times-circle-o"');
92:
93: return $form;
94: });
95:
96: $grid->setPagination(20, function ($filter, $order) {
97: return $this->breakdownRepository->getGridCount($filter);
98: });
99:
100: $grid->addCellsTemplate(__DIR__ . '/../templates/Breakdown/grid.latte');
101:
102: return $grid;
103: }
104:
105: function createEditForm($backlink) {
106: $form = new UI\Form;
107:
108: $form->setRenderer(new BootstrapRenderer());
109:
110: $form->getElementPrototype()->class = 'form-horizontal';
111:
112: $base = $form->addContainer('base');
113:
114: $base->addText('name', 'Název:')
115: ->setRequired('Zadejte prosím jméno')
116: ->setAttribute('class', 'form-control');
117:
118: $base->addText('price', 'Cena úkonu:')
119: ->addRule(UI\Form::FLOAT, 'Cena musí být číslo')
120: ->setAttribute('class', 'form-control');
121:
122: $base->addDate('date', 'Datum', \Vodacek\Forms\Controls\DateInput::TYPE_DATE)
123: ->addRule(UI\Form::VALID)
124: ->setAttribute('class', 'form-control');
125:
126: $base->addSelect('id_unit', 'Jednotka', $this->unitRepository->getPairData());
127: $base->addSelect('id_operation', 'Operace', $this->operationRepository->getPairData());
128: $base->addSelect('id_contact', 'Kontakt', array(0 => '') + $this->contactRepository->getPairData());
129:
130: $base->addTextArea('description', 'Popis:')
131: ->setAttribute('class', 'form-control');
132:
133: $document = $form->addContainer('document');
134:
135: $document->addSelect('id_documenttype', 'Typ', $this->documenttypeRepository->getPairData());
136: $document->addUpload('files', 'Soubor', true);
137:
138: $form->addSubmit('saving', 'Uložit a zpět')
139: ->setAttribute('class', 'btn btn-primary');
140:
141: $form->addSubmit('back')
142: ->setAttribute('class', 'btn btn-inverse')
143: ->getControlPrototype()
144: ->setName('a')
145: ->href($backlink)
146: ->add(Html::el('i')->class('fa fa-reply'))
147: ->add(Html::el('span', ' Zpět'));
148:
149: return $form;
150: }
151: }