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();
}
}