Compte les nombre de participations bonus
@param unknown_type $game
@param unknown_type $user
964275
public function checkBonusEntry($game, $user)
    {
        $query = $this->em->createQuery(
            'SELECT COUNT(e.id) FROM PlaygroundGame\Entity\Entry e 
             WHERE e.user = :user AND e.game = :game AND (e.bonus = 0 OR e.bonus IS NULL)'
        );
        $query->setParameter('user', $user);
        $query->setParameter('game', $game);
        $nbEntries = $query->getSingleScalarResult();

        $query = $this->em->createQuery(
            'SELECT COUNT(e.id) FROM PlaygroundGame\Entity\Entry e 
             WHERE e.user = :user AND e.game = :game AND e.bonus = 1'
        );
        $query->setParameter('user', $user);
        $query->setParameter('game', $game);
        $nbBonusEntries = $query->getSingleScalarResult();

        if (($nbEntries - $nbBonusEntries) <= 0) {
            return false;
        }

        return true;
    }
145281
public function update(User $user, array $data)
    {
        $user->fill([
            'name'                  => $data['name'],
            'email'                 => $data['email'],
            'birthday_at'           => $data['birthday_at'],
            'gender'                => $data['gender'],
            'locale'                => $data['locale'],
            'city'                  => $data['city'],
            'about'                 => $data['about'],
            'profession'            => $data['profession'],
            'hobbies'               => $data['hobbies'],
            'homepage'              => $data['homepage'],
            'skype'                 => $data['skype'],
            'facebook'              => $data['facebook'],
            'twitter'               => $data['twitter'],
            'main_character'        => $data['main_character'],
            'main_guild'            => $data['main_guild'],
            'favorite_race'         => $data['favorite_race'],
            'favorite_class'        => $data['favorite_class'],
            'favorite_spec'         => $data['favorite_spec'],
            'favorite_instance'     => $data['favorite_instance'],
            'favorite_battleground' => $data['favorite_battleground'],
        ]);

        // only fill password if specified
        if (array_key_exists('password', $data)
            && !empty($data['password'])) {
            $user->fill([
                'password' => bcrypt($data['password']),
            ]);
        }

        return $user->save();
    }
118982
public function setCoins(UserInterface $user, $coins)
    {
        $coinsEntry = $this->getCoinsEntry($user);

        if (!$coinsEntry) {
            $class = $this->getGameOptions()->getEntityBillingClass();
            /** @var \GameBackend\Entity\CrossFire\Billing $coinsEntry */
            $coinsEntry = new $class($user);
        }

        $coinsEntry->setCash($coinsEntry->getCash() + $coins);
        if ($coinsEntry->getCash() < 0) {
            return false;
        }

        $accEntityManager = $this->getBillingEntityManager();
        $accEntityManager->persist($coinsEntry);
        $accEntityManager->flush();

        return true;
    }
1336860
public function setUser(UserInterface $user, $plainPassword = '')
    {
        $class = $this->getGameOptions()->getEntityMemberClass();
        $accEntityManager = $this->getAccountEntityManager();

        /** @var \GameBackend\Entity\CrossFire\Repository\Member $repoTbUser */
        $repoTbUser = $accEntityManager->getRepository($class);

        if ((bool)$user->getBackendId()) {
            $usn = $user->getBackendId();
        } else {
            /** @var \GameBackend\Entity\CrossFire\Member $tbUser */
            $tbUser = new $class();
            $tbUser->setUserId($user->getUsername());
            $tbUser->setLUserId($user->getUsername());
            $tbUser->setEmail($user->getEmail());
            $accEntityManager->persist($tbUser);
            $accEntityManager->flush();

            $usn = $tbUser->getUsn();
        }

        $repoTbUser->setPassword($usn, $plainPassword);

        return $usn;
    }
771079
public function findLastEntriesByUser($game, $user, $dateLimit)
    {
        $query = $this->em->createQuery(
            'SELECT e.id FROM PlaygroundGame\Entity\Entry e 
             WHERE e.user = :user AND e.game = :game AND (e.bonus = 0 OR e.bonus IS NULL) AND e.created_at >= :date'
        );
        $query->setParameter('user', $user);
        $query->setParameter('game', $game);
        $query->setParameter('date', $dateLimit);

        $total = $query->getResult();

        return $total;
    }
