Ejemplo n.º 1
0
 /**
  * Return a user notification setting given a user.
  *
  * @param User   $user
  * @param string $name
  * @param mixed  $default
  *
  * @return mixed
  */
 public function getUserNotificationSetting(User $user, $name, $default = true)
 {
     if (false === $user->getNotificationSettings()->containsKey($name)) {
         return $default;
     }
     return $user->getNotificationSettings()->get($name)->getValue();
 }
 /**
  * {@inheritdoc}
  */
 public function getMessage()
 {
     if (!$this->registeredUser) {
         throw new LogicException('You must set a user before calling getMessage');
     }
     return $this->app->trans('admin::register: un utilisateur a fait une demande d\'inscription') . "\n\n" . sprintf('%s %s', $this->registeredUser->getFirstName(), $this->registeredUser->getLastName()) . "\n\n" . sprintf('%s %s', $this->registeredUser->getJob(), $this->registeredUser->getCompany());
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function getMessage()
 {
     if (!$this->user instanceof User) {
         throw new LogicException('You must set a user before calling getMessage()');
     }
     return $this->app->trans('%user% has ordered documents', ['%user%' => $this->user->getDisplayName()]);
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function getMessage()
 {
     if (!$this->deliverer) {
         throw new LogicException('You must set a deliverer before calling getMessage');
     }
     return $this->app->trans('%user% vous a delivre votre commande, consultez la en ligne a l\'adresse suivante', ['%user%' => $this->deliverer->getDisplayName()]);
 }
 /**
  * {@inheritdoc}
  */
 public function getMessage()
 {
     if (!$this->user) {
         throw new LogicException('You must set an user before calling getMessage');
     }
     return $this->app->trans('%user% has just sent its validation report, you can now see it', ['%user%' => $this->user->getDisplayName()]);
 }
 /**
  * Get all lists entries matching a given User
  *
  * @param User $user
  * @param type $like
  */
 public function findUserList(User $user)
 {
     $dql = 'SELECT e FROM Phraseanet:UsrListEntry e
         WHERE e.user = :usr_id';
     $params = ['usr_id' => $user->getId()];
     $query = $this->_em->createQuery($dql);
     $query->setParameters($params);
     return $query->getResult();
 }
Ejemplo n.º 7
0
 public function getModelForUser(User $user, array $basList)
 {
     $rsm = new ResultSetMappingBuilder($this->em);
     $rsm->addRootEntityFromClassMetadata('Alchemy\\Phrasea\\Model\\Entities\\User', 'u');
     $selectClause = $rsm->generateSelectClause();
     $query = $this->em->createNativeQuery("\n                SELECT " . $selectClause . "\n                FROM Users u\n                    INNER JOIN basusr b ON (b.usr_id=u.id)\n                WHERE u.model_of = :user_id\n                  AND b.base_id IN (" . implode(', ', $basList) . ")\n                  AND u.deleted='0'\n                GROUP BY u.id", $rsm);
     $query->setParameter(':user_id', $user->getId());
     return $query->getResult();
 }
 /**
  * {@inheritdoc}
  */
 public function getMessage()
 {
     if (!$this->deliverer instanceof User) {
         throw new LogicException('You must set a deliverer before calling getMessage()');
     }
     if (null === $this->quantity) {
         throw new LogicException('You must set a deliverer before calling getMessage()');
     }
     return $this->app->trans('%user% a refuse %quantity% elements de votre commande', ['%user%' => $this->deliverer->getDisplayName(), '%quantity%' => $this->quantity]);
 }
Ejemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function getMessage()
 {
     if (!$this->pusher) {
         throw new LogicException('You must set a basket before calling getMessage');
     }
     if (!$this->basket) {
         throw new LogicException('You must set a basket before calling getMessage');
     }
     return $this->app->trans('You just received a push containing %quantity% documents from %user%', ['%quantity%' => count($this->basket->getElements()), '%user%' => $this->pusher->getDisplayName()]) . "\n" . $this->message;
 }
 public function findByUser(User $user)
 {
     $dql = 'SELECT u
             FROM Phraseanet:UsrAuthProvider u
             WHERE u.user = :usrId';
     $params = ['usrId' => $user->getId()];
     $query = $this->_em->createQuery($dql);
     $query->setParameters($params);
     return $query->getResult();
 }
 /**
  * {@inheritdoc}
  */
 public function getSubject()
 {
     if (!$this->user) {
         throw new LogicException('You must set an user before calling getSubject');
     }
     if (!$this->title) {
         throw new LogicException('You must set a title before calling getSubject');
     }
     return $this->app->trans("Validation request from %user% for '%title%'", ['%user%' => $this->user->getDisplayName(), '%title%' => $this->title]);
 }
Ejemplo n.º 12
0
 /**
  * Search for a UsrList like '' with a given value, for a user
  *
  * @param  User                                         $user
  * @param  type                                         $name
  * @return \Doctrine\Common\Collections\ArrayCollection
  */
 public function findUserListLike(User $user, $name)
 {
     $dql = 'SELECT l FROM Phraseanet:UsrList l
           JOIN l.owners o
         WHERE o.user = :usr_id AND l.name LIKE :name';
     $params = ['usr_id' => $user->getId(), 'name' => $name . '%'];
     $query = $this->_em->createQuery($dql);
     $query->setParameters($params);
     return $query->getResult();
 }
Ejemplo n.º 13
0
 public function findUserStory(Application $app, User $user, \record_adapter $Story)
 {
     $story = $this->findOneBy(['user' => $user->getId(), 'sbas_id' => $Story->get_sbas_id(), 'record_id' => $Story->get_record_id()]);
     if ($story) {
         try {
             $story->getRecord($app);
         } catch (NotFoundHttpException $e) {
             $this->getEntityManager()->remove($story);
             $this->getEntityManager()->flush();
             $story = null;
         }
     }
     return $story;
 }
Ejemplo n.º 14
0
 public function getSecretForUser(User $user)
 {
     $userKey = '_' . (string) $user->getId();
     if (isset($this->secrets[$userKey])) {
         return $this->secrets[$userKey];
     }
     if (null === ($secret = $this->repository->findOneBy(['creator' => $user], ['created' => 'DESC']))) {
         $token = $this->generator->generateString(64, Generator::CHAR_ALNUM | Generator::CHAR_SYMBOLS);
         $secret = new Secret($user, $token);
         $this->repository->save($secret);
     }
     $this->secrets[$userKey] = $secret;
     return $secret;
 }
Ejemplo n.º 15
0
 private function autoregisterEMail(User $to, User $registeredUser)
 {
     $body = '';
     $body .= sprintf("Login : %s\n", $registeredUser->getLogin());
     $body .= sprintf("%s : %s\n", _('admin::compte-utilisateur nom'), $registeredUser->getFirstName());
     $body .= sprintf("%s : %s\n", _('admin::compte-utilisateur prenom'), $registeredUser->getLastName());
     $body .= sprintf("%s : %s\n", _('admin::compte-utilisateur email'), $registeredUser->getEmail());
     $body .= sprintf("%s/%s\n", $registeredUser->get_job(), $registeredUser->getCompany());
     $readyToSend = false;
     try {
         $receiver = Receiver::fromUser($to);
         $readyToSend = true;
     } catch (\Exception $e) {
     }
     if ($readyToSend) {
         $mail = MailInfoSomebodyAutoregistered::create($this->app, $receiver, null, $body);
         $this->deliver($mail);
     }
     return true;
 }
Ejemplo n.º 16
0
 /**
  * Gets registration registrations for a user.
  *
  * @param User $user
  *
  * @return array
  */
 public function getRegistrationsSummaryForUser(User $user)
 {
     $data = [];
     $rsm = $this->createResultSetMappingBuilder('d');
     $rsm->addScalarResult('sbas_id', 'sbas_id');
     $rsm->addScalarResult('bas_id', 'bas_id');
     $rsm->addScalarResult('dbname', 'dbname');
     $rsm->addScalarResult('time_limited', 'time_limited');
     $rsm->addScalarResult('limited_from', 'limited_from');
     $rsm->addScalarResult('limited_to', 'limited_to');
     $rsm->addScalarResult('actif', 'actif');
     $sql = "\n        SELECT dbname, sbas.sbas_id, time_limited,\n               UNIX_TIMESTAMP( limited_from ) AS limited_from,\n               UNIX_TIMESTAMP( limited_to ) AS limited_to,\n               bas.server_coll_id, Users.id, basusr.actif,\n               bas.base_id AS bas_id , " . $rsm->generateSelectClause(['d' => 'd']) . "\n        FROM (Users, bas, sbas)\n          LEFT JOIN basusr ON ( Users.id = basusr.usr_id AND bas.base_id = basusr.base_id )\n          LEFT JOIN Registrations d ON ( d.user_id = Users.id AND bas.base_id = d.base_id )\n        WHERE bas.active = 1 AND bas.sbas_id = sbas.sbas_id\n        AND Users.id = ?\n        AND model_of = 0";
     $query = $this->_em->createNativeQuery($sql, $rsm);
     $query->setParameter(1, $user->getId());
     foreach ($query->getResult() as $row) {
         $registrationEntity = $row[0];
         $data[$row['sbas_id']][$row['bas_id']] = ['base-id' => $row['bas_id'], 'db-name' => $row['dbname'], 'active' => (bool) $row['actif'], 'time-limited' => (bool) $row['time_limited'], 'in-time' => $row['time_limited'] && !($row['limited_from'] >= time() && $row['limited_to'] <= time()), 'registration' => $registrationEntity];
     }
     return $data;
 }
Ejemplo n.º 17
0
 /**
  * Notifiy an user using the specified datas
  *
  * @param User   $user
  * @param string $datas
  */
 private function notifyUser(User $user, $datas)
 {
     $mailed = false;
     if ($this->shouldSendNotificationFor($user->getId())) {
         $readyToSend = false;
         try {
             $receiver = Receiver::fromUser($user);
             $readyToSend = true;
         } catch (\Exception $e) {
         }
         if ($readyToSend) {
             $mail = MailInfoRecordQuarantined::create($this->app, $receiver);
             $this->app['notification.deliverer']->deliver($mail);
             $mailed = true;
         }
     }
     $this->broker->notify($user->getId(), __CLASS__, $datas, $mailed);
 }
Ejemplo n.º 18
0
 public static function load_authorized_app_by_user(Application $app, User $user)
 {
     $sql = '
     SELECT a.application_id
     FROM api_accounts a, api_applications c
     WHERE usr_id = :usr_id AND c.application_id = a.application_id
     AND revoked = 0';
     $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
     $stmt->execute([':usr_id' => $user->getId()]);
     $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     $apps = [];
     foreach ($rs as $row) {
         $apps[] = new API_OAuth2_Application($app, $row['application_id']);
     }
     return $apps;
 }
 public function findReceivedValidationElementsByRecord(\record_adapter $record, User $user)
 {
     $dql = 'SELECT e
         FROM Phraseanet:BasketElement e
         JOIN e.basket b
         JOIN b.validation v
         JOIN v.participants p
         WHERE p.user = :usr_id
         AND e.record_id = :record_id
         AND e.sbas_id = :sbas_id';
     $params = ['sbas_id' => $record->get_sbas_id(), 'record_id' => $record->get_record_id(), 'usr_id' => $user->getId()];
     $query = $this->_em->createQuery($dql);
     $query->setParameters($params);
     return $query->getResult();
 }
Ejemplo n.º 20
0
 public function testSetTemplateOwner()
 {
     $template = new User();
     $user = new User();
     $template->setTemplateOwner($user);
     $this->assertSame($user, $template->getTemplateOwner());
 }
Ejemplo n.º 21
0
 /**
  * Return all actives validation where current user is involved and user basket
  *
  * @param  User  $user
  * @param  type  $sort
  * @return Array
  */
 public function findActiveValidationAndBasketByUser(User $user, $sort = null)
 {
     $dql = 'SELECT b
         FROM Phraseanet:Basket b
         LEFT JOIN b.elements e
         LEFT JOIN b.validation s
         LEFT JOIN s.participants p
         WHERE (b.user = :usr_id AND b.archived = false)
           OR (b.user != :usr_id AND p.user = :usr_id
               AND (s.expires IS NULL OR s.expires > CURRENT_TIMESTAMP())
               )';
     if ($sort == 'date') {
         $dql .= ' ORDER BY b.created DESC';
     } elseif ($sort == 'name') {
         $dql .= ' ORDER BY b.name ASC';
     }
     $query = $this->_em->createQuery($dql);
     $query->setParameters(['usr_id' => $user->getId()]);
     return $query->getResult();
 }
Ejemplo n.º 22
0
 /**
  * Creates an Emitter given a User
  *
  * @param User $user
  *
  * @return Emitter
  *
  * @throws InvalidArgumentException In case no valid email is found for user
  */
 public static function fromUser(User $user)
 {
     return new static($user->getDisplayName(), $user->getEmail());
 }
Ejemplo n.º 23
0
 /**
  * Sets email for a user.
  *
  * @param User   $user
  * @param string $email
  *
  * @throws InvalidArgumentException if email is not valid or already exists.
  * @throws RuntimeException         if email already exists.
  */
 private function doSetEmail(User $user, $email)
 {
     if (null !== $email && false === (bool) \Swift_Validate::email($email)) {
         throw new InvalidArgumentException(sprintf('Email %s is not legal.', $email));
     }
     if (null !== $this->getRepository()->findByEmail($email)) {
         throw new RuntimeException(sprintf('User with email %s already exists.', $email));
     }
     $user->setEmail($email);
 }
Ejemplo n.º 24
0
 /**
  * Saves user's ACL in cache and returns it.
  *
  * @param User $user
  *
  * @return \ACL
  */
 private function fetch(User $user)
 {
     return self::$cache[$user->getId()] = new \ACL($user, $this->app);
 }
Ejemplo n.º 25
0
 protected function get_feed(Application $app, appbox $appbox, User $user, $pub_restrict, $homelink)
 {
     $user_key = 'user_' . $user->getId();
     if ($homelink == '1') {
         $feed_key = 'feed_homelink';
     } elseif ($pub_restrict == '1') {
         $feed_key = 'feed_restricted';
     } else {
         $feed_key = 'feed_public';
     }
     if (!array_key_exists($user_key, self::$feeds) || !isset(self::$feeds[$user_key][$feed_key])) {
         if ($homelink == '1') {
             $title = $user->getDisplayName() . ' - ' . 'homelink Feed';
         } elseif ($pub_restrict == '1') {
             $title = $user->getDisplayName() . ' - ' . 'private Feed';
         } else {
             $title = $user->getDisplayName() . ' - ' . 'public Feed';
         }
         $feed = new Feed();
         $publisher = new FeedPublisher();
         $feed->setTitle('title');
         $feed->setSubtitle('');
         $feed->addPublisher($publisher);
         $publisher->setFeed($feed);
         $publisher->setIsOwner(true);
         $publisher->setUser($user);
         if ($homelink) {
             $feed->setIsPublic(true);
             $app['orm.em']->persist($feed);
             $app['orm.em']->persist($user);
             $app['orm.em']->flush();
         } elseif ($pub_restrict == 1) {
             $collections = $app->getAclForUser($user)->get_granted_base();
             $collection = array_shift($collections);
             if (!$collection instanceof collection) {
                 foreach ($appbox->get_databoxes() as $databox) {
                     foreach ($databox->get_collections() as $coll) {
                         $collection = $coll;
                         break;
                     }
                     if ($collection instanceof collection) {
                         break;
                     }
                 }
             }
             if (!$collection instanceof collection) {
                 return false;
             }
             $feed->setCollection($collection);
         }
         self::$feeds[$user_key][$feed_key] = $feed;
     } else {
         $feed = self::$feeds[$user_key][$feed_key];
     }
     return $feed;
 }
Ejemplo n.º 26
0
 public function isOwner(Basket $basket, User $user)
 {
     return $basket->getUser()->getId() === $user->getId();
 }
Ejemplo n.º 27
0
 protected function evaluateGoodUserItem($data, User $user)
 {
     foreach (['@entity@' => V1Controller::OBJECT_TYPE_USER, 'id' => $user->getId(), 'email' => $user->getEmail() ?: null, 'login' => $user->getLogin() ?: null, 'first_name' => $user->getFirstName() ?: null, 'last_name' => $user->getLastName() ?: null, 'display_name' => $user->getDisplayName() ?: null, 'address' => $user->getAddress() ?: null, 'zip_code' => $user->getZipCode() ?: null, 'city' => $user->getCity() ?: null, 'country' => $user->getCountry() ?: null, 'phone' => $user->getPhone() ?: null, 'fax' => $user->getFax() ?: null, 'job' => $user->getJob() ?: null, 'position' => $user->getActivity() ?: null, 'company' => $user->getCompany() ?: null, 'geoname_id' => $user->getGeonameId() ?: null, 'last_connection' => $user->getLastConnection() ? $user->getLastConnection()->format(DATE_ATOM) : null, 'created_on' => $user->getCreated() ? $user->getCreated()->format(DATE_ATOM) : null, 'updated_on' => $user->getUpdated() ? $user->getUpdated()->format(DATE_ATOM) : null, 'locale' => $user->getLocale() ?: null] as $key => $value) {
         $this->assertArrayHasKey($key, $data, 'Assert key is present ' . $key);
         if ($value) {
             $this->assertEquals($value, $data[$key], 'Check key ' . $key);
         }
     }
 }
Ejemplo n.º 28
0
 /**
  * Returns a boolean indicating whether the given User is the publisher of the entry.
  *
  * @param User $user
  *
  * @return boolean
  */
 public function isPublisher(User $user)
 {
     if ($this->publisher) {
         if ($this->publisher->getUser()->getId() === $user->getId()) {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 29
0
 public function grant_preview_on(record_adapter $record, User $pusher, $action)
 {
     $sql = 'REPLACE INTO records_rights
         (id, usr_id, sbas_id, record_id, preview, `case`, pusher_usr_id)
         VALUES
         (null, :usr_id, :sbas_id, :record_id, 1, :case, :pusher)';
     $params = [':usr_id' => $this->user->getId(), ':sbas_id' => $record->get_sbas_id(), ':record_id' => $record->get_record_id(), ':case' => $action, ':pusher' => $pusher->getId()];
     $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
     $stmt->execute($params);
     $stmt->closeCursor();
     $this->delete_data_from_cache(self::CACHE_RIGHTS_RECORDS);
     return $this;
 }
Ejemplo n.º 30
0
 /**
  *
  * @param Application $app
  * @param Bridge_Api  $api
  * @param User        $user
  * @param string      $dist_id
  * @param string      $name
  *
  * @return Bridge_Account
  */
 public static function create(Application $app, Bridge_Api $api, User $user, $dist_id, $name)
 {
     $sql = 'INSERT INTO bridge_accounts
         (id, api_id, dist_id, usr_id, name, created_on, updated_on)
         VALUES (null, :api_id, :dist_id, :usr_id, :name, NOW(), NOW())';
     $params = [':api_id' => $api->get_id(), ':dist_id' => $dist_id, ':usr_id' => $user->getId(), ':name' => $name];
     $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
     $stmt->execute($params);
     $stmt->closeCursor();
     $account_id = $app['phraseanet.appbox']->get_connection()->lastInsertId();
     return new self($app, $api, $account_id);
 }