<commit_before><?php

namespace Esgi\BlogBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
 * PostsRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class PostsRepository extends EntityRepository
{
    /**
     * Get post datas by it's ID joined to User's Entity
     *
     * @return Post
     */
    public function findOneByIdJoinedToUser($id)
    {
        $query = $this->getEntityManager()
            ->createQuery('
            SELECT p, u
            FROM EsgiBlogBundle:Posts p
            JOIN p.user u
            WHERE p.id = :id'
            )->setParameter('id', $id);

        try {
            return $query->getSingleResult();
        } catch (\Doctrine\ORM\NoResultException $e) {
            return null;
        }
    }

    /**
     * Get post datas by it's slug joined to User's Entity
     *
     * @return Post
     */
    public function findOneBySlugJoinedToUser($postSlug)
    {
        $query = $this->getEntityManager()
            ->createQuery('
            SELECT p, u
            FROM EsgiBlogBundle:Posts p
            JOIN p.user u
            WHERE p.postSlug = :postSlug'
            )->setParameter('postSlug', $postSlug);

        try {
            return $query->getSingleResult();
        } catch (\Doctrine\ORM\NoResultException $e) {
            return null;
        }
    }

    public function findByCategory($id)
    {
        $query = $this->createQueryBuilder('p')
            ->select('p')
            ->leftJoin('p.category', 'c')
            ->addSelect('c');

        $query = $query->add('where', $query->expr()->in('c', ':c'))
            ->setParameter('c', $id)
            ->getQuery()
            ->getResult();

        return $query;
    }<commit_msg>Ajout jointure commentaires / posts dans repository pour findByPost($id)<commit_after><?php

namespace Esgi\BlogBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
 * PostsRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class PostsRepository extends EntityRepository
{
    /**
     * Get post datas by it's ID joined to User's Entity
     *
     * @return Post
     */
    public function findOneByIdJoinedToUser($id)
    {
        $query = $this->getEntityManager()
            ->createQuery('
            SELECT p, u
            FROM EsgiBlogBundle:Posts p
            JOIN p.user u
            WHERE p.id = :id'
            )->setParameter('id', $id);

        try {
            return $query->getSingleResult();
        } catch (\Doctrine\ORM\NoResultException $e) {
            return null;
        }
    }

    /**
     * Get post datas by it's slug joined to User's Entity
     *
     * @return Post
     */
    public function findOneBySlugJoinedToUser($postSlug)
    {
        $query = $this->getEntityManager()
            ->createQuery('
            SELECT p, u
            FROM EsgiBlogBundle:Posts p
            JOIN p.user u
            WHERE p.postSlug = :postSlug'
            )->setParameter('postSlug', $postSlug);

        try {
            return $query->getSingleResult();
        } catch (\Doctrine\ORM\NoResultException $e) {
            return null;
        }
    }

    public function findByCategory($id)
    {
        $query = $this->createQueryBuilder('p')
            ->select('p')
            ->leftJoin('p.category', 'c')
            ->addSelect('c');

        $query = $query->add('where', $query->expr()->in('c', ':c'))
            ->setParameter('c', $id)
            ->getQuery()
            ->getResult();

        return $query;
    }

    /**
     * Find comments by post id
     *
     * @param $id
     * @return array|\Doctrine\ORM\QueryBuilder
     */
    public function findByPost($id)
    {
        $query = $this->createQueryBuilder('c')
            ->select('c')
            ->leftJoin('c.post', 'p')
            ->addSelect('p');

        $query = $query->add('where', $query->expr()->in('p', ':p'))
            ->setParameter('p', $id)
            ->getQuery()
            ->getResult();

        return $query;
    }
{'fraction_non_alphanumeric': 0.1341581756428918, 'fraction_numerical': 0.0, 'mean_word_length': 1.7377158034528553, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2227319', 'n_tokens_mistral': 1229, 'n_tokens_neox': 1168, 'n_words': 283}