classes/paper/log/PaperEventLogDAO.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 //$Id$
00017 
00018 import ('paper.log.PaperEventLogEntry');
00019 
00020 class PaperEventLogDAO extends DAO {
00027    function &getLogEntry($logId, $paperId = null) {
00028       if (isset($paperId)) {
00029          $result =& $this->retrieve(
00030             'SELECT * FROM paper_event_log WHERE log_id = ? AND paper_id = ?',
00031             array($logId, $paperId)
00032          );
00033       } else {
00034          $result =& $this->retrieve(
00035             'SELECT * FROM paper_event_log WHERE log_id = ?', $logId
00036          );
00037       }
00038 
00039       $returner = null;
00040       if ($result->RecordCount() != 0) {
00041          $returner =& $this->_returnLogEntryFromRow($result->GetRowAssoc(false));
00042       }
00043 
00044       $result->Close();
00045       unset($result);
00046 
00047       return $returner;
00048    }
00049 
00055    function &getPaperLogEntries($paperId, $rangeInfo = null) {
00056       $returner =& $this->getPaperLogEntriesByAssoc($paperId, null, null, $rangeInfo);
00057       return $returner;
00058    }
00059 
00069    function &getPaperLogEntriesByAssoc($paperId, $assocType = null, $assocId = null, $rangeInfo = null) {
00070       $params = array($paperId);
00071       if (isset($assocType)) {
00072          array_push($params, $assocType);
00073          if (isset($assocId)) {
00074             array_push($params, $assocId);
00075          }
00076       }
00077 
00078       $result =& $this->retrieveRange(
00079          'SELECT * FROM paper_event_log WHERE paper_id = ?' . (isset($assocType) ? ' AND assoc_type = ?' . (isset($assocId) ? ' AND assoc_id = ?' : '') : '') . ' ORDER BY log_id DESC',
00080          $params, $rangeInfo
00081       );
00082 
00083       $returner = new DAOResultFactory($result, $this, '_returnLogEntryFromRow');
00084       return $returner;
00085    }
00086 
00092    function &_returnLogEntryFromRow(&$row) {
00093       $entry = new PaperEventLogEntry();
00094       $entry->setLogId($row['log_id']);
00095       $entry->setPaperId($row['paper_id']);
00096       $entry->setUserId($row['user_id']);
00097       $entry->setDateLogged($this->datetimeFromDB($row['date_logged']));
00098       $entry->setIPAddress($row['ip_address']);
00099       $entry->setLogLevel($row['log_level']);
00100       $entry->setEventType($row['event_type']);
00101       $entry->setAssocType($row['assoc_type']);
00102       $entry->setAssocId($row['assoc_id']);
00103       $entry->setIsTranslated($row['is_translated']);
00104       $entry->setEntryParams(unserialize($row['entry_params']));
00105       $entry->setMessage($row['message']);
00106 
00107       HookRegistry::call('PaperEventLogDAO::_returnLogEntryFromRow', array(&$entry, &$row));
00108 
00109       return $entry;
00110    }
00111 
00116    function insertLogEntry(&$entry) {
00117       if ($entry->getDateLogged() == null) {
00118          $entry->setDateLogged(Core::getCurrentDate());
00119       }
00120       if ($entry->getIPAddress() == null) {
00121          $entry->setIPAddress(Request::getRemoteAddr());
00122       }
00123       $this->update(
00124          sprintf('INSERT INTO paper_event_log
00125             (paper_id, user_id, date_logged, ip_address, log_level, event_type, assoc_type, assoc_id, is_translated, entry_params, message)
00126             VALUES
00127             (?, ?, %s, ?, ?, ?, ?, ?, ?, ?, ?)',
00128             $this->datetimeToDB($entry->getDateLogged())),
00129          array(
00130             $entry->getPaperId(),
00131             $entry->getUserId(),
00132             $entry->getIPAddress(),
00133             $entry->getLogLevel(),
00134             $entry->getEventType(),
00135             $entry->getAssocType(),
00136             $entry->getAssocId(),
00137             1, // is_translated: All new entries are.
00138             $entry->getEntryParamsSerialized(),
00139             $entry->getMessage()
00140          )
00141       );
00142 
00143       $entry->setLogId($this->getInsertLogId());
00144       return $entry->getLogId();
00145    }
00146 
00152    function deleteLogEntry($logId, $paperId = null) {
00153       if (isset($paperId)) {
00154          return $this->update(
00155             'DELETE FROM paper_event_log WHERE log_id = ? AND paper_id = ?',
00156             array($logId, $paperId)
00157          );
00158 
00159       } else {
00160          return $this->update(
00161             'DELETE FROM paper_event_log WHERE log_id = ?', $logId
00162          );
00163       }
00164    }
00165 
00170    function deletePaperLogEntries($paperId) {
00171       return $this->update(
00172          'DELETE FROM paper_event_log WHERE paper_id = ?', $paperId
00173       );
00174    }
00175 
00180    function transferPaperLogEntries($oldUserId, $newUserId) {
00181       return $this->update(
00182          'UPDATE paper_event_log SET user_id = ? WHERE user_id = ?',
00183          array($newUserId, $oldUserId)
00184       );
00185    }
00186 
00191    function getInsertLogId() {
00192       return $this->getInsertId('paper_event_log', 'log_id');
00193    }
00194 }
00195 
00196 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7