Example #1
0
 /**
  * @return void
  */
 public function initialize()
 {
     $this->criteria = $this->getVariable('validCriteria', []);
     $this->currentPage = isset($this->criteria['page']) ? $this->criteria['page'] : 1;
     $this->itemsCountPerPage = isset($this->criteria['limit']) ? $this->criteria['limit'] : 20;
     $criteria = $this->repository->createCriteria($this->criteria);
     $this->count = $this->repository->count($criteria);
     $this->zendPaginator = new ZendPaginator(new NullFill($this->count));
     $this->zendPaginator->setCurrentPageNumber($this->currentPage);
     $this->zendPaginator->setDefaultItemCountPerPage($this->itemsCountPerPage);
     $this->zendPaginator->setPageRange(5);
 }
Example #2
0
 public function handle($criteria, $changes)
 {
     if (empty($criteria['limit'])) {
         $criteria['limit'] = 20;
     }
     if (!isset($criteria['offset']) && empty($criteria['page'])) {
         $criteria['page'] = 1;
     }
     if (empty($criteria['order'])) {
         $criteria['order'] = 'id DESC';
     }
     $criteria = $this->repository->createCriteria($criteria);
     return $this->repository->findMany($criteria);
 }
Example #3
0
 /**
  * @return EntityInterface
  */
 public function handle($filter, $changes)
 {
     /** @var CriteriaInterface $criteria */
     $criteria = $this->repository->createCriteria($filter);
     $entity = $this->repository->find($criteria);
     if (!$entity) {
         throw new EntityNotFoundException("Entity does not found.");
     }
     if ($this->eventManager) {
         $event = $this->eventManager->createEvent('delete.pre', $entity);
         $this->eventManager->trigger($event);
     }
     $this->repository->remove($entity);
     if ($this->eventManager) {
         $event = $this->eventManager->createEvent('delete.post', $entity);
         $this->eventManager->trigger($event);
     }
     return $entity;
 }
Example #4
0
 /**
  * Execute the request
  *
  * @param  MvcEvent $e
  * @return ListViewModelInterface
  */
 public function onDispatch(MvcEvent $e)
 {
     if ($this->inputFilter) {
         $this->inputFilter->setData($this->query);
         if ($this->inputFilter->isValid()) {
             $validData = $this->inputFilter->getValues();
             $criteria = $this->repository->createCriteria($validData);
             $collection = $this->repository->findMany($criteria);
             $this->viewModel->setCollection($collection);
             $this->viewModel->setInputData($validData);
         } else {
             $this->viewModel->setErrors($this->inputFilter->getMessages());
             $this->viewModel->setInputData($this->query);
         }
     } else {
         $criteria = $this->repository->createCriteria($this->query);
         $collection = $this->repository->findMany($criteria);
         $this->viewModel->setCollection($collection);
         $this->viewModel->setInputData($this->query);
     }
     $e->setResult($this->viewModel);
     return $this->viewModel;
 }
 /**
  * @param array $filter
  * @return CriteriaInterface
  */
 public function createCriteria(array $filter = [])
 {
     return $this->entityRepository->createCriteria($filter);
 }
Example #6
0
 public function handle($criteria, $changes)
 {
     $criteria = $this->repository->createCriteria($criteria);
     return $this->repository->find($criteria);
 }