00001 <?php
00002
00016
00017
00018
00019 import ('article.log.ArticleEventLogEntry');
00020
00021 class ArticleEventLogDAO extends DAO {
00028 function &getLogEntry($logId, $articleId = null) {
00029 if (isset($articleId)) {
00030 $result = &$this->retrieve(
00031 'SELECT * FROM article_event_log WHERE log_id = ? AND article_id = ?',
00032 array($logId, $articleId)
00033 );
00034 } else {
00035 $result = &$this->retrieve(
00036 'SELECT * FROM article_event_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
00070 function &getArticleLogEntriesByAssoc($articleId, $assocType = null, $assocId = null, $rangeInfo = null) {
00071 $params = array($articleId);
00072 if (isset($assocType)) {
00073 array_push($params, $assocType);
00074 if (isset($assocId)) {
00075 array_push($params, $assocId);
00076 }
00077 }
00078
00079 $result = &$this->retrieveRange(
00080 'SELECT * FROM article_event_log WHERE article_id = ?' . (isset($assocType) ? ' AND assoc_type = ?' . (isset($assocId) ? ' AND assoc_id = ?' : '') : '') . ' ORDER BY log_id DESC',
00081 $params, $rangeInfo
00082 );
00083
00084 $returner = &new DAOResultFactory($result, $this, '_returnLogEntryFromRow');
00085 return $returner;
00086 }
00087
00093 function &_returnLogEntryFromRow(&$row) {
00094 $entry = &new ArticleEventLogEntry();
00095 $entry->setLogId($row['log_id']);
00096 $entry->setArticleId($row['article_id']);
00097 $entry->setUserId($row['user_id']);
00098 $entry->setDateLogged($this->datetimeFromDB($row['date_logged']));
00099 $entry->setIPAddress($row['ip_address']);
00100 $entry->setLogLevel($row['log_level']);
00101 $entry->setEventType($row['event_type']);
00102 $entry->setAssocType($row['assoc_type']);
00103 $entry->setAssocId($row['assoc_id']);
00104 $entry->setMessage($row['message']);
00105
00106 HookRegistry::call('ArticleEventLogDAO::_returnLogEntryFromRow', array(&$entry, &$row));
00107
00108 return $entry;
00109 }
00110
00115 function insertLogEntry(&$entry) {
00116 if ($entry->getDateLogged() == null) {
00117 $entry->setDateLogged(Core::getCurrentDate());
00118 }
00119 if ($entry->getIPAddress() == null) {
00120 $entry->setIPAddress(Request::getRemoteAddr());
00121 }
00122 $this->update(
00123 sprintf('INSERT INTO article_event_log
00124 (article_id, user_id, date_logged, ip_address, log_level, event_type, assoc_type, assoc_id, message)
00125 VALUES
00126 (?, ?, %s, ?, ?, ?, ?, ?, ?)',
00127 $this->datetimeToDB($entry->getDateLogged())),
00128 array(
00129 $entry->getArticleId(),
00130 $entry->getUserId(),
00131 $entry->getIPAddress(),
00132 $entry->getLogLevel(),
00133 $entry->getEventType(),
00134 $entry->getAssocType(),
00135 $entry->getAssocId(),
00136 $entry->getMessage()
00137 )
00138 );
00139
00140 $entry->setLogId($this->getInsertLogId());
00141 return $entry->getLogId();
00142 }
00143
00149 function deleteLogEntry($logId, $articleId = null) {
00150 if (isset($articleId)) {
00151 return $this->update(
00152 'DELETE FROM article_event_log WHERE log_id = ? AND article_id = ?',
00153 array($logId, $articleId)
00154 );
00155
00156 } else {
00157 return $this->update(
00158 'DELETE FROM article_event_log WHERE log_id = ?', $logId
00159 );
00160 }
00161 }
00162
00167 function deleteArticleLogEntries($articleId) {
00168 return $this->update(
00169 'DELETE FROM article_event_log WHERE article_id = ?', $articleId
00170 );
00171 }
00172
00177 function transferArticleLogEntries($oldUserId, $newUserId) {
00178 return $this->update(
00179 'UPDATE article_event_log SET user_id = ? WHERE user_id = ?',
00180 array($newUserId, $oldUserId)
00181 );
00182 }
00183
00188 function getInsertLogId() {
00189 return $this->getInsertId('article_event_log', 'log_id');
00190 }
00191 }
00192
00193 ?>