/**
  * @param Basket $basket
  * @param User   $user
  * @return Token|null
  * @throws \Doctrine\ORM\NonUniqueResultException
  */
 public function findValidationToken(Basket $basket, User $user)
 {
     $dql = 'SELECT t FROM Phraseanet:Token t
         WHERE t.type = :type
             AND t.user = :user
             AND t.data = :basket_id
             AND (t.expiration > CURRENT_TIMESTAMP() OR t.expiration IS NULL)';
     $query = $this->_em->createQuery($dql);
     $query->setParameters([':type' => TokenManipulator::TYPE_VALIDATE, ':user' => $user, ':basket_id' => $basket->getId()]);
     return $query->getOneOrNullResult();
 }
 /**
  * @param Basket $basket
  * @param User   $user
  *
  * @return Token
  */
 public function createBasketAccessToken(Basket $basket, User $user)
 {
     return $this->create($user, self::TYPE_VIEW, null, $basket->getId());
 }
Beispiel #3
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;
 }
Beispiel #4
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;
 }
 /**
  * {@inheritDoc}
  */
 public function getId()
 {
     if ($this->__isInitialized__ === false) {
         return (int) parent::getId();
     }
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array());
     return parent::getId();
 }