/**
  * Usuwanie
  *
  * @remote
  * @Secure(roles="ROLE_ADMIN")
  *
  * @param \Hatimeria\ExtJSBundle\Parameter\ParameterBag $params
  */
 public function destroyAction($params)
 {
     if (!$params->has('id')) {
         throw new NotFoundHttpException('You cant invoke this action without id parameter');
     }
     /* @var \Doctrine\ORM\EntityManager $em */
     $em = $this->get('doctrine.orm.entity_manager');
     $object = $this->getRepository()->find($params->get('id'));
     if (!is_object($object)) {
         throw new NotFoundHttpException('Newsletter with given id was not found');
     }
     $em->remove($object);
     $em->flush();
 }
Esempio n. 2
0
 /**
  * Paginated resultset in ext direct format
  *
  * @param Query $query
  *
  * @return array data in ext direct format
  */
 public function toArray()
 {
     if ($this->params->has('sort')) {
         $this->addSort();
     }
     $this->limit = $this->params->getInt('limit', 10);
     $this->start = $this->params->getInt('start', 0);
     if ($this->params->has('page') && $this->params->get('page') > 0) {
         $offset = ($this->params->get('page') - 1) * $this->limit;
     } else {
         $offset = 0;
     }
     $query = $this->qb->getQuery();
     if ($this->limit != 0) {
         $this->count = Paginate::getTotalQueryResults($query);
         $paginateQuery = Paginate::getPaginateQuery($query, $offset, $this->limit);
         $this->entities = $paginateQuery->getResult();
     } else {
         $this->entities = $query->getResult();
         $this->count = count($this->entities);
     }
     return $this->dumper->dump($this)->toArray();
 }