Example #1
0
 /**
  * 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();
 }
 /**
  * {@inheritdoc}
  */
 public function persistInteractionDetails(Question $question, \stdClass $importData)
 {
     $interaction = new InteractionGraphic();
     for ($i = 0, $max = count($importData->coords); $i < $max; ++$i) {
         $coord = new Coords();
         foreach ($importData->solutions as $solution) {
             if ($solution->id === $importData->choices[$i]->id) {
                 $coord->setValue($solution->value);
                 $coord->setShape($solution->shape);
                 $coord->setScoreCoords($solution->score);
                 $coord->setSize($solution->size);
                 if (isset($solution->feedback)) {
                     $coord->setFeedback($solution->feedback);
                 }
                 // should be required ?
                 if (isset($solution->color)) {
                     $coord->setColor($solution->color);
                 } else {
                     $coord->setColor('white');
                 }
             }
         }
         $coord->setInteractionGraphic($interaction);
         $interaction->addCoord($coord);
         $this->om->persist($coord);
     }
     // should we upload the picture ??
     $picture = new Picture();
     $picture->setLabel($importData->document->label ? $importData->document->label : '');
     $picture->setUrl($importData->document->url);
     $picture->setWidth($importData->width);
     $picture->setHeight($importData->height);
     $ext = pathinfo($importData->document->url)['extension'];
     $picture->setType($ext);
     $this->om->persist($picture);
     $interaction->setPicture($picture);
     $interaction->setQuestion($question);
     $this->om->persist($interaction);
 }
 /**
  * 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';
     }
 }