It provides methods to common features needed in controllers.
Author: Fabien Potencier (fabien@symfony.com)
Inheritance: extends Symfony\Component\DependencyInjection\ContainerAware
 public function onController(Controller $controller, Request $request)
 {
     $object = $this->admin->newObject();
     $label = null;
     if ($this->admin->tree && $this->admin->getTreeObjectId()) {
         $label = $this->admin->trans('sf.tree.create.title', array('%object%' => $this->admin->string($this->admin->getTreeObject()), '%admin%' => $this->admin->getLabel()), $this->sf_domain);
     } else {
         $label = $this->admin->getFormLabel();
     }
     $list_url = $this->admin->path('list');
     $this->admin->setFormOriginalObject($object);
     $builder = $controller->createFormBuilder($object, array('label' => $label));
     $this->admin->buildCreateForm($controller, $object, $builder, $this);
     $this->buildFormReferer($request, $builder, $object, $list_url);
     $form = $builder->getForm();
     $this->setForm($form);
     $dispatcher = $this->admin->getService('event_dispatcher');
     $event = new \Symforce\AdminBundle\Event\FormEvent($form, $request);
     $dispatcher->dispatch('sf.event.form', $event);
     if (null !== $event->getResponse()) {
         return $event->getResponse();
     }
     if ($request->isMethod('POST')) {
         $form->handleRequest($request);
         $this->admin->fireEvent('submit', $form);
         if ($form->isValid()) {
             $this->admin->onUpdate($controller, $request, $this, $object, $form);
             if ($form->isValid()) {
                 $this->admin->update($object);
                 return $this->admin->afterUpdate($controller, $request, $this, $object, $form);
             }
         }
     }
     return $controller->render($this->template, array('sf_admin_loader' => $controller->get('sf.admin.loader'), 'admin' => $this->admin, 'action' => $this, 'form' => $form->createView()));
 }
 public static function getUploadForms(Controller $controller)
 {
     $formImage = $controller->createForm(new ImageMediaFormType(), new Image(), array());
     // 		$formMultipleFiles = $controller->createForm ( new ImageMediaMultipleFormType (), array (), array () );
     return array($formImage->createView());
     return $formMultipleFiles->createView();
 }
示例#3
0
 /**
  * @param Spot $spot spot contenant les orientation de vent
  * Créer une image png de la rosace des vents, avec GD.
  * L'image sera stockée dans :  images/windRosaces/spotId.png
  */
 static function createRosaceWind(Spot $spot, Controller $controller)
 {
     try {
         $rosaceImg = RosaceWindManage::createImageRosaceWind($spot);
         $ds = DIRECTORY_SEPARATOR;
         $urlImage = $controller->get("kernel")->getRootDir() . $ds . '..' . $ds . 'web' . $ds . 'images' . $ds . 'windRosaces';
         RosaceWindManage::createRoute($urlImage);
         $urlImageMin = $urlImage . $ds . $spot->getId() . ".min.png";
         $urlImage = $urlImage . $ds . $spot->getId() . ".png";
         $rosaceImgMin = imagecreate(LargeurImg * ScalledImgMin, HauteurImg * ScalledImgMin);
         $blanc = imagecolorallocate($rosaceImgMin, 255, 255, 255);
         imagecopyresampled($rosaceImgMin, $rosaceImg, 0, 0, 0, 0, LargeurImg * ScalledImgMin, HauteurImg * ScalledImgMin, LargeurImg, HauteurImg);
         imagecolortransparent($rosaceImgMin, $blanc);
         imagepng($rosaceImg, $urlImage);
         // on enregistre l'image dans le dossier "images/windRosaces"
         imagepng($rosaceImgMin, $urlImageMin);
         // on enregistre l'image dans le dossier "images/windRosaces"
         imagedestroy($rosaceImg);
         // libération de l'espace mémoire utilisé
         imagedestroy($rosaceImgMin);
     } catch (\Exception $e) {
         $toto = $e->getMessage();
         // pour debug
     }
 }
示例#4
0
 public static function createNewForm(Controller $controller, Spot $spot)
 {
     $infoSpot = new InfoSpot();
     $form = $controller->createForm(InfoSpotType::class, $infoSpot, array('action' => $controller->generateUrl('_bo_ajax_spot_add_spot_info', array('id' => $spot->getId())), 'method' => 'POST'));
     $form->add('Create', SubmitType::class, array('label' => 'Create', 'attr' => array('class' => 'btn btn-default pull-right')));
     return $form;
 }
