/** * @Route("/manage/add", name="addPage") * @Template() * @param Request $request * @throws \Exception * @return Response */ public function addAction(Request $request) { $page = new Pages(); $page->setVersion('1.0'); $page->setDate(new \DateTime()); $form = $this->createForm(new AddForm(), $page); $form->handleRequest($request); $resultUl = null; if ($form->isSubmitted() && $form->isValid()) { $collector = new RemoteDataCollector($page->getSourceUrl()); $response = $collector->collect(); $parser = new HtmlParser(); $response = $parser->parse($response); $page->setRawdata($response); $page->setPrice($response['priceNight']); $em = $this->getDoctrine()->getManager(); $ds = DIRECTORY_SEPARATOR; $uploadPath = $this->get('kernel')->getRootDir() . $ds . '..' . $ds . 'web' . $ds . 'uploads' . $ds; $em->persist($page); $em->flush(); $imagesFactory = new ImageFactory($em, $uploadPath); $imagesFactory->processImages($page); $resultUl = '/rooms/' . $page->getId(); } return $this->render('manage/add-new.html.twig', array('form' => $form->createView(), 'url' => $resultUl)); }
/** * @Route("/notebook/editor/create/", name="editorCreate") * @Method("POST") */ public function createAction(Request $request) { $dateTimeFormat = $this->container->getParameter('AppBundle.dateTimeFormat'); $standardArea = $request->request->get('standardArea'); $folder = $request->request->get('folder'); $project = $request->request->get('project'); $syntax = $request->request->get('syntax'); $date = new \DateTime("now"); $user = $this->get('security.token_storage')->getToken()->getUser(); $userId = $user->getId(); $pages = new Pages(); $pages->setUserId($userId); $pages->setContent(""); $pages->setDateCreated($date); $pages->setDateModified($date); $pages->setFolder($folder); $pages->setProject($project); $pages->setSyntax($syntax); $pages->setArea($standardArea); $em = $this->getDoctrine()->getManager(); $em->persist($pages); $em->flush(); $response = new JsonResponse(array('id' => $pages->getId(), 'syntax' => $pages->getSyntax(), 'folder' => $pages->getFolder(), 'project' => $pages->getProject(), 'date' => $pages->getDateModified()->format($dateTimeFormat), 'year' => $pages->getDateCreated()->format('Y'))); return $response; }
/** * @param Pages $pageEntity * @return Images[] */ public function collect(Pages $pageEntity) { $images = $pageEntity->getImages(); $result = array(); /** * @var PersistentCollection $images * @var Images $image */ $i = 0; $gallery = array(); foreach ($images->getIterator() as $image) { if ($image->getType() == 'gallery') { if ($i < 2) { $gallery['featured'][] = $image; } elseif ($i < 4) { $gallery['supporting'][] = $image; } elseif ($i == 5) { $gallery['last'] = $image; } else { $gallery['other'][] = $image; } $i++; } else { $result[$image->getType()][] = $image; } } $gallery['count'] = $i; $result['gallery'] = $gallery; return $result; }
/** * @param Pages $page * @param Images $image * @param string $url */ private function performFsOperations(Pages $page, Images $image, $url) { try { $image = $this->generateFromRemote($url, $image); $page->addImage($image); } catch (\Exception $e) { $this->entityManager->remove($image); } }
public function __construct(Pages $page, EntityManager $entityManager, $directoryPath) { $this->entityManager = $entityManager; $this->directoryPath = $directoryPath; $this->deletingContent = $this->entityManager->getRepository('AppBundle:Content', 'content')->findBy(['pagesid' => $page->getId()]); foreach ($this->deletingContent as $item) { $image = $item->getImagesid(); array_push($this->deletingImages, $image); } }
/** * Deletes a Images entity and jpg file. * * @Route("/content/{id}/delete", name="_deleteContent") * @Method("DELETE") * @param Request $request * @param Images $image * @param Pages $page * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function deleteAction(Request $request, Images $image, Pages $page) { $form = $this->createDeleteForm($image); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->remove($image); $em->flush(); } return $this->redirectToRoute('_indexContent', ['id' => $page->getId()]); }
/** * @param Pages $page The Pages entity * @return \Symfony\Component\Form\Form The form */ private function createDeleteForm(Pages $page) { return $this->createFormBuilder()->setAction($this->generateUrl('_delete', ['id' => $page->getId()]))->setMethod('DELETE')->getForm(); }