classes/paper/log/PaperEmailLogDAO.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 //$Id$
00017 
00018 import ('paper.log.PaperEmailLogEntry');
00019 
00020 class PaperEmailLogDAO extends DAO {
00027    function &getLogEntry($logId, $paperId = null) {
00028       if (isset($paperId)) {
00029          $result =& $this->retrieve(
00030             'SELECT * FROM paper_email_log WHERE log_id = ? AND paper_id = ?',
00031             array($logId, $paperId)
00032          );
00033       } else {
00034          $result =& $this->retrieve(
00035             'SELECT * FROM paper_email_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 
00067    function &getPaperLogEntriesByAssoc($paperId, $assocType = null, $assocId = null, $rangeInfo = null) {
00068       $params = array($paperId);
00069       if (isset($assocType)) {
00070          array_push($params, $assocType);
00071          if (isset($assocId)) {
00072             array_push($params, $assocId);
00073          }
00074       }
00075 
00076       $result =& $this->retrieveRange(
00077          'SELECT * FROM paper_email_log WHERE paper_id = ?' . (isset($assocType) ? ' AND assoc_type = ?' . (isset($assocId) ? ' AND assoc_id = ?' : '') : '') . ' ORDER BY log_id DESC',
00078          $params, $rangeInfo
00079       );
00080 
00081       $returner = new DAOResultFactory($result, $this, '_returnLogEntryFromRow');
00082       return $returner;
00083    }
00084 
00090    function &_returnLogEntryFromRow(&$row) {
00091       $entry = new PaperEmailLogEntry();
00092       $entry->setLogId($row['log_id']);
00093       $entry->setPaperId($row['paper_id']);
00094       $entry->setSenderId($row['sender_id']);
00095       $entry->setDateSent($this->datetimeFromDB($row['date_sent']));
00096       $entry->setIPAddress($row['ip_address']);
00097       $entry->setEventType($row['event_type']);
00098       $entry->setAssocType($row['assoc_type']);
00099       $entry->setAssocId($row['assoc_id']);
00100       $entry->setFrom($row['from_address']);
00101       $entry->setRecipients($row['recipients']);
00102       $entry->setCcs($row['cc_recipients']);
00103       $entry->setBccs($row['bcc_recipients']);
00104       $entry->setSubject($row['subject']);
00105       $entry->setBody($row['body']);
00106 
00107       HookRegistry::call('PaperEmailLogDAO::_returnLogEntryFromRow', array(&$entry, &$row));
00108 
00109       return $entry;
00110    }
00111 
00116    function insertLogEntry(&$entry) {
00117       if ($entry->getDateSent() == null) {
00118          $entry->setDateSent(Core::getCurrentDate());
00119       }
00120       if ($entry->getIPAddress() == null) {
00121          $entry->setIPAddress(Request::getRemoteAddr());
00122       }
00123       $this->update(
00124          sprintf('INSERT INTO paper_email_log
00125             (paper_id, sender_id, date_sent, ip_address, event_type, assoc_type, assoc_id, from_address, recipients, cc_recipients, bcc_recipients, subject, body)
00126             VALUES
00127             (?, ?, %s, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
00128             $this->datetimeToDB($entry->getDateSent())),
00129          array(
00130             $entry->getPaperId(),
00131             $entry->getSenderId(),
00132             $entry->getIPAddress(),
00133             $entry->getEventType(),
00134             $entry->getAssocType(),
00135             $entry->getAssocId(),
00136             $entry->getFrom(),
00137             $entry->getRecipients(),
00138             $entry->getCcs(),
00139             $entry->getBccs(),
00140             $entry->getSubject(),
00141             $entry->getBody()
00142          )
00143       );
00144 
00145       $entry->setLogId($this->getInsertLogId());
00146       return $entry->getLogId();
00147    }
00148 
00154    function deleteLogEntry($logId, $paperId = null) {
00155       if (isset($paperId)) {
00156          return $this->update(
00157             'DELETE FROM paper_email_log WHERE log_id = ? AND paper_id = ?',
00158             array($logId, $paperId)
00159          );
00160 
00161       } else {
00162          return $this->update(
00163             'DELETE FROM paper_email_log WHERE log_id = ?', $logId
00164          );
00165       }
00166    }
00167 
00172    function deletePaperLogEntries($paperId) {
00173       return $this->update(
00174          'DELETE FROM paper_email_log WHERE paper_id = ?', $paperId
00175       );
00176    }
00177 
00182    function transferPaperLogEntries($oldUserId, $newUserId) {
00183       return $this->update(
00184          'UPDATE paper_email_log SET sender_id = ? WHERE sender_id = ?',
00185          array($newUserId, $oldUserId)
00186       );
00187    }
00188 
00193    function getInsertLogId() {
00194       return $this->getInsertId('paper_email_log', 'log_id');
00195    }
00196 }
00197 
00198 ?>

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