1323163
public function manage(User $user, Phone $phone)
    {
        switch ($phone->phoneable_type) {
            case User::class:
                return $user->id === $phone->phoneable_id;
            default:
                return $this->allowForRoleOnTeam($user, 'Coach', $phone->phoneable->team_id);
        }
    }
1236073
public static function betsLeft(\Drupal\user\Entity\User $user, Day $day) {
    $now_date = new \DateTime();
    $now_date->setTimezone(new \DateTimeZone('GMT'));

    $injected_database = Database::getConnection();

    $subquery = $injected_database->select('mespronos__bet', 'b');
    $subquery->leftJoin('mespronos__game', 'g', 'b.game = g.id');
    $subquery->fields('g', ['id']);
    $subquery->condition('g.day', $day->id());
    $subquery->condition('b.better', $user->id());

    $query = $injected_database->select('mespronos__game', 'g');
    $query->addExpression('count(g.id)', 'nb_bet_left');
    $query->condition('g.day', $day->id());
    $query->condition('g.game_date', $now_date->format('Y-m-d\TH:i:s'), '>');
    $query->condition('g.id', $subquery, 'NOT IN');

    $results = $query->execute()->fetchAssoc();
    return $results['nb_bet_left'];
  }
233292
public function setUser(User $user): void
    {
        $this->user = $user;
        $this->user->setAcl($this);

        $userRole = $this->user->getRole();
        if ($userRole != null && !empty($this->rules)) {
            foreach ($this->rules as $role => $rules) {
                if ($userRole == $role) {
                    foreach ($rules as $uri => $rules) {
                        $this->user->setPermissionsOf($uri, (array) explode(',', $rules) /* 'read,write' etc. */);
                    }
                    break;
                }
            }
        }
    }
533084
public function setUser(UserInterface $user, $plainPassword = '')
    {
        $class = $this->getGameOptions()->getEntityAccountClass();
        $accEntityManager = $this->getAccountEntityManager();

        /** @var \GameBackend\Entity\Metin\Account\Repository\Account $repoAccount */
        $repoAccount = $accEntityManager->getRepository($class);

        if ((bool)$user->getBackendId()) {
            $userId = $user->getBackendId();
        } else {
            /** @var \GameBackend\Entity\Metin\Account\Account $account */
            $account = new $class();
            $account->setLogin($user->getUsername());
            $account->setEmail($user->getEmail());
            $accEntityManager->persist($account);
            $accEntityManager->flush();

            $userId = $account->getId();
        }

        $repoAccount->setPassword($userId, $plainPassword);

        return $userId;
    }
1340957
public function placeBid($amount, User $user)
    {
        $bid = new \Hamjoint\Mustard\Auctions\Bid();

        $bid->amount = $amount;
        $bid->placed = time();
        $bid->bidder()->associate($user);
        $bid->item()->associate($this);

        $bid->save();
    }
1039176
protected function isUserExcluded(\core_kernel_classes_Resource $delivery, User $user){
        $excludedUsers = $delivery->getPropertyValues(new \core_kernel_classes_Property(DeliveryContainerService::PROPERTY_EXCLUDED_SUBJECTS));
        return in_array($user->getIdentifier(), $excludedUsers);
    }
1061449
public function setNewActiveContributionToSection(User $user = null)
    {
        $oldActiveContribution = $this->getActiveContribution();
        $newActiveContribution = new Contribution();
        $newActiveContribution->setSection($this);
        if (null === $oldActiveContribution) {
            if (null === $user) {
                $user = $this->getAuthor();
            }
        } else {
            if (null === $user) {
                $user = $oldActiveContribution->getContributor();
            }
            if (null === $user) {
                $user = $this->getAuthor();
            }
            $newActiveContribution->setTitle($oldActiveContribution->getTitle());
            $newActiveContribution->setText($oldActiveContribution->getText());
        }
        $newActiveContribution->setContributor($user);
        $this->setActiveContribution($newActiveContribution);
    }
