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(); }
/** * 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(); }
/** * 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(); }
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(); }
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; }
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; }
/** * 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; }
/** * 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); }
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(); }
/** * 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(); }
/** * 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); }
public static function load_with_user(Application $app, API_OAuth2_Application $application, User $user) { $sql = 'SELECT api_account_id FROM api_accounts WHERE usr_id = :usr_id AND application_id = :application_id'; $params = [":usr_id" => $user->getId(), ":application_id" => $application->get_id()]; $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute($params); $row = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); if (!$row) { throw new NotFoundHttpException('Account nof found.'); } return new self($app, $row['api_account_id']); }
private function list_user(User $user) { switch ($user->getGender()) { case User::GENDER_MR: $gender = 'Mr'; break; case User::GENDER_MRS: $gender = 'Mrs'; break; case User::GENDER_MISS: $gender = 'Miss'; break; } return ['@entity@' => self::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, 'gender' => $gender, '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]; }
/** * Finds templates owned by a given user. * * @param User $user * * @return array */ public function findTemplateOwner(User $user) { return $this->findBy(['templateOwner' => $user->getId()]); }
/** * {@inheritDoc} */ public function getId() { if ($this->__isInitialized__ === false) { return (int) parent::getId(); } $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array()); return parent::getId(); }
/** * Returns an instance of FeedPublisher matching to the given user. * * @param User $user * * @return FeedPublisher */ public function getPublisher(User $user) { foreach ($this->getPublishers() as $publisher) { if ($publisher->getUser()->getId() == $user->getId()) { return $publisher; } } return null; }
/** * 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; }
private function formatUser(User $user) { $subtitle = array_filter([$user->getJob(), $user->getCompany()]); return ['type' => 'USER', 'usr_id' => $user->getId(), 'firstname' => $user->getFirstName(), 'lastname' => $user->getLastName(), 'email' => $user->getEmail(), 'display_name' => $user->getDisplayName(), 'subtitle' => implode(', ', $subtitle)]; }
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; }
/** * * @return ValidationData */ public function getUserValidationDatas(User $user) { foreach ($this->validation_datas as $validationData) { if ($validationData->getParticipant()->getUser()->getId() == $user->getId()) { return $validationData; } } throw new \Exception('There is no such participant ' . $user->getEmail()); }
/** * * @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); }
/** * Deletes registration for given user. * * @param User $user * @param \collection[] $collections * * @return mixed */ public function deleteUserRegistrations(User $user, array $collections) { $qb = $this->getRepository()->createQueryBuilder('d'); $qb->delete('Phraseanet:Registration', 'd'); $qb->where($qb->expr()->eq('d.user', ':user')); $qb->setParameter(':user', $user->getId()); if (count($collections) > 0) { $qb->andWhere('d.baseId IN (:bases)'); $qb->setParameter(':bases', array_map(function ($collection) { return $collection->get_base_id(); }, $collections)); } return $qb->getQuery()->execute(); }
public function isOwner(Basket $basket, User $user) { return $basket->getUser()->getId() === $user->getId(); }
protected static function resetUsersRights(Application $app, User $user) { switch ($user->getId()) { case self::$fixtureIds['user']['test_phpunit']: self::giveRightsToUser($app, $user); $app['acl']->get($user)->set_admin(true); $app['acl']->get(self::$DI['user'])->revoke_access_from_bases([self::$DI['collection_no_access']->get_base_id()]); $app['acl']->get(self::$DI['user'])->set_masks_on_base(self::$DI['collection_no_access_by_status']->get_base_id(), '00000000000000000000000000010000', '00000000000000000000000000010000', '00000000000000000000000000010000', '00000000000000000000000000010000'); break; case self::$fixtureIds['user']['user_1']: case self::$fixtureIds['user']['user_2']: case self::$fixtureIds['user']['user_3']: case self::$fixtureIds['user']['test_phpunit_not_admin']: case self::$fixtureIds['user']['test_phpunit_alt1']: case self::$fixtureIds['user']['test_phpunit_alt2']: case self::$fixtureIds['user']['user_template']: self::giveRightsToUser($app, $user); $app['acl']->get($user)->set_admin(false); $app['acl']->get(self::$DI['user'])->revoke_access_from_bases([self::$DI['collection_no_access']->get_base_id()]); $app['acl']->get(self::$DI['user'])->set_masks_on_base(self::$DI['collection_no_access_by_status']->get_base_id(), '00000000000000000000000000010000', '00000000000000000000000000010000', '00000000000000000000000000010000', '00000000000000000000000000010000'); break; default: throw new \InvalidArgumentException(sprintf('User %s not found', $user->getLogin())); } }
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; }
/** * Restrict user with the provided last model * * @param User|int|null $login * * @return $this */ public function last_model_is($login = null) { $this->last_model = $login instanceof User ? $login->getId() : $login; return $this; }
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); } } }
/** * Return true if one of the entry is related to the given user * * @param User $user * @return boolean */ public function has(User $user) { return $this->entries->exists(function ($key, $entry) use($user) { return $entry->getUser()->getId() === $user->getId(); }); }
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; }
/** * Removes all user's rights. * * @param User $user */ private function cleanRights(User $user) { foreach (['DELETE FROM `basusr` WHERE usr_id = :usr_id', 'DELETE FROM `sbasusr` WHERE usr_id = :usr_id'] as $sql) { $stmt = $this->appboxConnection->prepare($sql); $stmt->execute([':usr_id' => $user->getId()]); $stmt->closeCursor(); } }