Example #1
0
 /**
  * @param Basket $basket
  * @param User   $user
  *
  * @return Token
  */
 public function createBasketValidationToken(Basket $basket, User $user = null)
 {
     if (null === $basket->getValidation()) {
         throw new \InvalidArgumentException('A validation token requires a validation basket.');
     }
     return $this->create($user ?: $basket->getValidation()->getInitiator(), self::TYPE_VALIDATE, new \DateTime('+10 days'), $basket->getId());
 }
Example #2
0
 public function displayBasket(Application $app, Request $request, BasketEntity $basket)
 {
     if ($basket->getIsRead() === false) {
         $basket->setIsRead(true);
         $app['EM']->flush();
     }
     if ($basket->getValidation()) {
         if ($basket->getValidation()->getParticipant($app['authentication']->getUser())->getIsAware() === false) {
             $basket->getValidation()->getParticipant($app['authentication']->getUser())->setIsAware(true);
             $app['EM']->flush();
         }
     }
     $params = ['basket' => $basket, 'ordre' => $request->query->get('order')];
     return $app['twig']->render('prod/WorkZone/Basket.html.twig', $params);
 }
 public function displayBasket(Request $request, Basket $basket)
 {
     if ($basket->getIsRead() === false) {
         $basket->setIsRead(true);
         $this->getEntityManager()->flush();
     }
     if ($basket->getValidation()) {
         if ($basket->getValidation()->getParticipant($this->getAuthenticatedUser())->getIsAware() === false) {
             $basket->getValidation()->getParticipant($this->getAuthenticatedUser())->setIsAware(true);
             $this->getEntityManager()->flush();
         }
     }
     /** @var \Closure $filter */
     $filter = $this->app['plugin.filter_by_authorization'];
     return $this->render('prod/WorkZone/Basket.html.twig', ['basket' => $basket, 'ordre' => $request->query->get('order'), 'plugins' => ['actionbar' => $filter('workzone.basket.actionbar')]]);
 }
 /**
  * @param Basket $basket
  * @return Response
  */
 public function ajaxSetReleaseAction(Basket $basket)
 {
     try {
         if (!$basket->getValidation()) {
             throw new Exception('There is no validation session attached to this basket');
         }
         if (!$basket->getValidation()->getParticipant($this->getAuthenticatedUser())->getCanAgree()) {
             throw new Exception('You have not right to agree');
         }
         $this->assertAtLeastOneElementAgreed($basket);
         $participant = $basket->getValidation()->getParticipant($this->getAuthenticatedUser());
         /** @var Token $token */
         $token = $this->app['manipulator.token']->createBasketValidationToken($basket);
         $url = $this->app->url('lightbox', ['LOG' => $token->getValue()]);
         $this->dispatch(PhraseaEvents::VALIDATION_DONE, new ValidationEvent($participant, $basket, $url));
         $participant->setIsConfirmed(true);
         $this->app['orm.em']->merge($participant);
         $this->app['orm.em']->flush();
         $data = ['error' => false, 'datas' => $this->app->trans('Envoie avec succes')];
     } catch (Exception $e) {
         $data = ['error' => true, 'datas' => $e->getMessage()];
     }
     return $this->app->json($data);
 }
Example #5
0
 /**
  * Retrieve information about one basket
  *
  * @param  Basket $basket
  *
  * @return array
  */
 private function list_basket(Application $app, Basket $basket)
 {
     $ret = ['basket_id' => $basket->getId(), 'owner' => $this->list_user($basket->getUser()), 'created_on' => $basket->getCreated()->format(DATE_ATOM), 'description' => (string) $basket->getDescription(), 'name' => $basket->getName(), 'pusher_usr_id' => $basket->getPusher() ? $basket->getPusher()->getId() : null, 'pusher' => $basket->getPusher() ? $this->list_user($basket->getPusher()) : null, 'updated_on' => $basket->getUpdated()->format(DATE_ATOM), 'unread' => !$basket->getIsRead(), 'validation_basket' => !!$basket->getValidation()];
     if ($basket->getValidation()) {
         $users = array_map(function ($participant) use($app) {
             $user = $participant->getUser();
             return ['usr_id' => $user->getId(), 'usr_name' => $user->getDisplayName(), 'confirmed' => $participant->getIsConfirmed(), 'can_agree' => $participant->getCanAgree(), 'can_see_others' => $participant->getCanSeeOthers(), 'readonly' => $user->getId() != $app['authentication']->getUser()->getId(), 'user' => $this->list_user($user)];
         }, iterator_to_array($basket->getValidation()->getParticipants()));
         $expires_on_atom = $basket->getValidation()->getExpires();
         if ($expires_on_atom instanceof \DateTime) {
             $expires_on_atom = $expires_on_atom->format(DATE_ATOM);
         }
         $ret = array_merge(['validation_users' => $users, 'expires_on' => $expires_on_atom, 'validation_infos' => $basket->getValidation()->getValidationString($app, $app['authentication']->getUser()), 'validation_confirmed' => $basket->getValidation()->getParticipant($app['authentication']->getUser())->getIsConfirmed(), 'validation_initiator' => $basket->getValidation()->isInitiator($app['authentication']->getUser()), 'validation_initiator_user' => $this->list_user($basket->getValidation()->getInitiator())], $ret);
     }
     return $ret;
 }
Example #6
0
 /**
  * Retirve information about one basket
  *
  * @param  Basket $basket
  * @return array
  */
 public function list_basket(Basket $basket)
 {
     $ret = ['basket_id' => $basket->getId(), 'created_on' => $basket->getCreated()->format(DATE_ATOM), 'description' => (string) $basket->getDescription(), 'name' => $basket->getName(), 'pusher_usr_id' => $basket->getPusher() ? $basket->getPusher()->getId() : null, 'updated_on' => $basket->getUpdated()->format(DATE_ATOM), 'unread' => !$basket->getIsRead(), 'validation_basket' => !!$basket->getValidation()];
     if ($basket->getValidation()) {
         $users = [];
         foreach ($basket->getValidation()->getParticipants() as $participant) {
             /* @var $participant ValidationParticipant */
             $user = $participant->getUser();
             $users[] = ['usr_id' => $user->getId(), 'usr_name' => $user->getDisplayName(), 'confirmed' => $participant->getIsConfirmed(), 'can_agree' => $participant->getCanAgree(), 'can_see_others' => $participant->getCanSeeOthers(), 'readonly' => $user->getId() != $this->app['authentication']->getUser()->getId()];
         }
         $expires_on_atom = $basket->getValidation()->getExpires();
         if ($expires_on_atom instanceof DateTime) {
             $expires_on_atom = $expires_on_atom->format(DATE_ATOM);
         }
         $ret = array_merge(['validation_users' => $users, 'expires_on' => $expires_on_atom, 'validation_infos' => $basket->getValidation()->getValidationString($this->app, $this->app['authentication']->getUser()), 'validation_confirmed' => $basket->getValidation()->getParticipant($this->app['authentication']->getUser())->getIsConfirmed(), 'validation_initiator' => $basket->getValidation()->isInitiator($this->app['authentication']->getUser())], $ret);
     }
     return $ret;
 }
 /**
  * {@inheritDoc}
  */
 public function getValidation()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getValidation', array());
     return parent::getValidation();
 }