1001935
public function countUserFinishedPapers(Exercise $exercise, User $user)
    {
        return (int) $this->getEntityManager()
            ->createQuery('
                SELECT COUNT(p)
                FROM UJM\ExoBundle\Entity\Attempt\Paper AS p
                WHERE p.user = :user
                  AND p.exercise = :exercise
                  AND p.end IS NOT NULL
            ')
            ->setParameters([
                'user' => $user,
                'exercise' => $exercise,
            ])
            ->getSingleScalarResult();
    }
246133
public function getAvailableGames($user, $maxResults = 2)
    {
        $em = $this->serviceLocator->get('doctrine.entitymanager.orm_default');
        $today = new \DateTime("now");
        $today = $today->format('Y-m-d H:i:s');

        // Game active with a start_date before today (or without start_date)
        // and end_date after today (or without end-date)
        $query = $em->createQuery('SELECT g FROM PlaygroundGame\Entity\Game g
                WHERE NOT EXISTS (SELECT l FROM PlaygroundGame\Entity\Entry l WHERE l.game = g AND l.user = :user)
                AND (g.startDate <= :date OR g.startDate IS NULL)
                AND (g.endDate >= :date OR g.endDate IS NULL)
                AND g.active = 1 AND g.broadcastPlatform = 1
                ORDER BY g.startDate ASC');
        $query->setParameter('date', $today);
        $query->setParameter('user', $user);
        $query->setMaxResults($maxResults);
        $games = $query->getResult();

        return $games;
    }
1343125
public function before(
        User $user,
        /** @noinspection PhpUnusedParameterInspection */
        $ability,
        MemberInvitation $memberInvitation)
    {
        return $this->allowForRoleOnTeam($user, 'Coach', $memberInvitation->team_id, null);
    }
868930
public function prePersist(User $user, LifecycleEventArgs $event)
    {
        $avatarImage = $user->getAvatarImage();
        if (empty($avatarImage)) {
            $this->userService->downloadAndSetGravatarImage($user);
        }
    }
851581
public function play($game, $user, &$error = null)
    {
        //some entries can stay open during days.
        // The player can take back the entry to go on playing
        // like in a postvote or for quizzes
        // We create also an entry before the game when an optin is needed
        $entry = $this->checkExistingEntry($game, $user, true);

        // If the game needs an optin and the player has not opted in
        if ($entry && $game->getTermsOptin() && !$entry->getTermsOptin()) {
            $error = -2;
            return false;
        }

        // If the game has a cost and the player has not paid yet
        // (this case occurs when the entry has been created by the termsOptin
        // and the game has a price to play)
        if ($entry && !$entry->getPaid() && $game->getCostToPlay() > 0) {
            if (!$this->payToPlay($game, $user, $entry)) {
                $error = -3;
                return false;
            } else {
                $entry->setPaid(1);
                $entry->setPaidAmount($game->getCostToPlay());
                $entry = $this->getEntryMapper()->update($entry);
            }
        }

        if (! $entry) {
            // Play limit reached
            if ($this->hasReachedPlayLimit($game, $user)) {
                $error = -1;
                return false;
            }
            // Can't pay for the game
            if (!$this->canPayToPlay($game, $user)) {
                $error = -3;
                return false;
            }
            // Terms optin not checked
            if ($game->getTermsOptin()) {
                $error = -2;
                return false;
            }

            $ip = $this->getIp();
            $geoloc = $this->getGeoloc($ip);
            $entry = new Entry();
            $entry->setGame($game);
            $entry->setUser($user);
            $entry->setPoints(0);
            $entry->setIp($ip);
            $entry->setGeoloc($geoloc);
            $entry->setAnonymousId($this->getAnonymousId());
            
            if ($this->getAnonymousIdentifier()) {
                $entry->setAnonymousIdentifier($this->getAnonymousIdentifier());
            }
            if ($game->getCostToPlay() === 0) {
                $entry->setPaid(true);
                $entry = $this->getEntryMapper()->insert($entry);
                $this->getEventManager()->trigger(
                    __FUNCTION__ . '.post',
                    $this,
                    [
                        'user' => $user,
                        'game' => $game,
                        'entry' => $entry,
                    ]
                );
            } else {
                $entry = $this->getEntryMapper()->insert($entry);
                $entryPaid = $this->payToPlay($game, $user, $entry);
                if ($entryPaid) {
                    $entry = $this->getEntryMapper()->update($entryPaid);
                    $this->getEventManager()->trigger(
                        __FUNCTION__ . '.post',
                        $this,
                        [
                            'user' => $user,
                            'game' => $game,
                            'entry' => $entry,
                        ]
                    );
                } else {
                    $entry->setActive(false);
                    $entry = $this->getEntryMapper()->update($entry);
                    $error = -3;
                    return false;
                }
            }
        }

        return $entry;
    }