/**
  * @Route("/user/create", name="admin_user_create")
  * @Template()
  */
 public function userCreateAction()
 {
     if (!$this->getUserLayer()->isUser() || !$this->getUser()->getIsAdmin()) {
         return $this->createAccessDeniedResponse();
     }
     /** @var $user User */
     $user = new User();
     $privacyChoice = array('choices' => array(User::PRIVACY_PUBLIC => 'user.privacy.public', User::PRIVACY_PRIVATE => 'user.privacy.private'), 'attr' => array('class' => 'profileEdit-privacy-select'), 'required' => false);
     $form = $this->createFormBuilder($user)->add('login', null, array('required' => true))->add('fullName', null, array('required' => true))->add('mail', null, array('required' => true))->add('password', null, array('required' => true))->add('studentId', null, array('required' => false))->add('phoneNumber', null, array('required' => false))->add('phoneNumberPrivacy', 'choice', $privacyChoice)->add('sex', 'choice', array('choices' => array(User::SEX_MALE => 'base.user.sex.male', User::SEX_FEMALE => 'base.user.sex.female'), 'required' => false))->add('sexPrivacy', 'choice', $privacyChoice)->add('nationality', null, array('required' => false))->add('nationalityPrivacy', 'choice', $privacyChoice)->add('adress', null, array('required' => false))->add('adressPrivacy', 'choice', $privacyChoice)->add('postalCode', null, array('required' => false))->add('postalCodePrivacy', 'choice', $privacyChoice)->add('city', null, array('required' => false))->add('cityPrivacy', 'choice', $privacyChoice)->add('country', null, array('required' => false))->add('countryPrivacy', 'choice', $privacyChoice)->add('birthday', 'birthday', array('widget' => 'single_text', 'format' => 'dd/MM/yyyy', 'required' => false))->add('birthdayPrivacy', 'choice', $privacyChoice)->add('birthdayDisplayOnlyAge', null, array('required' => false))->add('personnalMail', null, array('required' => false))->add('personnalMailPrivacy', 'choice', $privacyChoice)->add('website', null, array('required' => false))->add('facebook', null, array('required' => false))->add('twitter', null, array('required' => false))->add('linkedin', null, array('required' => false))->add('viadeo', null, array('required' => false))->getForm();
     $request = $this->getRequest();
     if ($request->getMethod() == 'POST' && $form->bind($request)->isValid()) {
         $em = $this->getDoctrine()->getManager();
         if ($user->getProfileCompletion() == 100) {
             BadgesManager::userAddBadge($user, 'profile_completed');
         } else {
             BadgesManager::userRemoveBadge($user, 'profile_completed');
         }
         if ($user->getTrombiCompletion() == 100) {
             BadgesManager::userAddBadge($user, 'trombi_completed');
         } else {
             BadgesManager::userRemoveBadge($user, 'trombi_completed');
         }
         BadgesManager::userPersistBadges($user);
         $user->setPassword($this->get('etu.user.crypting')->encrypt($user->getPassword()));
         $user->setKeepActive(true);
         $em->persist($user);
         $em->flush();
         $this->get('session')->getFlashBag()->set('message', array('type' => 'success', 'message' => 'user.admin.userCreate.confirm'));
         return $this->redirect($this->generateUrl('user_view', array('login' => $user->getLogin())));
     }
     return array('user' => $user, 'form' => $form->createView());
 }
