/** * {@inheritDoc} */ public function load(ObjectManager $em) { $entity = new Projet(); $entity->setNomprojet('Chaudière à bois pour l\'école'); $entity->setDescription('chaudière à bois déchiqueté de 100 Kw consommation de 70 T annuelles de bois bocager issus de l\'élagage des haies'); $entity->setDaterealisation(new \DateTime('2013-01-01')); $entity->setDuree('3 mois'); $entity->setGains('des économies importantes grâce au chauffage de 5 bâtiments soit 3 000 m2'); $entity->setCout('20 000'); $entity->setFinancement('departement:3;'); $file = new File(__DIR__ . '/../Data/chauffage.jpg'); $destFile = __DIR__ . '/../Data/tmp-chauffagebois.jpg'; copy($file, $destFile); $entity->file = new File($destFile); $entity->setUser($em->merge($this->getReference('user-olivier'))); $em->persist($entity); $entity = new Projet(); $entity->setNomprojet('Chaudière à bois pour l\'école du village et un local avec un conteneur préfabriqué'); $entity->setDescription('chaudière à bois de bois bocager issus de l\'élagage des haies '); $entity->setDaterealisation(new \DateTime('2014-03-01')); $entity->setDuree('3 mois'); $entity->setGains('des économies importantes grâce au chauffage de 520 m2 de locaux '); $entity->setCout('53 000'); $entity->setFinancement('departement:3;'); $file = new File(__DIR__ . '/../Data/chaudiere.png'); $destFile = __DIR__ . '/../Data/tmp-chaudierebois.png'; copy($file, $destFile); $entity->file = new File($destFile); $entity->setUser($em->merge($this->getReference('user-gilbert'))); $em->persist($entity); $em->flush(); }
/** * @param EntityManager $user * * @return bool */ public function process(ProjetModel $projet) { $this->form->setData($projet); if ('POST' == $this->request->getMethod()) { $this->form->bind($this->request); if ($this->form->isValid()) { $projet->setUser($this->connectedUser); ############ Edit settings ############## $DestinationDirectory = __DIR__ . '/../../../../../web/uploads/'; //specify upload directory ends with / (slash) $Quality = 90; //jpeg quality ########################################## //Let's check allowed $ImageType, we use PHP SWITCH statement here $ext = $projet->file->getMimeType(); switch (strtolower($projet->file->getMimeType())) { case 'image/png': //Create a new image from file $CreatedImage = imagecreatefrompng($projet->file->getRealPath()); break; case 'image/gif': $CreatedImage = imagecreatefromgif($projet->file->getRealPath()); break; case 'image/jpeg': case 'image/pjpeg': $CreatedImage = imagecreatefromjpeg($projet->file->getRealPath()); break; default: die('Unsupported File!'); //output error and exit } // Crop and save image to upload directory $cropService = $this->cropper; $destImage = uniqid() . '.' . $projet->file->guessExtension(); if (!$cropService->cropImage($projet->getX(), $projet->getY(), $projet->getW(), $projet->getH(), $DestinationDirectory . $destImage, $CreatedImage, $Quality, $projet->file->getMimeType())) { die('Erreur lors du rognage de l\'image'); } $projet->setPhoto($destImage); // Create entity project $entity = new Projet(); $entity->setNomprojet($projet->getNomprojet()); $entity->setDescription($projet->getDescription()); $entity->setDuree($projet->getDuree()); $entity->setDaterealisation($projet->getDaterealisation()); $entity->setGains($projet->getGains()); $entity->setFinancement($projet->getFinancement()); $entity->setPhoto($projet->getPhoto()); $entity->setCout($projet->getCout()); $entity->setUser($projet->getUser()); $this->entityManager->persist($entity); $this->entityManager->flush(); return true; } } return false; }