Exemple #1
0
 protected function createComponentGrid() : Ytnuk\Grid\Control
 {
     $grid = new Ytnuk\Grid\Control(function (Nextras\Orm\Entity\IEntity $entity = NULL) {
         if (!$entity) {
             $entityClass = $this->repository->getEntityMetadata()->getClassName();
             $entity = new $entityClass();
         }
         $form = $this->form->create($entity);
         $form->onSubmit[] = function () {
             $this->redirect('this');
         };
         return $form;
     }, function (array $order, array $filter) {
         return $this->repository->findBy($this->prepareValues($filter))->orderBy($this->prepareValues($order))->fetchPairs(current($this->repository->getEntityMetadata()->getPrimaryKey()));
     });
     return $grid->setLink(function ($entity) {
         return $entity ? $this->getPresenter()->link('Presenter:edit', [current($this->repository->getEntityMetadata()->getPrimaryKey()) => $entity->id]) : $this->getPresenter()->link('Presenter:add');
     })->filterInputs(['this']);
 }
Exemple #2
0
 protected function createComponentForm() : Ytnuk\Orm\Form
 {
     $form = $this->form->create($this->entity);
     $form->onSuccess[] = function (Ytnuk\Orm\Form $form) {
         $presenter = $this->getPresenter();
         switch ($form->isSubmitted()) {
             case $form['action']['add']:
                 $presenter->redirect('Presenter:edit', $this->entity->getPersistedId());
                 break;
             case $form['action']['edit']:
                 $presenter->redirect('this#' . $this->getSnippetId());
                 break;
             case $form['action']['delete']:
                 $presenter->redirect('Presenter:list');
                 break;
         }
     };
     return $form;
 }