示例#1
0
 /**
  * @deprecated Deprecated since version 10.0 Bêta1, to be removed in 10.1. Use
  *             {@link User::currentSemester()} instead.
  * @return string
  */
 public static function currentSemester()
 {
     return User::currentSemester();
 }
示例#2
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());
 }