/** * @param \Hatimeria\ExtJSBundle\Parameter\ParameterBag $params * @return bool|\Hatimeria\ExtJSBundle\Validation\FormResponse */ public function process($params) { $options = array('data_class' => $this->dataClass); if ($params->get('id')) { $repository = $this->em->getRepository($this->repositoryClass); $object = $repository->find(array((int) $params->get('id'))); if (!is_object($object)) { throw new NotFoundHttpException('Object with given id not found'); } } else { $name = $this->dataClass; $object = new $name(); } $form = $this->formFactory->create(new CmsPageEditFormType(), $object, $options); $form->bind($params->all()); if ($form->isValid()) { $this->onSuccess($object); return true; } return new Form($form); }
/** * @param \Hatimeria\ExtJSBundle\Parameter\ParameterBag $params * @return bool|\Hatimeria\ExtJSBundle\Validation\FormResponse */ public function process($params) { $options = array('data_class' => 'Hatimeria\\NewsletterBundle\\Entity\\Mailing'); /* @var \Hatimeria\NewsletterBundle\Entity\Mailing $object */ if ($params->get('id')) { $repository = $this->em->getRepository('HatimeriaNewsletterBundle:Mailing'); $object = $repository->find(array((int) $params->get('id'))); if (!is_object($object)) { throw new NotFoundHttpException('Object with given id not found'); } } else { $object = new Mailing(); } $form = $this->formFactory->create(new NewsletterEditFormType(), $object, $options); $form->bind($params->all()); if ($form->isValid()) { $this->onSuccess($object); return true; } return new Form($form); }
/** * 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(); }
/** * 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(); }