Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
CounterReportDAO.inc.php
1 <?php
2 
16 class CounterReportDAO extends DAO {
17 
22  function getYears() {
23  $result = $this->retrieve(
24  'SELECT DISTINCT year FROM counter_monthly_log'
25  );
26  $years = array();
27  while (!$result->EOF) {
28  $row = $result->GetRowAssoc(false);
29  $years[] = $row['year'];
30  $result->MoveNext();
31  }
32  $result->Close();
33  return $years;
34  }
35 
40  function getJournalIds() {
41  $result = $this->retrieve(
42  'SELECT DISTINCT journal_id FROM counter_monthly_log l'
43  );
44  $journalIds = array();
45  while (!$result->EOF) {
46  $row = $result->GetRowAssoc(false);
47  $journalIds[] = $row['journal_id'];
48  $result->MoveNext();
49  }
50  $result->Close();
51  return $journalIds;
52  }
53 
54 
62  function getMonthlyLogRange($journalId, $begin, $end) {
63  $begin = getdate(strtotime($begin));
64  $end = getdate(strtotime($end));
65  $beginComb = $begin['year'] * 100 + $begin['mon'];
66  $endComb = $end['year'] * 100 + $end['mon'];
67 
68  $result = $this->retrieve(
69  'SELECT * FROM counter_monthly_log
70  WHERE journal_id = ? AND year * 100 + month >= ? AND year * 100 + month <= ?',
71  array((int) $journalId, (int) $beginComb, (int) $endComb)
72  );
73 
74  $returner = null;
75  if ($result->RecordCount() != 0) {
76  $returner = $result->GetArray();
77  }
78 
79  $result->Close();
80  return $returner;
81  }
82 
89  function getMonthlyTotalRange($begin, $end) {
90  $begin = getdate(strtotime($begin));
91  $end = getdate(strtotime($end));
92  $beginComb = $begin['year'] * 100 + $begin['mon'];
93  $endComb = $end['year'] * 100 + $end['mon'];
94 
95  $result = $this->retrieve(
96  'SELECT month, SUM(count_html) as count_html, SUM(count_pdf) as count_pdf FROM counter_monthly_log
97  WHERE year * 100 + month >= ? AND year * 100 + month <= ?
98  GROUP BY month',
99  array((int) $beginComb, (int) $endComb)
100  );
101 
102  $returner = null;
103  if ($result->RecordCount() != 0) {
104  $returner = $result->GetArray();
105  }
106 
107  $result->Close();
108  return $returner;
109  }
110 
111 
115  function _conditionalCreate($journalId, $year, $month) {
116  $result = $this->retrieve(
117  'SELECT * FROM counter_monthly_log WHERE journal_id = ? AND year = ? AND month = ?',
118  array((int) $journalId, (int) $year, (int) $month)
119  );
120 
121  $returner = false;
122  if ($result->RecordCount() == 0) {
123  $this->update(
124  'INSERT INTO counter_monthly_log (journal_id, year, month) VALUES (?, ?, ?)',
125  array((int) $journalId, (int) $year, (int) $month)
126  );
127  }
128 
129  $result->Close();
130  }
131 
132 
142  function incrementCount($journalId, $year, $month, $isPdf, $isHtml) {
143  // create the monthly record if it does not exist
144  $this->_conditionalCreate($journalId, $year, $month);
145 
146  if ($month < 1 || $month > 12) return false;
147 
148  $this->update(
149  "UPDATE counter_monthly_log SET " .
150  ' count_html = count_html + ' . ($isHtml?'1,':'0,') .
151  ' count_pdf = count_pdf + ' . ($isPdf?'1':'0') .
152  " WHERE journal_id = ? AND year = ? AND month = ?",
153  array((int) $journalId, (int) $year, (int) $month)
154  );
155 
156  return true;
157  }
158 }
159 
160 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
incrementCount($journalId, $year, $month, $isPdf, $isHtml)
getMonthlyTotalRange($begin, $end)
getMonthlyLogRange($journalId, $begin, $end)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
Class for managing COUNTER records.
_conditionalCreate($journalId, $year, $month)