示例#5
0
文件: Log.php 项目: ephp/utility
 public static function emergency(Controller $controller, $object, $text = '', $mode = 0)
 {
     $message = self::getMessage($object, $text, $mode);
     $logger = $controller->get('logger');
     /* @var $logger \Symfony\Bridge\Monolog\Logger */
     $pre = Debug::typeof($object, true);
     $logger->emerg("{$pre} | {$message}");
 }
示例#6
0
 /**
  * Permet de récupérer la bon route en php
  * @param $route
  * @param $params
  * @param string $locale
  * @param Controller $controller
  * @return string
  */
 public function getPath($route, $params, $locale = 'fr', Controller $controller)
 {
     if ($locale !== 'fr') {
         $route .= ucfirst($locale);
         $params['_locale'] = $locale;
     }
     return $controller->generateUrl($route, $params);
 }
 public function __construct(Controller $controller, $parametres = null)
 {
     $this->controller = $controller;
     $this->securityContext = $controller->get('security.context');
     if ($parametres === null) {
         $parametres = array();
     }
     $this->parametres = $parametres;
 }
 public function onController(Controller $controller, Request $request)
 {
     $repos = $this->admin->getRepository();
     $dql = $this->admin->getListDQL();
     $em = $this->admin->getManager();
     $query = $em->createQuery($dql);
     $paginator = $this->admin->getService('knp_paginator');
     $pagination = $paginator->paginate($query, $this->page_number, 10, array('pageParameterName' => 'admin_list_page'));
     return $controller->render($this->template, array('sf_admin_loader' => $controller->get('sf.admin.loader'), 'admin' => $this->admin, 'action' => $this, 'pagination' => $pagination));
 }
 public function onController(Controller $controller, Request $request)
 {
     $object = $this->admin->getRouteObject();
     $label = null;
     if ($this->admin->tree && $this->admin->getTreeObjectId()) {
         $label = $this->admin->trans('sf.tree.create.title', array('%object%' => $this->admin->string($this->admin->getTreeObject()), '%admin%' => $this->admin->getLabel()), $this->sf_domain);
     } else {
         $label = $this->admin->getFormLabel();
     }
     return $controller->render($this->template, array('sf_admin_loader' => $controller->get('sf.admin.loader'), 'admin' => $this->admin, 'action' => $this, 'object' => $object, 'title' => $label));
 }
示例#10
0
 /**
  * Esta funcion permite instanciar un nuevo paginador para los listados
  * de la aplicacion, seteando los valores por defecto o parametrizados
  * por el usuario
  * @author Cesar Giraldo <*****@*****.**> 27/08/2015
  * @param \Symfony\Bundle\FrameworkBundle\Controller\Controller $controller
  * @param \Symfony\Component\HttpFoundation\Request $request
  * @return \Ideup\SimplePaginatorBundle\Paginator\Paginator instancia del paginador
  */
 public static function createPaginators($controller, $request, array $ids)
 {
     $paginator = $controller->get('ideup.simple_paginator');
     $paginator->pageRanges = Paginator::$defaultPageRanges;
     foreach ($ids as $id) {
         $paginator->setItemsPerPage($request->get('itemsPerPage') != '' ? $request->get('itemsPerPage') : Paginator::$defaultItemsPerPage, $id);
         if ($paginator->getItemsPerPage($id) == 0) {
             $paginator->setItemsPerPage(Paginator::$defaultPageRanges[count(Paginator::$defaultPageRanges) - 1], $id);
         }
         $paginator->setMaxPagerItems(Paginator::$defaultMaxPagerItems, $id);
     }
     return $paginator;
 }
示例#11
0
 /**
  * Check if self registration is allowed.
  *
  * setContainer is called after controller creation is used to deny access to controller if self registration has
  * been disabled.
  */
 public function setContainer(ContainerInterface $container = NULL)
 {
     parent::setContainer($container);
     if (!$this->container->getParameter('fom_user.selfregister')) {
         throw new AccessDeniedHttpException();
     }
 }
示例#12
0
 public function redirectToRoute($route, array $parameters = array(), $status = 302)
 {
     if ($route instanceof Request) {
         $route = $route->get('_route', 'error_no_route_specified');
     }
     return parent::redirectToRoute($route, $parameters, $status);
 }
