示例#1
0
 /**
  * @param $resource
  * @param $language
  * @return ResourceTranslation
  */
 public function loadModel(Resource $resource, Language $language)
 {
     $resourceTranslation = $this->objectManager->getRepository('BigfishResourceBundle:Resource')->findOneByLanguage($resource->getId(), $language->getId());
     if (!$resourceTranslation) {
         $resourceTranslation = new ResourceTranslation();
         $resourceTranslation->setLanguage($language);
         $resourceTranslation->setResource($resource);
     }
     return $resourceTranslation;
 }
示例#2
0
 /**
  * @param Resource $resource
  * @param Category $category
  * @param Area $area
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function listAction(Resource $resource, Category $category, Area $area = null)
 {
     $em = $this->getDoctrine()->getManager();
     /** @var \Bigfish\Bundle\PagekitBundle\Entity\Repository\AreaRepository $areas */
     $areas = $em->getRepository('BigfishPagekitBundle:Area')->findByTemplate($resource->getTemplate(), $category);
     $grids = array();
     foreach ($areas as $area) {
         /** @var \Bigfish\Bundle\PagekitBundle\Entity\Repository\InstanceRepository $entities */
         $entities = $em->getRepository('BigfishPagekitBundle:Instance')->findInstances($area, $resource);
         $grid = $this->container->get('bigfish.grid.factory')->createGrid($this->container->get('bigfish.pagekit.grid.area_list'), $entities, array('title' => $area->getTitle(), 'category' => $category, 'area' => $area, 'resource' => $resource, 'maxWidgets' => $area->getMaxWidgets(), 'currentWidgets' => count($entities)))->createView();
         $grids[] = $grid;
     }
     return $this->render('BigfishPagekitBundle:Area:list.html.twig', array('grids' => $grids));
 }
 /**
  * @param Template $template
  * @param Resource $parent
  * @return Resource
  */
 public function create(Template $template, Resource $parent = null, array $data)
 {
     $resource = new Resource();
     $resource->setTemplate($template);
     $this->objectManager->persist($resource);
     $translation = new ResourceTranslation();
     $translation->setResource($resource);
     $translation->setLanguage($this->language->getObject());
     $translation->setName(uniqid());
     $this->objectManager->persist($translation);
     $module = $template->getModule();
     $container = $this->loadModel($resource, $module);
     $moduleManager = $this->moduleManager->setModule($module);
     return $moduleManager->save($container, $data);
 }
 public function findByTemplate(Template $template, Resource $parent = null)
 {
     $culture = $this->getLanguageManager()->getCulture();
     $context = $this->getContextManager()->getContext();
     $module = $template->getModule();
     $qb = $this->initialize();
     $qb->addSelect("*");
     $qb->from($this->buildEavQuery($module), EavTables::CONTAINER_PREFIX);
     //        $qb = $this->createQueryBuilder();
     //        $qb->addSelect("*")
     $qb->where($qb->expr()->isNull(EavTables::CONTAINER_PREFIX . ".deleted"))->andWhere($qb->expr()->eq(EavTables::CONTAINER_PREFIX . ".context_id", ":context_id"))->setParameter("context_id", $context->getId())->andWhere($qb->expr()->eq(EavTables::CONTAINER_PREFIX . ".culture", ":culture"))->setParameter("culture", $culture);
     if ($parent) {
         $qb->andWhere($qb->expr()->eq("Resource.parent_id", ":parent_id"))->setParameter("parent_id", $parent->getId());
     } else {
         $qb->andWhere($qb->expr()->isNull("Resource.parent_id", ":parent_id"));
     }
     $qb->andWhere($qb->expr()->eq("Template.template_id", ":template_id"))->setParameter("template_id", $template->getId())->orderBy(EavTables::CONTAINER_PREFIX . ".sequence", "ASC");
     $result = $qb->getQuery()->getResult();
     return $result;
 }
示例#5
0
 public function createTemporary(TemplateInterface $template, Resource $parent = null, EavPersisterObjectInterface $object = null)
 {
     $context = $this->contextLanguageMediator->getContextManager()->getContext();
     $culture = $this->contextLanguageMediator->getLanguageManager()->getObject();
     $module = $template->getModule();
     /** @var EavPersisterObjectInterface $container */
     $container = $this->eavPersister->loadModel($module, $context, $object);
     $resource = new Resource();
     $resource->setExpireTemporaryDate(new \DateTime("+3 hour"));
     $resource->setContext($context);
     $resource->setTemplate($template);
     if ($parent) {
         $resource->setParent($parent);
     }
     $this->objectManager->persist($resource);
     $translation = new ResourceTranslation();
     $translation->setResource($resource);
     $translation->setLanguage($culture);
     $translation->setName(uniqid());
     $this->objectManager->persist($translation);
     $container->setResource($resource);
     $this->objectManager->persist($container);
     $this->objectManager->flush();
     return $resource;
 }
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('resource_id', 'hidden', array("data" => $this->resource->getId(), "constraints" => array(new EqualTo(array("value" => $this->resource->getId())))));
 }
 /**
  * @param Request $request
  * @param ResourceHasInstance $resourceHasInstance
  * @return JsonResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function deleteAction(Request $request, ResourceHasInstance $resourceHasInstance, Resource $resource, Category $category, Area $area = null)
 {
     $form = $this->createForm(new ComponentDeleteType($resourceHasInstance));
     if ($this->formHandler->handleDelete($form, $request, $resourceHasInstance)) {
         $url = $this->generateUrl('pagekit_pagekit_grid_list', array('category' => $category->getId(), 'resource' => $resource->getId(), 'area' => $resourceHasInstance->getArea()->getId()));
         return new JsonResponse(array("success" => true, "url" => $url));
     }
     return $this->render("BigfishEavBundle:Default:delete.html.twig", array("form" => $form->createView(), "actionUrl" => $this->generateUrl("pagekit_component_delete", array("resourceHasInstance" => $resourceHasInstance->getId(), 'category' => $category->getId(), 'resource' => $resource->getId(), 'area' => isset($area) ? $area->getId() : null))));
 }
 /**
  * @param Request $request
  * @param Resource $resource
  * @return RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function editAction(Request $request, Resource $resource, Resource $parent = null)
 {
     /** @var \Bigfish\Bundle\EavBundle\Entity\Module $module */
     $module = $resource->getModule();
     $persister = $this->container->get("bigfish.resource.persister");
     $container = $persister->loadModel($module, $resource);
     /**  @var \Symfony\Component\Form\Form $form **/
     $form = $this->get("eav.form.builder")->createFormBuilder($module, array("container" => $container))->getForm();
     $parent_id = $parent ? $parent->getId() : 0;
     if ($this->formHandler->handleUpdate($form, $request, $resource)) {
         return $this->redirect($this->generateUrl('resource_index', array('template' => $resource->getTemplate()->getId(), "parent" => $parent_id)));
     }
     //        var_dump($this->getFormErrors($form));
     return $this->render("BigfishResourceBundle:Resource:edit.html.twig", array('form' => $form->createView(), 'actionUrl' => $this->generateUrl('resource_edit', array('resource' => $resource->getId(), "parent" => $parent_id))));
 }