/**
  * Creates a user by the new user entity
  *
  * @param User $user
  *
  * @return SimpleUserOverview
  */
 public static function fromAggregateRootDetails(User $user)
 {
     $credentials = $user->getCredentials();
     $identifier = $user->getId();
     $profileData = $user->getSimpleProfile();
     return new self($identifier, $credentials->getUsername(), $profileData->getEmail(), $profileData->getLocale());
 }
예제 #2
0
 /**
  * Shares a post
  *
  * @param User $user
  *
  * @return $this
  *
  * @throws \LogicException If the author tries to share its own post
  * @throws \LogicException If the post is already shared by the user
  */
 public function share(User $user)
 {
     if ($this->author->getId() === ($userId = $user->getId())) {
         throw new \LogicException('Author cannot share its own post!');
     }
     if ($this->canBeShared($userId)) {
         throw new \LogicException(sprintf('The user "%d" has already shared this post!', $userId));
     }
     $share = new SharedPost($user);
     $share->share();
     $this->shares->add($share);
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function findFollowingByFollowing(User $user, $maxQueryResultLength = 5)
 {
     $qb = $this->getEntityManager()->createQueryBuilder();
     $limit = (int) $maxQueryResultLength;
     $userIds = array_map(function (User $user) {
         return $user->getId();
     }, array_merge($user->getFollowing(), [$user]));
     $qb->select('user')->from('SEN_User:User', 'user')->join('SEN_User:User', 'following', Join::WITH, $qb->expr()->in('following.identifier', ':followingIds'))->where($qb->expr()->isMemberOf('user', 'following.following'))->andWhere($qb->expr()->notIn('user.identifier', $userIds))->setParameter(':followingIds', $userIds);
     $qb->setMaxResults($limit);
     return $qb->getQuery()->getResult();
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function calculateSortPriority(User $perspective)
 {
     $points = 0;
     if ($this->isMarked($perspective->getId())) {
         $points += self::HIGH_SORT_CRITERION;
     }
     if ($perspective->follows($this->author->getCredentials()->getUsername())) {
         $points += self::HIGH_SORT_CRITERION;
     }
     if ($this->isShortlyWritten()) {
         $points += self::SIMPLE_SORT_CRITERION;
     }
     if ($this->isCurrent()) {
         $points += self::NORMAL_SORT_CRITERION;
     }
     return $points;
 }