text changes to registration mail content
[namibia] / module / Report / src / Report / Report / Email.php
1 <?php
2 namespace Report\Report;
3
4
5
6 /**
7  * SMS Report.
8  * @author andre.fourie
9  */
10 class Email extends \Utility\Service\Report
11 {
12
13
14
15         /**
16          * @var string
17          */
18         protected $_title  = 'Email Report';
19         /**
20          * @var string
21          */
22         protected $_subject = 'Email';
23         /**
24          * @var string
25          */
26         protected $_description = 'Historical report for email notifications.';
27         /**
28          * @var array
29          */
30         protected $_notes = array(
31                         'Confidential information, generated using Bid 4 Cars, for more information visit bid4cars.com.na'
32         );
33         /**
34          * @var array
35          */
36         protected $_headers = array(
37                         'Originator Group',
38                         'Originator Division',
39                         'Originator Dealership',
40                         'Originator User Name',
41                         'Originator User Surname',
42                         'Date & Time Sent',
43                         'Receiver Group',
44                         'Receiver Division',
45                         'Receiver Dealership',
46                         'Receiver Name',
47                         'Receiver Surname',
48                         'Receiver Email Address',
49                         'Email Subject'
50         );
51         /**
52          * @var array
53          */
54         protected $_fields = array(
55                         'fromGroup_name',
56                         'fromDivision_name',
57                         'fromCompany_name',
58                         'fromProfile_firstName',
59                         'fromProfile_familyName',
60                         'log_created',
61                         'toGroup_name',
62                         'toDivision_name',
63                         'toCompany_name',
64                         'toProfile_firstName',
65                         'toProfile_familyName',
66                         'log_emailTo',
67                         'log_emailSubject'
68         );
69         /**
70          * @var array
71          */
72         protected $_totals = array();
73         /**
74          * @var array
75          */
76         protected $_currencyFields = array(
77                         'clickValue',
78                         'total'
79         );
80
81
82
83         /**
84          * Build the dataset.
85          */
86         public function build()
87         {
88                 #-> Prepare parameters.
89                 $join      = array();
90                 $leftJion  = array();
91                 $where     = array();
92                 $params    = array();
93
94                 ini_set('memory_limit','512M');
95
96                 $query = 'SELECT '
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 '
111                                 . '[WHERE] '
112                                 . 'ORDER BY log_created ASC';
113                 $where[] = 'log.emailTo IS NOT NULL';
114
115                 #-> Construct details.
116                 if (isset($this->_input['dateFrom']) && !empty($this->_input['dateFrom']))
117                 {
118                         $this->_queries['Date Range From'] = $this->_input['dateFrom'];
119                         $where[] = 'log.created >= :dateFrom';
120                         $params['dateFrom'] = new \DateTime($this->_input['dateFrom']);
121                 }
122                 if (isset($this->_input['dateTo']) && !empty($this->_input['dateTo']))
123                 {
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');
127                 }
128                 if (isset($this->_input['group'])
129                                 && !empty($this->_input['group'])
130                                 && 'null' != $this->_input['group'])
131                 {
132                         $this->_queries['Group'] = $this->em
133                                 ->find('\Company\Entity\Group', $this->_input['group'])
134                                 ->name;
135                         $where[] = 'fromGroup.id = :group';
136                         $params['group'] = $this->_input['group'];
137                 }
138                 if (isset($this->_input['groupDivision'])
139                                 && !empty($this->_input['groupDivision'])
140                                 && 'null' != $this->_input['groupDivision'])
141                 {
142                         $this->_queries['Division'] = $this->em
143                                 ->find('\Company\Entity\GroupDivision', $this->_input['groupDivision'])
144                                 ->name;
145                         $where[] = 'fromDivision.id = :division';
146                         $params['division'] = $this->_input['groupDivision'];
147                 }
148                 if (isset($this->_input['company'])
149                                 && !empty($this->_input['company'])
150                                 && 'null' != $this->_input['company'])
151                 {
152                         $this->_queries['Dealership'] = $this->em
153                                 ->find('\Company\Entity\Company', $this->_input['company'])
154                                 ->name;
155                         $where[] = 'fromCompany.id = :company';
156                         $params['company'] = $this->_input['company'];
157                 }
158                 if (isset($this->_input['profile'])
159                                 && !empty($this->_input['profile'])
160                                 && 'null' != $this->_input['profile'])
161                 {
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'];
167                 }
168
169                 #-> Finalize query.
170                 $query = str_replace(array(
171                                 '[WHERE]'
172                         ), array(
173                                 !empty($where)
174                                         ? 'WHERE ' . implode(' AND ', $where) . ' '
175                                         : ' '
176                         ), $query);
177
178                 #-> Collect data.
179                 $query = $this->em->createQuery($query);
180                 !empty($params)
181                         && $query->setParameters($params);
182                 $this->_data = $query->getResult();
183         }
184
185 }