Beispiel #2
0
 private function giveBadges()
 {
     $user = $this->getUser();
     $em = $this->getDoctrine()->getManager();
     $threads = $em->createQueryBuilder()->select('t')->from('EtuModuleForumBundle:Thread', 't')->where('t.author = :user')->setParameter('user', $user)->getQuery()->getResult();
     $nbThreads = count($threads);
     if ($nbThreads >= 1) {
         BadgesManager::userAddBadge($user, 'mysterion', 1);
         BadgesManager::userPersistBadges($user);
     }
     if ($nbThreads >= 10) {
         BadgesManager::userAddBadge($user, 'mysterion', 2);
         BadgesManager::userPersistBadges($user);
     }
     if ($nbThreads >= 20) {
         BadgesManager::userAddBadge($user, 'mysterion', 3);
         BadgesManager::userPersistBadges($user);
     }
     if ($nbThreads >= 40) {
         BadgesManager::userAddBadge($user, 'mysterion', 4);
         BadgesManager::userPersistBadges($user);
     }
     $messages = $em->createQueryBuilder()->select('m')->from('EtuModuleForumBundle:Message', 'm')->where('m.author = :user')->setParameter('user', $user)->getQuery()->getResult();
     $nbMessages = count($messages);
     if ($nbMessages >= 1) {
         BadgesManager::userAddBadge($user, 'monkey', 1);
         BadgesManager::userPersistBadges($user);
     }
     if ($nbMessages >= 20) {
         BadgesManager::userAddBadge($user, 'monkey', 2);
         BadgesManager::userPersistBadges($user);
     }
     if ($nbMessages >= 50) {
         BadgesManager::userAddBadge($user, 'monkey', 3);
         BadgesManager::userPersistBadges($user);
     }
     if ($nbMessages >= 100) {
         BadgesManager::userAddBadge($user, 'monkey', 4);
         BadgesManager::userPersistBadges($user);
     }
     if ($nbMessages >= 500) {
         BadgesManager::userAddBadge($user, 'monkey', 5);
         BadgesManager::userPersistBadges($user);
     }
 }
 /**
  * Update the element in the database
  *
  * @return DbUser
  */
 public function update()
 {
     /*
      * Update:
      *      - formation
      *      - niveau
      *      - filiere
      *      - uvs
      *      - semesters history
      */
     $persist = false;
     $user = $this->database;
     $history = $user->addCureentSemesterToHistory();
     $niveau = null;
     $branch = $this->ldap->getNiveau();
     preg_match('/^[^0-9]+/i', $this->ldap->getNiveau(), $match);
     if (isset($match[0])) {
         $branch = $match[0];
         $niveau = str_replace($branch, '', $this->ldap->getNiveau());
     }
     // Updates
     if (ucfirst(strtolower($this->ldap->getFormation())) != $this->database->getFormation()) {
         $persist = true;
         $user->setFormation(ucfirst(strtolower($this->ldap->getFormation())));
     }
     if ($niveau != $this->database->getNiveau()) {
         $persist = true;
         $user->setNiveau($niveau);
     }
     if ($branch != $this->database->getBranch()) {
         $persist = true;
         $user->setBranch($branch);
     }
     if ($this->ldap->getFiliere() != $this->database->getFiliere()) {
         $persist = true;
         $user->setFiliere($this->ldap->getFiliere());
     }
     if (implode('|', $this->ldap->getUvs()) != $this->database->getUvs()) {
         $persist = true;
         $user->setUvs(implode('|', $this->ldap->getUvs()));
     }
     /*
      * Add badges
      */
     if (substr($history['niveau'], 0, 2) == 'TC' && substr($user->getNiveau(), 0, 2) != 'TC') {
         BadgesManager::userAddBadge($user, 'tc_survivor');
         BadgesManager::userPersistBadges($user);
     }
     if ($persist) {
         $this->doctrine->getManager()->persist($user);
     }
     return $persist;
 }
Beispiel #4
0
 /**
  * @Route("/{slug}-{name}/send-review", name="uvs_view_send_review")
  * @Template()
  */
 public function sendReviewAction(Request $request, $slug, $name)
 {
     if (!$this->getUserLayer()->isUser()) {
         return $this->createAccessDeniedResponse();
     }
     /** @var EntityManager $em */
     $em = $this->getDoctrine()->getManager();
     /** @var UV $uv */
     $uv = $em->getRepository('EtuModuleUVBundle:UV')->findOneBy(array('slug' => $slug));
     if (!$uv) {
         throw $this->createNotFoundException(sprintf('UV for slug %s not found', $slug));
     }
     if (StringManipulationExtension::slugify($uv->getName()) != $name) {
         return $this->redirect($this->generateUrl('uvs_view_send_review', array('slug' => $uv->getSlug(), 'name' => StringManipulationExtension::slugify($uv->getName()))), 301);
     }
     $review = new Review();
     $review->setUv($uv)->setSender($this->getUser())->setSemester(User::currentSemester());
     $form = $this->createFormBuilder($review)->add('type', 'choice', array('choices' => Review::$types, 'required' => true))->add('semester', 'choice', array('choices' => Review::availableSemesters(), 'required' => true))->add('file', null, array('required' => true))->getForm();
     if ($request->getMethod() == 'POST' && $form->submit($request)->isValid()) {
         $review->upload();
         $em->persist($review);
         $em->flush();
         // Notify subscribers
         $notif = new Notification();
         $review->file = null;
         $notif->setModule($this->getCurrentBundle()->getIdentifier())->setHelper('uv_new_review')->setAuthorId($this->getUser()->getId())->setEntityType('uv')->setEntityId($uv->getId())->addEntity($review);
         $this->getNotificationsSender()->send($notif);
         // Add badges
         $count = $em->createQueryBuilder()->select('COUNT(r) as nb')->from('EtuModuleUVBundle:Review', 'r')->where('r.sender = :user')->setParameter('user', $this->getUser()->getId())->getQuery()->getSingleScalarResult();
         $user = $this->getUser();
         if ($count >= 1) {
             BadgesManager::userAddBadge($user, 'uvs_reviews', 1);
         } else {
             BadgesManager::userRemoveBadge($user, 'uvs_reviews', 1);
         }
         if ($count >= 2) {
             BadgesManager::userAddBadge($user, 'uvs_reviews', 2);
         } else {
             BadgesManager::userRemoveBadge($user, 'uvs_reviews', 2);
         }
         if ($count >= 4) {
             BadgesManager::userAddBadge($user, 'uvs_reviews', 3);
         } else {
             BadgesManager::userRemoveBadge($user, 'uvs_reviews', 3);
         }
         if ($count >= 10) {
             BadgesManager::userAddBadge($user, 'uvs_reviews', 4);
         } else {
             BadgesManager::userRemoveBadge($user, 'uvs_reviews', 4);
         }
         BadgesManager::userPersistBadges($user);
         $em->persist($user);
         $em->flush();
         $this->get('session')->getFlashBag()->set('message', array('type' => 'success', 'message' => 'uvs.main.sendReview.confirm'));
         return $this->redirect($this->generateUrl('uvs_view', array('slug' => $slug, 'name' => $name)));
     }
     return array('uv' => $uv, 'form' => $form->createView());
 }
