18 import (
'lib.pkp.classes.log.EmailLogEntry');
29 function getById($logId, $assocType =
null, $assocId =
null) {
30 $params = array((
int) $logId);
31 if (isset($assocType)) {
32 $params[] = (int) $assocType;
33 $params[] = (int) $assocId;
37 'SELECT * FROM email_log WHERE log_id = ?' .
38 (isset($assocType)?
' AND assoc_type = ? AND assoc_id = ?':
''),
43 if ($result->RecordCount() != 0) {
44 $returner =& $this->
build($result->GetRowAssoc(
false));
60 function _getByEventType($assocType, $assocId, $eventType, $userId =
null, $rangeInfo =
null) {
65 if ($userId) $params[] = $userId;
70 ($userId ?
' LEFT JOIN email_log_users u ON e.log_id = u.email_log_id' :
'') .
71 ' WHERE e.assoc_type = ? AND
74 ($userId ?
' AND u.user_id = ?' :
''),
89 function getByAssoc($assocType =
null, $assocId =
null, $rangeInfo =
null) {
95 ORDER BY log_id DESC',
96 array((
int) $assocType, (
int) $assocId),
109 $entry = $this->newDataObject();
110 $entry->setId($row[
'log_id']);
111 $entry->setAssocType($row[
'assoc_type']);
112 $entry->setAssocId($row[
'assoc_id']);
113 $entry->setSenderId($row[
'sender_id']);
115 $entry->setEventType($row[
'event_type']);
116 $entry->setFrom($row[
'from_address']);
117 $entry->setRecipients($row[
'recipients']);
118 $entry->setCcs($row[
'cc_recipients']);
119 $entry->setBccs($row[
'bcc_recipients']);
120 $entry->setSubject($row[
'subject']);
121 $entry->setBody($row[
'body']);
134 sprintf(
'INSERT INTO email_log
135 (sender_id, date_sent, event_type, assoc_type, assoc_id, from_address, recipients, cc_recipients, bcc_recipients, subject, body)
137 (?, %s, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
140 $entry->getSenderId(),
141 $entry->getEventType(),
142 $entry->getAssocType(),
143 $entry->getAssocId(),
145 $entry->getRecipients(),
148 $entry->getSubject(),
156 return $entry->getId();
166 $params = array((
int) $logId);
167 if (isset($assocType)) {
168 $params[] = (int) $assocType;
169 $params[] = (int) $assocId;
172 'DELETE FROM email_log WHERE log_id = ?' .
173 (isset($assocType)?
' AND assoc_type = ? AND assoc_id = ?':
''),
185 'DELETE FROM email_log WHERE assoc_type = ? AND assoc_id = ?',
186 array((
int) $assocType, (
int) $assocId)
197 'UPDATE email_log SET sender_id = ? WHERE sender_id = ?',
198 array((
int) $newUserId, (
int) $oldUserId)
219 $recipients = $entry->getRecipients();
222 $pattern =
'/(?<=<)[^>]*(?=>)/';
223 preg_match_all($pattern, $recipients, $matches);
224 if (!isset($matches[0]))
return;
227 foreach ($matches[0] as $emailAddress) {
228 $user = $userDao->getUserByEmail($emailAddress);
229 if (is_a($user,
'User')) {
232 $this->
replace(
'email_log_users',
233 array(
'email_log_id' => $entry->getId(),
'user_id' => $user->getId()),
234 array(
'email_log_id',
'user_id'));