Your IP : 216.73.217.79


Current Path : /var/www/v3.cesa.co.za/src/ContactBundle/Repository/
Upload File :
Current File : /var/www/v3.cesa.co.za/src/ContactBundle/Repository/MessageCreditRepository.php

<?php

namespace App\ContactBundle\Repository;

use App\UserBundle\Entity\UserList;

/**
 * MessageCreditRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class MessageCreditRepository extends \Doctrine\ORM\EntityRepository {

    /**
     * Get all e-mail credits report
     *
     * @param array $conf
     * @return Object
     */
    public function getSiteListQuery($conf = array()) {

        $qb = $this->createQueryBuilder('mc')
                ->where('1 = 1');

        if (isset($conf['user_list']) && is_object($conf['user_list'])) {

//            echo count($conf['user_list']->getCompanies()) . '<br />';

            $userIDArray = array($conf['user_list']->getId());

            foreach ($conf['user_list']->getCompanies() as $company) {

                $users = $this->getEntityManager()->getRepository(UserList::class)->findBySearchCompany('', $company->getId(), array('user_type_id' => $conf['user_list']->getUserTypes()->getId()));

                foreach ($users as $user) {
                    $userIDArray[] = $user->getId();
                }
            }

//            var_dump($userIDArray);
//            echo '<br />';

            $qb = $qb->andWhere('mc.owner IN (:userIDs)')->setParameter('userIDs', array_unique($userIDArray));
        }

        if (isset($conf['message_type']) && is_object($conf['message_type'])) {
            $qb = $qb->andWhere('mc.message_type = :messageType')->setParameter('messageType', $conf['message_type']);
        }

        if (isset($conf['owner_ids']) && $conf['owner_ids']) {
            $qb->join('mc.owner', 'ul')->select('ul.id');
        } else {
            $qb = $qb->orderBy('mc.created_at', 'DESC');
        }

//        echo $qb->getQuery()->getSQL() . '<br />';
//        exit;

        return $qb->getQuery();
    }
}