00001 <?php
00002
00016
00017
00018
00019 import ('article.log.ArticleEmailLogEntry');
00020
00021 class ArticleEmailLogDAO extends DAO {
00028 function &getLogEntry($logId, $articleId = null) {
00029 if (isset($articleId)) {
00030 $result = &$this->retrieve(
00031 'SELECT * FROM article_email_log WHERE log_id = ? AND article_id = ?',
00032 array($logId, $articleId)
00033 );
00034 } else {
00035 $result = &$this->retrieve(
00036 'SELECT * FROM article_email_log WHERE log_id = ?', $logId
00037 );
00038 }
00039
00040 $returner = null;
00041 if ($result->RecordCount() != 0) {
00042 $returner = &$this->_returnLogEntryFromRow($result->GetRowAssoc(false));
00043 }
00044
00045 $result->Close();
00046 unset($result);
00047
00048 return $returner;
00049 }
00050
00056 function &getArticleLogEntries($articleId, $rangeInfo = null) {
00057 $returner = &$this->getArticleLogEntriesByAssoc($articleId, null, null, $rangeInfo);
00058 return $returner;
00059 }
00060
00068 function &getArticleLogEntriesByAssoc($articleId, $assocType = null, $assocId = null, $rangeInfo = null) {
00069 $params = array($articleId);
00070 if (isset($assocType)) {
00071 array_push($params, $assocType);
00072 if (isset($assocId)) {
00073 array_push($params, $assocId);
00074 }
00075 }
00076
00077 $result = &$this->retrieveRange(
00078 'SELECT * FROM article_email_log WHERE article_id = ?' . (isset($assocType) ? ' AND assoc_type = ?' . (isset($assocId) ? ' AND assoc_id = ?' : '') : '') . ' ORDER BY log_id DESC',
00079 $params, $rangeInfo
00080 );
00081
00082 $returner = &new DAOResultFactory($result, $this, '_returnLogEntryFromRow');
00083 return $returner;
00084 }
00085
00091 function &_returnLogEntryFromRow(&$row) {
00092 $entry = &new ArticleEmailLogEntry();
00093 $entry->setLogId($row['log_id']);
00094 $entry->setArticleId($row['article_id']);
00095 $entry->setSenderId($row['sender_id']);
00096 $entry->setDateSent($this->datetimeFromDB($row['date_sent']));
00097 $entry->setIPAddress($row['ip_address']);
00098 $entry->setEventType($row['event_type']);
00099 $entry->setAssocType($row['assoc_type']);
00100 $entry->setAssocId($row['assoc_id']);
00101 $entry->setFrom($row['from_address']);
00102 $entry->setRecipients($row['recipients']);
00103 $entry->setCcs($row['cc_recipients']);
00104 $entry->setBccs($row['bcc_recipients']);
00105 $entry->setSubject($row['subject']);
00106 $entry->setBody($row['body']);
00107
00108 HookRegistry::call('ArticleEmailLogDAO::_returnLogEntryFromRow', array(&$entry, &$row));
00109
00110 return $entry;
00111 }
00112
00117 function insertLogEntry(&$entry) {
00118 if ($entry->getDateSent() == null) {
00119 $entry->setDateSent(Core::getCurrentDate());
00120 }
00121 if ($entry->getIPAddress() == null) {
00122 $entry->setIPAddress(Request::getRemoteAddr());
00123 }
00124 $this->update(
00125 sprintf('INSERT INTO article_email_log
00126 (article_id, sender_id, date_sent, ip_address, event_type, assoc_type, assoc_id, from_address, recipients, cc_recipients, bcc_recipients, subject, body)
00127 VALUES
00128 (?, ?, %s, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
00129 $this->datetimeToDB($entry->getDateSent())),
00130 array(
00131 $entry->getArticleId(),
00132 $entry->getSenderId(),
00133 $entry->getIPAddress(),
00134 $entry->getEventType(),
00135 $entry->getAssocType(),
00136 $entry->getAssocId(),
00137 $entry->getFrom(),
00138 $entry->getRecipients(),
00139 $entry->getCcs(),
00140 $entry->getBccs(),
00141 $entry->getSubject(),
00142 $entry->getBody()
00143 )
00144 );
00145
00146 $entry->setLogId($this->getInsertLogId());
00147 return $entry->getLogId();
00148 }
00149
00155 function deleteLogEntry($logId, $articleId = null) {
00156 if (isset($articleId)) {
00157 return $this->update(
00158 'DELETE FROM article_email_log WHERE log_id = ? AND article_id = ?',
00159 array($logId, $articleId)
00160 );
00161
00162 } else {
00163 return $this->update(
00164 'DELETE FROM article_email_log WHERE log_id = ?', $logId
00165 );
00166 }
00167 }
00168
00173 function deleteArticleLogEntries($articleId) {
00174 return $this->update(
00175 'DELETE FROM article_email_log WHERE article_id = ?', $articleId
00176 );
00177 }
00178
00183 function transferArticleLogEntries($oldUserId, $newUserId) {
00184 return $this->update(
00185 'UPDATE article_email_log SET sender_id = ? WHERE sender_id = ?',
00186 array($newUserId, $oldUserId)
00187 );
00188 }
00189
00194 function getInsertLogId() {
00195 return $this->getInsertId('article_email_log', 'log_id');
00196 }
00197 }
00198
00199 ?>