2 namespace Report\Report;
10 class Email extends \Utility\Service\Report
18 protected $_title = 'Email Report';
22 protected $_subject = 'Email';
26 protected $_description = 'Historical report for email notifications.';
30 protected $_notes = array(
31 'Confidential information, generated using Bid 4 Cars, for more information visit bid4cars.co.za'
36 protected $_headers = array(
38 'Originator Division',
39 'Originator Dealership',
40 'Originator User Name',
41 'Originator User Surname',
45 'Receiver Dealership',
48 'Receiver Email Address',
54 protected $_fields = array(
58 'fromProfile_firstName',
59 'fromProfile_familyName',
64 'toProfile_firstName',
65 'toProfile_familyName',
72 protected $_totals = array();
76 protected $_currencyFields = array(
86 public function build()
88 #-> Prepare parameters.
94 ini_set('memory_limit','512M');
97 . 'fromCompany.name AS fromCompany_name, fromGroup.name AS fromGroup_name, fromDivision.name AS fromDivision_name, '
98 . 'fromProfile.firstName AS fromProfile_firstName, fromProfile.familyName AS fromProfile_familyName, '
99 . 'log.created AS log_created, log.emailTo AS log_emailTo, log.emailSubject AS log_emailSubject, '
100 . 'toCompany.name AS toCompany_name, toGroup.name AS toGroup_name, toDivision.name AS toDivision_name, '
101 . 'toProfile.firstName AS toProfile_firstName, toProfile.familyName AS toProfile_familyName '
102 . 'FROM \Utility\Entity\NotificationLog log '
103 . ' LEFT JOIN log.fromCompany fromCompany '
104 . ' LEFT JOIN fromCompany.group fromGroup '
105 . ' LEFT JOIN fromCompany.groupDivision fromDivision '
106 . ' LEFT JOIN log.fromProfile fromProfile '
107 . ' LEFT JOIN log.toCompany toCompany '
108 . ' LEFT JOIN toCompany.group toGroup '
109 . ' LEFT JOIN toCompany.groupDivision toDivision '
110 . ' LEFT JOIN log.toProfile toProfile '
112 . 'ORDER BY log_created ASC';
113 $where[] = 'log.emailTo IS NOT NULL';
115 #-> Construct details.
116 if (isset($this->_input['dateFrom']) && !empty($this->_input['dateFrom']))
118 $this->_queries['Date Range From'] = $this->_input['dateFrom'];
119 $where[] = 'log.created >= :dateFrom';
120 $params['dateFrom'] = new \DateTime($this->_input['dateFrom']);
122 if (isset($this->_input['dateTo']) && !empty($this->_input['dateTo']))
124 $this->_queries['Date Range Until'] = $this->_input['dateTo'];
125 $where[] = 'log.created <= :dateTo';
126 $params['dateTo'] = new \DateTime($this->_input['dateTo'] . ' 23:59:59');
128 if (isset($this->_input['group'])
129 && !empty($this->_input['group'])
130 && 'null' != $this->_input['group'])
132 $this->_queries['Group'] = $this->em
133 ->find('\Company\Entity\Group', $this->_input['group'])
135 $where[] = 'fromGroup.id = :group';
136 $params['group'] = $this->_input['group'];
138 if (isset($this->_input['groupDivision'])
139 && !empty($this->_input['groupDivision'])
140 && 'null' != $this->_input['groupDivision'])
142 $this->_queries['Division'] = $this->em
143 ->find('\Company\Entity\GroupDivision', $this->_input['groupDivision'])
145 $where[] = 'fromDivision.id = :division';
146 $params['division'] = $this->_input['groupDivision'];
148 if (isset($this->_input['company'])
149 && !empty($this->_input['company'])
150 && 'null' != $this->_input['company'])
152 $this->_queries['Dealership'] = $this->em
153 ->find('\Company\Entity\Company', $this->_input['company'])
155 $where[] = 'fromCompany.id = :company';
156 $params['company'] = $this->_input['company'];
158 if (isset($this->_input['profile'])
159 && !empty($this->_input['profile'])
160 && 'null' != $this->_input['profile'])
162 $profile = $this->_queries['User'] = $this->em
163 ->find('\User\Entity\Profile', $this->_input['profile']);
164 $this->_queries['User'] = $profile->firstName . ' ' . $profile->familyName;
165 $where[] = 'fromProfile.id = :profile';
166 $params['profile'] = $this->_input['profile'];
170 $query = str_replace(array(
174 ? 'WHERE ' . implode(' AND ', $where) . ' '
179 $query = $this->em->createQuery($query);
181 && $query->setParameters($params);
182 $this->_data = $query->getResult();