Ejemplo n.º 1
0
 /**
  * Constructor
  * 
  * @param string $msg  Success message ("Operation succesfull")
  */
 public function __construct($msg = null)
 {
     $content = new ParameterBag();
     $content->set('success', true);
     if ($msg != null) {
         $content->set('msg', $msg);
     }
     $this->content = $content;
 }
 /**
  * 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();
 }
 /**
  * @param \Hatimeria\ExtJSBundle\Parameter\ParameterBag $params
  * @param mixed $user
  * @return \Hatimeria\ExtJSBundle\Response\Form
  */
 public function process($params, $user = null)
 {
     $validationGroup = 'Profile';
     if (null === $user) {
         $validationGroup = 'Registration';
         $user = $this->um->createUser();
     }
     $options = array('data_class' => $this->userClass, 'validation_groups' => array($validationGroup));
     $type = new UserFormType();
     $type->setExtend($this->extensionCollector->getExtensions());
     $form = $this->formFactory->create($type, $user, $options);
     $form->bind($params->all());
     $result = new Form($form);
     if ($result->isValid()) {
         $this->um->updateUser($user);
         return $user;
     }
     return $result;
 }
 /**
  * @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);
 }
Ejemplo n.º 6
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();
 }