Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
UsageStatsTemporaryRecordDAO.inc.php
1 <?php
2 
17 
19  var $_result;
20 
22  var $_loadId;
23 
27  function UsageStatsTemporaryRecordDAO() {
28  parent::DAO();
29 
30  $this->_result = false;
31  $this->_loadId = null;
32  }
33 
39  function insert($assocType, $assocId, $day, $countryCode, $region, $cityName, $fileType, $loadId) {
40  $this->update(
41  'INSERT INTO usage_stats_temporary_records
42  (assoc_type, assoc_id, day, country_id, region, city, file_type, load_id)
43  VALUES
44  (?, ?, ?, ?, ?, ?, ?, ?)',
45  array(
46  $assocType,
47  $assocId,
48  $day,
49  $countryCode,
50  $region,
51  $cityName,
52  $fileType,
53  $loadId
54  )
55  );
56 
57  return true;
58  }
59 
66  function getNextByLoadId($loadId) {
67  if (!$this->_result || $this->_loadId != $loadId) {
68  $this->_result = $this->_getGrouped($loadId);
69  $this->_loadId = $loadId;
70  }
71 
72  if ($this->_result->EOF) return false;
73  $row = $this->_result->GetRowAssoc(false);
74  $this->_result->MoveNext();
75  return $row;
76  }
77 
84  function deleteByLoadId($loadId) {
85  return $this->update('DELETE from usage_stats_temporary_records WHERE load_id = ?', array($loadId));
86  }
87 
96  function deleteRecord($assocType, $assocId, $loadId) {
97  return $this->update('DELETE from usage_stats_temporary_records
98  WHERE assoc_type = ? AND assoc_id = ? AND load_id = ?
99  ORDER BY day DESC
100  LIMIT 1',
101  array($assocType, $assocId, $loadId));
102  }
103 
104 
105  //
106  // Private helper methods.
107  //
113  function _getGrouped($loadId) {
114  return $this->retrieve(
115  'SELECT assoc_type, assoc_id, day, country_id, region, city, file_type, load_id, count(metric) as metric
116  FROM usage_stats_temporary_records WHERE load_id = ?
117  GROUP BY assoc_type, assoc_id, day, country_id, region, city, file_type, load_id',
118  array($loadId)
119  );
120  }
121 }
122 
123 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
Operations for retrieving and adding temporary usage statistics records.
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
deleteRecord($assocType, $assocId, $loadId)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:207
insert($assocType, $assocId, $day, $countryCode, $region, $cityName, $fileType, $loadId)