Newscoop\Entity\Repository\UserRepository::setUserPoints PHP Method

setUserPoints() public method

Set user points
public setUserPoints ( User $user = null, string | integer $authorId = null ) : void
$user Newscoop\Entity\User
$authorId string | integer
return void
    public function setUserPoints(User $user = null, $authorId = null)
    {
        $em = $this->getEntityManager();
        if (!is_null($authorId)) {
            $user = $em->getRepository('Newscoop\\Entity\\User')->findOneByAuthor($authorId);
        }
        if (!$user) {
            return false;
        }
        $query = $this->createQueryBuilder('u')->select('u.id, ' . $this->getUserPointsSelect())->where('u.id = :user')->getQuery();
        $query->setParameter('user', $user->getId());
        $result = $query->getSingleResult();
        $articlesCount = $em->getRepository('Newscoop\\Entity\\Article')->countByAuthor($user);
        $total = (int) $result['comments'] + $articlesCount;
        if ($user) {
            $user->setPoints($total);
            $em->flush();
        }
    }