public function countByUser(User $user) { $query = $this->createQueryBuilder('nv')->select('COUNT(nv.id)')->join('nv.user', 'u')->where('u.id = ' . $user->getId())->groupBy('u.id'); $result = $query->getQuery()->getArrayResult(); if (count($result) === 0) { $result = 0; } else { $result = $result[0][1]; } return $result; }
/** * @param User $user */ public function updateUser(User $user) { $date = new \DateTime(); $date->sub(new \DateInterval('PT3600S')); if ($user->getLastUpdate() < $date) { $user->setNbSujets($this->em->getRepository('TerAelisForumBundle:Post')->getNumberById($user->getId())); $user->setNbCommentaires($this->em->getRepository('TerAelisCommentBundle:Comment')->getNumberById($user->getId())); $user->setNbMessages($this->em->getRepository('TerAelisTChatBundle:Message')->getNumberById($user->getId())); $user->setLastUpdate(); $this->em->persist($user); $this->em->flush(); } }
public function findUserPost(User $user, Post $post) { return $this->createQueryBuilder('nv')->join('nv.post', 'p')->join('nv.user', 'u')->leftJoin('nv.comment', 'c')->where('p.id = ' . $post->getId())->andWhere('u.id = ' . $user->getId())->andWhere('p.publie = 1')->addSelect('c')->getQuery()->getResult(); }