<commit_before><?php

namespace Oro\Bundle\EmailBundle\Entity\Provider;

use Doctrine\ORM\EntityManager;

use Oro\Bundle\UserBundle\Entity\User;

/**
 * Email owner provider chain
 */
class EmailProvider
{
    /** @var EntityManager */
    protected $em;

    public function __construct(EntityManager $entityManager)
    {
        $this->em = $entityManager;
    }

    public function getNewEmails(User $user, $limit)
    {
        $qb = $this->em->getRepository('OroEmailBundle:Email')->createQueryBuilder('e')
                ->leftJoin('e.emailUsers', 'eu')
                ->where('eu.organization = :organizationId')
                ->andWhere('eu.owner = :ownerId')
                ->andWhere('eu.seen = 0')
                ->orderBy('e.sentAt', 'DESC')
                ->setParameter('organizationId', $user->getOrganization()->getId())
                ->setParameter('ownerId', $user->getId())
                ->setMaxResults($limit);

        return $qb->getQuery()->getResult();
    }

    public function getCountNewEmails(User $user)
    {
        return $this->em->getRepository('OroEmailBundle:Email')->createQueryBuilder('e')
            ->select('COUNT(DISTINCT e)')
            ->leftJoin('e.emailUsers', 'eu')
            ->where('eu.organization = :organizationId')
            ->andWhere('eu.owner = :ownerId')
            ->andWhere('eu.seen = 0')
            ->setParameter('organizationId', $user->getOrganization()->getId())
            ->setParameter('ownerId', $user->getId())
            ->getQuery()
            ->getSingleScalarResult();
    }
}
<commit_msg>CRM-2385: Flash message notifications on email synchronization + on the top menu<commit_after><?php

namespace Oro\Bundle\EmailBundle\Entity\Provider;

use Doctrine\ORM\EntityManager;

use Oro\Bundle\UserBundle\Entity\User;

/**
 * Email owner provider chain
 */
class EmailProvider
{
    /** @var EntityManager */
    protected $em;

    public function __construct(EntityManager $entityManager)
    {
        $this->em = $entityManager;
    }

    public function getNewEmails(User $user, $limit)
    {
        $qb = $this->em->getRepository('OroEmailBundle:Email')->createQueryBuilder('e')
                ->leftJoin('e.emailUsers', 'eu')
                ->where('eu.organization = :organizationId')
                ->andWhere('eu.owner = :ownerId')
                ->andWhere('eu.seen = 0')
                ->groupBy('e')
                ->orderBy('e.sentAt', 'DESC')
                ->setParameter('organizationId', $user->getOrganization()->getId())
                ->setParameter('ownerId', $user->getId())
                ->setMaxResults($limit);

        return $qb->getQuery()->getResult();
    }

    public function getCountNewEmails(User $user)
    {
        return $this->em->getRepository('OroEmailBundle:Email')->createQueryBuilder('e')
            ->select('COUNT(DISTINCT e)')
            ->leftJoin('e.emailUsers', 'eu')
            ->where('eu.organization = :organizationId')
            ->andWhere('eu.owner = :ownerId')
            ->andWhere('eu.seen = 0')
            ->setParameter('organizationId', $user->getOrganization()->getId())
            ->setParameter('ownerId', $user->getId())
            ->getQuery()
            ->getSingleScalarResult();
    }
}

{'fraction_non_alphanumeric': 0.1626984126984127, 'fraction_numerical': 0.002442002442002442, 'mean_word_length': 2.395854922279793, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 68, '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': '3631322', 'n_tokens_mistral': 952, 'n_tokens_neox': 914, 'n_words': 149}