示例#13
0
 /**
  * {@inheritdoc}
  */
 public function generateUrl($route, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
 {
     if (array_key_exists('id', $parameters)) {
         $parameters['id'] = IriHelper::extractId($parameters['id']);
     }
     return parent::generateUrl($route, $parameters, $referenceType);
 }
 public function setContainer(ContainerInterface $container = null)
 {
     parent::setContainer($container);
     $options = $this->container->getParameter('bushidoio_qrcode');
     $this->http_max_age = $options['http_max_age'];
     $this->https_max_age = $options['https_max_age'];
 }
 /**
  * Generates a URL from the given parameters adding project id.
  *
  * @param string $route         The name of the route
  * @param mixed  $parameters    An array of parameters
  * @param int    $referenceType The type of reference (one of the constants in UrlGeneratorInterface)
  *
  * @return string The generated URL
  *
  * @see UrlGeneratorInterface
  */
 public function generateUrl($route, $parameters = array(), $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
 {
     if ($this->project) {
         $mergedParameters = array_merge(array('id' => $this->project->getId()), $parameters);
     }
     return parent::generateUrl($route, $mergedParameters, $referenceType);
 }
 /**
  * @param string|\Symfony\Component\Form\FormTypeInterface $type
  * @param null                                             $data
  * @param array                                            $options
  * @param string|null                                      $editionRole
  *
  * @return \Symfony\Component\Form\Form
  */
 public function createForm($type, $data = null, array $options = array(), $editionRole = null)
 {
     if (!isset($options['disabled']) && !is_null($editionRole)) {
         $options['disabled'] = !$this->get('security.authorization_checker')->isGranted($editionRole, $data);
     }
     return parent::createForm($type, $data, $options);
 }
 /**
  * @param string $id Service name/id
  *
  * @return object
  */
 public function get($id)
 {
     if (!isset($this->loadedServices[$id])) {
         $this->loadedServices[$id] = parent::get($id);
     }
     return $this->loadedServices[$id];
 }
示例#18
0
 /**
  * Check if password reset is allowed.
  *
  * setContainer is called after controller creation is used to deny access to controller if password reset has
  * been disabled.
  */
 public function setContainer(ContainerInterface $container = null)
 {
     parent::setContainer($container);
     if (!$this->container->getParameter('fom_user.reset_password')) {
         throw new AccessDeniedHttpException();
     }
 }
示例#19
0
 /**
  * Returns a rendered structure.
  *
  * @param StructureInterface $structure The structure, which has been loaded for rendering
  * @param array $attributes Additional attributes, which will be passed to twig
  * @param bool $preview Defines if the site is rendered in preview mode
  * @param bool $partial Defines if only the content block of the template should be rendered
  *
  * @return Response
  */
 protected function renderStructure(StructureInterface $structure, $attributes = [], $preview = false, $partial = false)
 {
     // extract format twig file
     if (!$preview) {
         $request = $this->getRequest();
         $requestFormat = $request->getRequestFormat();
     } else {
         $requestFormat = 'html';
     }
     $viewTemplate = $structure->getView() . '.' . $requestFormat . '.twig';
     try {
         // get attributes to render template
         $data = $this->getAttributes($attributes, $structure, $preview);
         // if partial render only content block else full page
         if ($partial) {
             $content = $this->renderBlock($viewTemplate, 'content', $data);
         } else {
             $content = parent::renderView($viewTemplate, $data);
         }
         return new Response($content);
     } catch (InvalidArgumentException $e) {
         // template not found
         throw new HttpException(406, 'Error encountered when rendering content', $e);
     }
 }
 public function setContainer(ContainerInterface $container = null)
 {
     parent::setContainer($container);
     $options = $this->container->getParameter('hyperbolaa_ueditor');
     $this->http_max_age = $options['http_max_age'];
     $this->https_max_age = $options['https_max_age'];
 }
 /**
  * {@inheritdoc}
  */
 protected function render($view, array $parameters = [], Response $response = null)
 {
     $pool = $this->get('sonata.admin.pool');
     $parameters['admin_pool'] = isset($parameters['admin_pool']) ? $parameters['admin_pool'] : $pool;
     $parameters['base_template'] = 'YnloAdminBundle::standard_layout.html.twig';
     return parent::render($view, $parameters, $response);
 }
示例#22
0
 public function onController(Controller $controller, Request $request)
 {
     $object_id = (int) $this->admin->getRouteObjectId();
     $page_object = null;
     if ($object_id) {
         $object = $this->admin->getRouteObject();
         $page_object = $this->admin->getPageObject($object);
     } else {
         $object = null;
         $page_object = $this->admin->getRootPageObject();
     }
     $page_admin = $this->admin->getPageAdmin();
     $this->admin->setFormOriginalObject($object);
     $builder = $controller->createFormBuilder($page_object, array('label' => $this->admin->getFormLabel()));
     $list_url = $this->admin->path('list');
     $update_action = $page_admin->getAction('update');
     $page_admin->buildUpdateForm($controller, $page_object, $builder, $update_action);
     $this->buildFormReferer($request, $builder, $object, $list_url);
     $form = $builder->getForm();
     $this->setForm($form);
     $dispatcher = $this->admin->getService('event_dispatcher');
     $event = new \Symforce\AdminBundle\Event\FormEvent($form, $request);
     $dispatcher->dispatch('sf.event.form', $event);
     if (null !== $event->getResponse()) {
         return $event->getResponse();
     }
     if ($request->isMethod('POST')) {
         $form->bind($request);
         $this->admin->fireEvent('submit', $form);
         if ($form->isValid()) {
             $page_admin->onUpdate($controller, $request, $update_action, $page_object, $form);
             if ($form->isValid()) {
                 $em = $this->admin->getManager();
                 $uow = $em->getUnitOfWork();
                 if ($object) {
                     // need copy propertie back to object ,
                     $this->admin->update($object);
                 } else {
                     $page_admin->update($page_object);
                 }
                 $request->getSession()->getFlashBag()->add('info', $this->trans('sf.action.update.finish', $object));
                 return $controller->redirect($this->getFormReferer($form));
             }
         }
     }
     return $controller->render($this->template, array('sf_admin_loader' => $controller->get('sf.admin.loader'), 'admin' => $this->admin, 'page_admin' => $page_admin, 'action' => $this, 'object' => $object, 'form' => $form->createView()));
 }
示例#23
0
 public function setContainer(ContainerInterface $container = null)
 {
     parent::setContainer($container);
     $this->jarves = $this->container->get('jarves');
     $this->localFilesystem = $this->container->get('jarves.filesystem.local');
     $this->rootDir = $this->container->getParameter('kernel.root_dir');
     $this->utils = $this->container->get('jarves.utils');
 }
示例#24
0
 public function setContainer(ContainerInterface $container = null)
 {
     parent::setContainer($container);
     $this->api = $this->get('wealthbot_docusign.api_client');
     $this->signatureManager = $this->get('wealthbot_docusign.document_signature.manager');
     $this->electronicSignature = $this->get('wealthbot_docusign.electronic_signature_service');
     $this->em = $this->get('doctrine.orm.entity_manager');
 }
示例#25
0
 public function setContainer(ContainerInterface $container = null)
 {
     parent::setContainer($container);
     $this->translator = $container->get('translator');
     if (method_exists($this, 'init')) {
         $this->init();
     }
 }
示例#26
0
 public function testForward()
 {
     $request = Request::create('/');
     $request->setLocale('fr');
     $request->setRequestFormat('xml');
     $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
     $kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) {
         return new Response($request->getRequestFormat() . '--' . $request->getLocale());
     }));
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $container->expects($this->at(0))->method('get')->will($this->returnValue($request));
     $container->expects($this->at(1))->method('get')->will($this->returnValue($kernel));
     $controller = new Controller();
     $controller->setContainer($container);
     $response = $controller->forward('a_controller');
     $this->assertEquals('xml--fr', $response->getContent());
 }
 public function render($template, array $data = array(), Response $response = null)
 {
     $lastTale = $this->getDoctrine()->getManager()->getRepository('AppBundle:Tale')->findLastPublicTale();
     $bestTale = $this->getDoctrine()->getManager()->getRepository('AppBundle:Tale')->findByLikesDesc();
     $correctTale = $this->getDoctrine()->getManager()->getRepository('AppBundle:Tale')->findByScoreDesc();
     $commonData = array('bestTale' => $bestTale, 'lastTale' => $lastTale[0], 'correctTale' => $correctTale[0]);
     return parent::render($template, $data + $commonData, $response);
 }
 public function render($view, array $parameters = array(), Response $response = null)
 {
     if ($this->get('templating')->exists(self::BUNDLE_MAXIMCMS . ':' . $view)) {
         return parent::render(self::BUNDLE_MAXIMCMS . ':' . $view, $parameters);
     } else {
         return parent::render($this->bundle . ':' . $view, $parameters);
     }
 }
示例#29
0
 public function setContainer(ContainerInterface $container = null)
 {
     parent::setContainer($container);
     $this->pageStack = $this->get('jarves.page_stack');
     $this->jarves = $this->get('jarves');
     $this->acl = $this->get('jarves.acl');
     $this->utils = $this->get('jarves.utils');
 }
 public function setContainer(ContainerInterface $container = null)
 {
     parent::setContainer($container);
     if (!$this->container->has('doctrine.orm.entity_manager')) {
         throw new InvalidConfigurationException();
     }
     $this->em = $this->container->get('doctrine.orm.entity_manager');
 }