Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
EventLogDAO.inc.php
1 <?php
2 
18 import ('lib.pkp.classes.log.EventLogEntry');
19 
20 class EventLogDAO extends DAO {
24  function EventLogDAO() {
25  parent::DAO();
26  }
27 
35  function getById($logId, $assocType = null, $assocId = null) {
36  $params = array((int) $logId);
37  if (isset($assocType)) {
38  $params[] = (int) $assocType;
39  $params[] = (int) $assocId;
40  }
41 
42  $result = $this->retrieve(
43  'SELECT * FROM event_log WHERE log_id = ?' .
44  (isset($assocType)?' AND assoc_type = ? AND assoc_id = ?':''),
45  $params
46  );
47 
48  $returner = null;
49  if ($result->RecordCount() != 0) {
50  $returner =& $this->build($result->GetRowAssoc(false));
51  }
52 
53  $result->Close();
54  return $returner;
55  }
56 
64  function getByAssoc($assocType, $assocId, $rangeInfo = null) {
65  $result = $this->retrieveRange(
66  'SELECT * FROM event_log WHERE assoc_type = ? AND assoc_id = ? ORDER BY log_id DESC',
67  array((int) $assocType, (int) $assocId),
68  $rangeInfo
69  );
70 
71  return new DAOResultFactory($result, $this, 'build');
72  }
73 
78  function newDataObject() {
79  return new EventLogEntry();
80  }
81 
87  function build($row) {
88  $entry = $this->newDataObject();
89  $entry->setId($row['log_id']);
90  $entry->setUserId($row['user_id']);
91  $entry->setDateLogged($this->datetimeFromDB($row['date_logged']));
92  $entry->setIPAddress($row['ip_address']);
93  $entry->setEventType($row['event_type']);
94  $entry->setAssocType($row['assoc_type']);
95  $entry->setAssocId($row['assoc_id']);
96  $entry->setMessage($row['message']);
97  $entry->setIsTranslated($row['is_translated']);
98 
99  $result = $this->retrieve('SELECT * FROM event_log_settings WHERE log_id = ?', array((int) $entry->getId()));
100  $params = array();
101  while (!$result->EOF) {
102  $r = $result->getRowAssoc(false);
103  $params[$r['setting_name']] = $this->convertFromDB(
104  $r['setting_value'],
105  $r['setting_type']
106  );
107  $result->MoveNext();
108  }
109  $result->Close();
110  $entry->setParams($params);
111 
112  HookRegistry::call('EventLogDAO::build', array(&$entry, &$row));
113 
114  return $entry;
115  }
116 
121  function insertObject($entry) {
122  $this->update(
123  sprintf('INSERT INTO event_log
124  (user_id, date_logged, ip_address, event_type, assoc_type, assoc_id, message, is_translated)
125  VALUES
126  (?, %s, ?, ?, ?, ?, ?, ?)',
127  $this->datetimeToDB($entry->getDateLogged())),
128  array(
129  (int) $entry->getUserId(),
130  $entry->getIPAddress(),
131  (int) $entry->getEventType(),
132  (int) $entry->getAssocType(),
133  (int) $entry->getAssocId(),
134  $entry->getMessage(),
135  (int) $entry->getIsTranslated()
136  )
137  );
138  $entry->setId($this->getInsertId());
139 
140  // Add name => value entries into the settings table
141  $params = $entry->getParams();
142  if (is_array($params)) foreach ($params as $key => $value) {
143  $type = null;
144  $value = $this->convertToDB($value, $type);
145  $params = array(
146  (int) $entry->getId(),
147  $key, $value, $type
148  );
149  $this->update(
150  'INSERT INTO event_log_settings (log_id, setting_name, setting_value, setting_type) VALUES (?, ?, ?, ?)',
151  $params
152  );
153  }
154 
155  return $entry->getId();
156  }
157 
162  function deleteById($logId, $assocType = null, $assocId = null) {
163  $params = array((int) $logId);
164  if ($assocType !== null) {
165  $params[] = (int) $assocType;
166  $params[] = (int) $assocId;
167  }
168  $this->update(
169  'DELETE FROM event_log WHERE log_id = ?' .
170  ($assocType !== null?' AND assoc_type = ? AND assoc_id = ?':''),
171  $params
172  );
173  if ($this->getAffectedRows()) $this->update('DELETE FROM event_log_settings WHERE log_id = ?', array((int) $logId));
174  }
175 
181  function deleteByAssoc($assocType, $assocId) {
182  $entries = $this->getByAssoc($assocType, $assocId);
183  while ($entry = $entries->next()) {
184  $this->deleteById($entry->getId());
185  }
186  }
187 
193  function changeUser($oldUserId, $newUserId) {
194  return $this->update(
195  'UPDATE event_log SET user_id = ? WHERE user_id = ?',
196  array((int) $newUserId, (int) $oldUserId)
197  );
198  }
199 
204  function getInsertId() {
205  return $this->_getInsertId('event_log', 'log_id');
206  }
207 }
208 
209 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
Class for inserting/accessing event log entries.
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
insertObject($entry)
getByAssoc($assocType, $assocId, $rangeInfo=null)
changeUser($oldUserId, $newUserId)
deleteById($logId, $assocType=null, $assocId=null)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
datetimeFromDB($dt)
Definition: DAO.inc.php:313
getAffectedRows()
Definition: DAO.inc.php:258
static call($hookName, $args=null)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
convertFromDB($value, $type)
Definition: DAO.inc.php:335
deleteByAssoc($assocType, $assocId)
Describes an entry in the event log.
convertToDB($value, &$type)
Definition: DAO.inc.php:391
getById($logId, $assocType=null, $assocId=null)
datetimeToDB($dt)
Definition: DAO.inc.php:293
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208