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/MessageRepository.php

<?php

namespace App\ContactBundle\Repository;

use Doctrine\ORM\EntityRepository;
use App\UserBundle\Entity\UserList;

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

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

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

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

            $users = $this->getEntityManager()->getRepository(UserList::class)->findBySearchCompany('', $conf['user_list']->getCompanyId());
            $userIDArray = array();

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

            $qb = $qb->andWhere('m.created_by IN (:userIDs)')->setParameter('userIDs', $userIDArray);
        }

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

        if (isset($conf['drafts']) && $conf['drafts']) {
            $qb = $qb->andWhere('m.draft = :drafts')->setParameter('drafts', $conf['drafts']);
        }

        $qb = $qb->orderBy('m.date_to_be_sent', 'DESC');

        return $qb->getQuery();
    }

    /**
     * Get all e-mails to be sent
     *
     * @param array $smsMessageTypes
     * @return array
     */
    public function getMailsToBeSent($smsMessageTypes = array()) {

        $qb = $this->createQueryBuilder('m')
                ->join('m.message_recipient', 'mr')
                ->leftJoin('mr.message_error', 'me')
                ->where('mr.sent = :sent')->setParameter('sent', false)
                ->andWhere('m.date_to_be_sent <= :date_to_be_sent')->setParameter('date_to_be_sent', date('Y-m-d H:i:s'))
                ->andWhere('m.draft = :draft')->setParameter('draft', false)
                ->andWhere('me.id IS NULL')
        ;

        if (count($smsMessageTypes) > 0) {
            $qb->join('m.message_type', 'mt')
                    ->andWhere('mt.id NOT IN (:smsMessageTypes)')->setParameter('smsMessageTypes', $smsMessageTypes);
        }

        $query = $qb->getQuery();

//        echo var_dump($smsMessageTypes);
//        echo "<br />\r\n";
//        echo $query->getSQL() . "\r\n";

        return $query->execute();
    }
}