Open Journal Systems  2.4.4
 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  unset($result);
55 
56  return $returner;
57  }
58 
66  function &getByAssoc($assocType, $assocId, $rangeInfo = null) {
67  $params = array((int) $assocType, (int) $assocId);
68 
69  $result =& $this->retrieveRange(
70  'SELECT * FROM event_log WHERE assoc_type = ? AND assoc_id = ? ORDER BY log_id DESC',
71  $params, $rangeInfo
72  );
73 
74  $returner = new DAOResultFactory($result, $this, 'build');
75  return $returner;
76  }
77 
82  function newDataObject() {
83  return new EventLogEntry();
84  }
85 
91  function &build(&$row) {
92  $entry = $this->newDataObject();
93  $entry->setId($row['log_id']);
94  $entry->setUserId($row['user_id']);
95  $entry->setDateLogged($this->datetimeFromDB($row['date_logged']));
96  $entry->setIPAddress($row['ip_address']);
97  $entry->setEventType($row['event_type']);
98  $entry->setAssocType($row['assoc_type']);
99  $entry->setAssocId($row['assoc_id']);
100  $entry->setMessage($row['message']);
101  $entry->setIsTranslated($row['is_translated']);
102 
103  $result =& $this->retrieve('SELECT * FROM event_log_settings WHERE log_id = ?', array((int) $entry->getId()));
104  $params = array();
105  while (!$result->EOF) {
106  $r =& $result->getRowAssoc(false);
107  $params[$r['setting_name']] = $this->convertFromDB(
108  $r['setting_value'],
109  $r['setting_type']
110  );
111  unset($r);
112  $result->MoveNext();
113  }
114  $result->Close();
115  unset($result);
116  $entry->setParams($params);
117 
118  HookRegistry::call('EventLogDAO::build', array(&$entry, &$row));
119 
120  return $entry;
121  }
122 
127  function insertObject(&$entry) {
128  $this->update(
129  sprintf('INSERT INTO event_log
130  (user_id, date_logged, ip_address, event_type, assoc_type, assoc_id, message, is_translated)
131  VALUES
132  (?, %s, ?, ?, ?, ?, ?, ?)',
133  $this->datetimeToDB($entry->getDateLogged())),
134  array(
135  (int) $entry->getUserId(),
136  $entry->getIPAddress(),
137  (int) $entry->getEventType(),
138  (int) $entry->getAssocType(),
139  (int) $entry->getAssocId(),
140  $entry->getMessage(),
141  (int) $entry->getIsTranslated()
142  )
143  );
144  $entry->setId($this->getInsertLogId());
145 
146  // Add name => value entries into the settings table
147  $params = $entry->getParams();
148  if (is_array($params)) foreach ($params as $key => $value) {
149  $type = null;
150  $value = $this->convertToDB($value, $type);
151  $params = array(
152  (int) $entry->getId(),
153  $key, $value, $type
154  );
155  $this->update(
156  'INSERT INTO event_log_settings (log_id, setting_name, setting_value, setting_type) VALUES (?, ?, ?, ?)',
157  $params
158  );
159  }
160 
161  return $entry->getId();
162  }
163 
168  function deleteObject($logId, $assocType = null, $assocId = null) {
169  $params = array((int) $logId);
170  if ($assocType !== null) {
171  $params[] = (int) $assocType;
172  $params[] = (int) $assocId;
173  }
174  $this->update(
175  'DELETE FROM event_log WHERE log_id = ?' .
176  ($assocType !== null?' AND assoc_type = ? AND assoc_id = ?':''),
177  $params
178  );
179  if ($this->getAffectedRows()) $this->update('DELETE FROM event_log_settings WHERE log_id = ?', array((int) $logId));
180  }
181 
187  function deleteByAssoc($assocType, $assocId) {
188  $entries =& $this->getByAssoc($assocType, $assocId);
189  while ($entry =& $entries->next()) {
190  $this->deleteObject($entry->getId());
191  unset($entry);
192  }
193  unset($entries);
194  }
195 
201  function changeUser($oldUserId, $newUserId) {
202  return $this->update(
203  'UPDATE event_log SET user_id = ? WHERE user_id = ?',
204  array((int) $newUserId, (int) $oldUserId)
205  );
206  }
207 
212  function getInsertLogId() {
213  return $this->getInsertId('event_log', 'log_id');
214  }
215 }
216 
217 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
Class for inserting/accessing event log entries.
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
getInsertId($table= '', $id= '', $callHooks=true)
Definition: DAO.inc.php:252
insertObject(&$entry)
changeUser($oldUserId, $newUserId)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
& getByAssoc($assocType, $assocId, $rangeInfo=null)
datetimeFromDB($dt)
Definition: DAO.inc.php:316
getAffectedRows()
Definition: DAO.inc.php:261
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
deleteObject($logId, $assocType=null, $assocId=null)
convertFromDB($value, $type)
Definition: DAO.inc.php:338
deleteByAssoc($assocType, $assocId)
Describes an entry in the event log.
& build(&$row)
convertToDB($value, &$type)
Definition: DAO.inc.php:394
call($hookName, $args=null)
datetimeToDB($dt)
Definition: DAO.inc.php:296
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
& getById($logId, $assocType=null, $assocId=null)