/** * Create the Document. * * @param DOMELEMENT $ob object tag */ protected function createPicture($objectTag) { $user = $this->container->get('security.token_storage')->getToken()->getUser(); $userDir = $this->container->getParameter('claroline.param.uploads_directory') . '/ujmexo/users_documents/' . $user->getUsername(); $picName = $this->cpPicture($objectTag->getAttribute('data'), $userDir); $picture = new Picture(); $picture->setLabel($objectTag->nodeValue); $picture->setType($objectTag->getAttribute('type')); $picture->setUrl('./uploads/ujmexo/users_documents/' . $user->getUsername() . '/images/' . $picName); $picture->setUser($user); $picture->setHeight($objectTag->getAttribute('height')); $picture->setWidth($objectTag->getAttribute('width')); $this->om->persist($picture); $this->om->flush(); $this->interactionGraph->setPicture($picture); $this->om->persist($this->interactionGraph); $this->om->flush(); }
/** * Export question image. * * @param Picture $picture * * @return \stdClass */ private function exportImage(Picture $picture) { // Export Image $image = new \stdClass(); $image->id = $picture->getId(); $image->url = $picture->getUrl(); $image->label = $picture->getLabel(); $image->width = $picture->getWidth(); $image->height = $picture->getHeight(); return $image; }
/** * To add a picture. * * * @param bool $redirection Add picture on create/edit graphic question or Add picture on manage pictures * @param int $pageToGo for the pagination * @param int $maxPage for the pagination * @param int $nbItem for the pagination * * @return \Symfony\Component\HttpFoundation\Response */ public function postPictureAddAction($redirection, $pageToGo, $maxPage, $nbItem) { // We post the data label, url, type, login // Login allow to link a doc and a user // check also login matches to the connected user $request = $this->container->get('request'); $fileUp = $request->files->get('picture'); if ($this->get('security.authorization_checker')->isGranted('ROLE_USER')) { $userDir = './uploads/ujmexo/users_pictures/' . $this->container->get('security.token_storage')->getToken()->getUser()->getUsername(); if (!is_dir($this->container->getParameter('ujm.param.exo_directory'))) { mkdir($this->container->getParameter('ujm.param.exo_directory')); } if (!is_dir($this->container->getParameter('ujm.param.exo_directory') . '/users_pictures/')) { mkdir($this->container->getParameter('ujm.param.exo_directory') . '/users_pictures/'); } if (!is_dir($userDir)) { $dirs = array('audio', 'images', 'media', 'video'); mkdir($userDir); foreach ($dirs as $dir) { mkdir($userDir . '/' . $dir); } } if (isset($fileUp) && $fileUp != '') { $file = $fileUp->getClientOriginalName(); $fileUp->move($userDir . '/images/', $fileUp->getClientOriginalName()); // get height and width of the uploaded picture list($width, $height) = getimagesize($userDir . '/images/' . $file); $em = $this->getDoctrine()->getManager(); $picture = new Picture(); $picture->setLabel(trim($request->get('label'))); $picture->setUrl($userDir . '/images/' . $file); $picture->setType(strrchr($file, '.')); $picture->setWidth($width); $picture->setHeight($height); $picture->setUser($this->container->get('security.token_storage')->getToken()->getUser()); if ($redirection == 1 || $redirection == 0 && (strtolower($picture->getType()) == '.png' || strtolower($picture->getType()) == '.jpeg' || strtolower($picture->getType()) == '.jpg' || strtolower($picture->getType()) == '.gif' || strtolower($picture->getType()) == '.bmp')) { $em->persist($picture); } $em->flush(); } // Add picture on create/edit graphic question if ($redirection == 0) { return new Response($picture->getId() . ';' . $picture->getLabel() . ';' . $picture->getType()); // Add picture on manage pictures } elseif ($redirection == 1) { $user = $this->container->get('security.token_storage')->getToken()->getUser(); $repository = $this->getDoctrine()->getManager()->getRepository('UJMExoBundle:Picture'); $listPic = $repository->findBy(array('user' => $user->getId())); // Pagination of pictures $adapterPic = new ArrayAdapter($listPic); $pagerPic = new Pagerfanta($adapterPic); if ($nbItem != 0) { // If new item > max per page, display next page $rest = $nbItem % $maxPage; if ($rest == 0) { $pageToGo += 1; } } try { $listPicPager = $pagerPic->setMaxPerPage($maxPage)->setCurrentPage($pageToGo)->getCurrentPageResults(); } catch (\Pagerfanta\Exception\NotValidCurrentPageException $e) { throw $this->createNotFoundException("Cette page n'existe pas."); } return $this->render('UJMExoBundle:Picture:managePic.html.twig', array('listPic' => $listPicPager, 'pagerPic' => $pagerPic)); } } else { return 'Not authorized'; } }