/**
  * @param string $entityType
  * @param integer $entityId
  * @param User $user
  * @param \DateTime $date
  * @return bool
  */
 public function subscribe(User $user, $entityType, $entityId, \DateTime $date = null)
 {
     /** @var $em EntityManager */
     $em = $this->doctrine->getManager();
     if (!$this->isSubscriber($user, $entityType, $entityId)) {
         $subscription = new Subscription();
         $subscription->setEntityType($entityType);
         $subscription->setEntityId($entityId);
         $subscription->setUser($user);
         if ($date instanceof \DateTime) {
             $subscription->setCreatedAt($date);
         }
         $em->persist($subscription);
         $em->flush();
     }
     return true;
 }
Example #2
0
 /**
  * Import a user in the database
  *
  * @param Organization $bdeOrga
  * @param bool $flush
  * @return \Etu\Core\UserBundle\Entity\User
  */
 protected function importUser($bdeOrga = null, $flush = false)
 {
     $imagine = new Imagine();
     $webDirectory = __DIR__ . '/../../../../../../../web';
     $avatar = $this->element->getLogin() . '.jpg';
     if (!file_exists($webDirectory . '/uploads/photos/' . $this->element->getLogin() . '.jpg')) {
         // Resize photo
         try {
             $image = $imagine->open('http://local-sig.utt.fr/Pub/trombi/individu/' . $this->element->getStudentId() . '.jpg');
             $image->copy()->thumbnail(new Box(200, 200), Image::THUMBNAIL_OUTBOUND)->save($webDirectory . '/uploads/photos/' . $this->element->getLogin() . '.jpg');
         } catch (\Exception $e) {
             $avatar = 'default-avatar.png';
         }
     }
     $niveau = null;
     $branch = $this->element->getNiveau();
     preg_match('/^[^0-9]+/i', $this->element->getNiveau(), $match);
     if (isset($match[0])) {
         $branch = $match[0];
         $niveau = str_replace($branch, '', $this->element->getNiveau());
     }
     $user = new \Etu\Core\UserBundle\Entity\User();
     $user->setAvatar($avatar);
     $user->setLogin($this->element->getLogin());
     $user->setFullName($this->element->getFullName());
     $user->setFirstName($this->element->getFirstName());
     $user->setLastName($this->element->getLastName());
     $user->setFiliere($this->element->getFiliere());
     $user->setFormation(ucfirst(strtolower($this->element->getFormation())));
     $user->setNiveau($niveau);
     $user->setBranch($branch);
     $user->setMail($this->element->getMail());
     $user->setPhoneNumber($this->element->getPhoneNumber());
     $user->setRoom($this->element->getRoom());
     $user->setStudentId($this->element->getStudentId());
     $user->setTitle($this->element->getTitle());
     $user->setIsStudent($this->element->getIsStudent());
     $user->setKeepActive(false);
     $user->setUvs(implode('|', $this->element->getUvs()));
     $this->doctrine->getManager()->persist($user);
     // Subscribe to BDE
     if ($bdeOrga) {
         $subscription = new Subscription();
         $subscription->setEntityType('orga')->setEntityId($bdeOrga->getId())->setUser($user);
         $this->doctrine->getManager()->persist($subscription);
     }
     // Subscribe to all events
     $subscription = new Subscription();
     $subscription->setEntityType('event')->setEntityId(0)->setUser($user);
     $this->doctrine->getManager()->persist($subscription);
     // Flush if needed
     if ($flush) {
         $this->doctrine->getManager()->flush();
     }
     return $user;
 }
Example #3
0
 /**
  * @Route("/{id}-{slug}/edit", requirements = {"id" = "\d+"}, name="bugs_edit")
  * @Template()
  */
 public function editAction($id, $slug)
 {
     if (!$this->getUserLayer()->isUser()) {
         return $this->createAccessDeniedResponse();
     }
     /** @var $em EntityManager */
     $em = $this->getDoctrine()->getManager();
     /** @var $bug Issue */
     $bug = $em->createQueryBuilder()->select('i, u, a')->from('EtuModuleBugsBundle:Issue', 'i')->leftJoin('i.user', 'u')->leftJoin('i.assignee', 'a')->where('i.id = :id')->setParameter('id', $id)->setMaxResults(1)->getQuery()->getOneOrNullResult();
     if (!$bug) {
         throw $this->createNotFoundException('Issue #' . $id . ' not found');
     }
     if (StringManipulationExtension::slugify($bug->getTitle()) != $slug) {
         throw $this->createNotFoundException('Invalid slug');
     }
     if ($bug->getUser()->getId() != $this->getUser()->getId() && !$this->getUser()->getIsAdmin()) {
         throw new AccessDeniedHttpException('Vous n\'avez pas le droit de modifier ce signalement.');
     }
     $form = $this->createFormBuilder($bug)->add('title')->add('criticality', 'choice', array('choices' => array(Issue::CRITICALITY_SECURITY => 'bugs.criticality.60', Issue::CRITICALITY_CRITICAL => 'bugs.criticality.50', Issue::CRITICALITY_MAJOR => 'bugs.criticality.40', Issue::CRITICALITY_MINOR => 'bugs.criticality.30', Issue::CRITICALITY_VISUAL => 'bugs.criticality.20', Issue::CRITICALITY_TYPO => 'bugs.criticality.10')))->add('body')->getForm();
     $request = $this->getRequest();
     if ($request->getMethod() == 'POST' && $form->bind($request)->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($bug);
         $em->flush();
         // Subscribe automatically the user at the issue
         $subscription = new Subscription();
         $subscription->setUser($this->getUser());
         $subscription->setEntityType('issue');
         $subscription->setEntityId($bug->getId());
         $em->persist($subscription);
         $em->flush();
         $this->get('session')->getFlashBag()->set('message', array('type' => 'success', 'message' => 'bugs.bugs.edit.confirm'));
         return $this->redirect($this->generateUrl('bugs_view', array('id' => $bug->getId(), 'slug' => StringManipulationExtension::slugify($bug->getTitle()))));
     }
     return array('form' => $form->createView());
 }