Beispiel #5
0
 /**
  * @Route(
  *      "/unfollow/{entityType}/{entityId}",
  *      requirements={"entityType"="[a-z\-_]+", "entityId" = "\d+"},
  *      defaults={"_format"="json"},
  *      name="notifs_unsubscribe",
  *      options={"expose"=true}
  * )
  */
 public function unsubscribeAction($entityType, $entityId)
 {
     if (!$this->getUserLayer()->isUser()) {
         return new Response(json_encode(array('status' => 403, 'message' => 'You are not allowed to access this URL as anonymous or organization.')), 403);
     }
     $user = $this->getUser();
     if (!$user->testingContext) {
         $this->getSubscriptionsManager()->unsubscribe($user, $entityType, $entityId);
     }
     /** @var $em EntityManager */
     $em = $this->getDoctrine()->getManager();
     $count = $em->createQueryBuilder()->select('COUNT(s) as nb')->from('EtuCoreBundle:Subscription', 's')->where('s.user = :user')->setParameter('user', $user->getId())->getQuery()->getSingleScalarResult();
     $count = (int) $count;
     if ($count >= 10) {
         BadgesManager::userAddBadge($user, 'subscriber', 1);
     } else {
         BadgesManager::userRemoveBadge($user, 'subscriber', 1);
     }
     if ($count >= 20) {
         BadgesManager::userAddBadge($user, 'subscriber', 2);
     } else {
         BadgesManager::userRemoveBadge($user, 'subscriber', 2);
     }
     if ($count >= 30) {
         BadgesManager::userAddBadge($user, 'subscriber', 3);
     } else {
         BadgesManager::userRemoveBadge($user, 'subscriber', 3);
     }
     BadgesManager::userPersistBadges($user);
     $em->persist($user);
     $em->flush();
     return new Response(json_encode(array('status' => 200, 'message' => $this->get('translator')->trans('core.subscriptions.api.confirm_unfollow'))));
 }
 /**
  * @Route("/user/trombi/edit", name="user_trombi_edit")
  * @Template()
  */
 public function trombiEditAction()
 {
     if (!$this->getUserLayer()->isUser()) {
         return $this->createAccessDeniedResponse();
     }
     /** @var $user User */
     $user = $this->getUser();
     $form = $this->createFormBuilder($user)->add('surnom', null, array('required' => false))->add('jadis', null, array('required' => false, 'attr' => array('class' => 'trombi-textarea')))->add('passions', null, array('required' => false, 'attr' => array('class' => 'trombi-textarea')))->getForm();
     $request = $this->getRequest();
     if ($request->getMethod() == 'POST' && $form->bind($request)->isValid()) {
         $em = $this->getDoctrine()->getManager();
         if ($user->getTrombiCompletion() == 100) {
             BadgesManager::userAddBadge($user, 'trombi_completed');
         } else {
             BadgesManager::userRemoveBadge($user, 'trombi_completed');
         }
         BadgesManager::userPersistBadges($user);
         $em->persist($user);
         $em->flush();
         $this->get('session')->getFlashBag()->set('message', array('type' => 'success', 'message' => 'user.profile.trombiEdit.confirm'));
         return $this->redirect($this->generateUrl('user_profile'));
     }
     return array('form' => $form->createView());
 }