/** * @Route("/{id}", name="remove_profile_image", requirements={"id" = "\d+"}) * @ParamConverter("Image", class="ConnectionUserBundle:Profile\Image") */ public function removeAction(Image $image) { if (!($user = $this->getUser())) { throw new AccessDeniedException(); } if ($image->getGallery()->getUser()->getId() != $user->getId()) { throw new AccessDeniedException(); } $em = $this->getDoctrine()->getManager(); $em->remove($image); $em->flush(); return $this->redirect($this->generateUrl('edit_user_profile', array('tab' => 'gallery'))); }
private function processEventImage($event) { $em = $this->container->get('doctrine')->getManager(); $user = $this->container->get('security.context')->getToken()->getUser(); $file = $event->getFile(); $request = $event->getRequest(); $response = $event->getResponse(); $config = $event->getConfig(); if (!$file instanceof File) { throw new \Exception('Not instance of File'); } $cropResult = $this->cropImage($file, $request->request); if (!$cropResult) { throw new \Exception('Fail cropping image'); } $fileDir = str_replace($this->container->get('kernel')->getRootDir() . '/../web', "", $config['storage']['directory']); $image = new Image(); $image->setName($file->getFilename()); $image->setPath($fileDir . "/" . $user->getId() . "/" . $file->getFilename()); $em->persist($image); $em->flush(); if (file_exists($image->getUploadRootDir())) { $response['id'] = $image->getId(); $response['name'] = $image->getPath(); $response['size'] = filesize($image->getUploadRootDir()); } }
/** * {@inheritDoc} */ public function getEvent() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getEvent', array()); return parent::getEvent(); }
protected function execute(InputInterface $input, OutputInterface $output) { /* @var $em \Doctrine\ORM\EntityManager */ $em = $this->getContainer()->get('doctrine')->getManager(); $userRepo = $em->getRepository('ConnectionUserBundle:User'); $countryRepo = $em->getRepository('ConnectionCoreBundle:Country'); $stateRepo = $em->getRepository('ConnectionCoreBundle:State'); $genderRepo = $em->getRepository('ConnectionUserBundle:Profile\\Gender'); $eventCategoryRepo = $em->getRepository('ConnectionEventBundle:Category'); $userManager = $this->getContainer()->get('fos_user.user_manager'); $rootDir = $this->getContainer()->get('kernel')->getRootDir() . '/../web/'; $userArray = $this->_getUserArray(); foreach ($userArray as $userItem) { $output->writeln('Creating user: '******'username']); $user = $userRepo->findOneBy(array('username' => $userItem['username'])); if ($user) { $em->remove($user); $em->flush(); } $email = strtolower($userItem['username']) . '@mail.com'; $user = new User(); $user->setUsername($userItem['username']); $user->setEmail($email); $user->setPlainPassword('123456'); $user->setEnabled(true); $profile = new Profile(); $gender = $genderRepo->find($userItem['profile']['gender']); $profile->setGender($gender); $seek = $genderRepo->find($userItem['profile']['seek']); $profile->setSeek($seek); $profile->setBirthdate($userItem['profile']['birthdate']); $country = $countryRepo->findOneBy(array('iso' => $userItem['profile']['country'])); $profile->setCountry($country); $state = $stateRepo->findOneBy(array('name' => $userItem['profile']['state'])); $profile->setState($state); $user->setProfile($profile); $em->persist($user); $em->flush(); foreach ($userItem['events'] as $eventItem) { $event = new Event(); $event->setContactName($userItem['username']); $event->setTitle($eventItem['title']); $event->setDescription($eventItem['description']); $event->setEventDate($eventItem['date']); $event->setEmail($email); $event->setPhone('12345678'); $event->setUser($user); $collection = new ArrayCollection(); foreach ($eventItem['categories'] as $categoryItem) { $category = $eventCategoryRepo->findOneBy(array('name' => $categoryItem)); $collection->add($category); } $event->setCategory($collection); $image = new Image(); $imageName = $userItem['username'] . 'Event.jpeg'; $imagePath = 'uploads/user/event/' . $user->getId(); $pathFrom = $rootDir . 'uploads/user/fixtures/' . $imageName; $pathTo = $rootDir . $imagePath . '/' . $imageName; mkdir($rootDir . $imagePath); copy($pathFrom, $pathTo); $image->setName($imageName); $image->setPath('/' . $imagePath . '/' . $imageName); $event->setImage($image); $em->persist($event); $em->flush(); } $gallery = $user->getGalleries()->first(); $gallery->setUser($user); $gallery->setTitle('Profile Images'); $gallery->setDefault(true); $image = new Image(); $imageName = $userItem['username'] . '.jpeg'; $imagePath = 'uploads/user/profile/' . $user->getId(); $pathFrom = $rootDir . 'uploads/user/fixtures/' . $imageName; $pathTo = $rootDir . $imagePath . '/' . $imageName; mkdir($rootDir . $imagePath); copy($pathFrom, $pathTo); $image->setName($imageName); $image->setPath('/' . $imagePath . '/' . $imageName); $profile->setAvatar('/' . $imagePath . '/' . $imageName); $image->setGallery($gallery); $collection = new ArrayCollection(); $collection->add($image); $gallery->setImages($collection); $em->persist($gallery); $em->flush(); } }