XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
stats.php
Go to the documentation of this file.
1 <?php
20 defined('XOOPS_ROOT_PATH') or die('Restricted access');
21 
31 {
38  function getCount($criteria = null)
39  {
40  $field = '';
41  $groupby = false;
42  if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
43  if ($criteria->groupby != '') {
44  $groupby = true;
45  $field = $criteria->groupby . ", ";
46  }
47  }
48  $sql = "SELECT {$field} COUNT(*) FROM `{$this->handler->table}`";
49  if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
50  $sql .= ' ' . $criteria->renderWhere();
51  $sql .= $criteria->getGroupby();
52  }
53  $result = $this->handler->db->query($sql);
54  if (!$result) {
55  return 0;
56  }
57  if ($groupby == false) {
58  list ($count) = $this->handler->db->fetchRow($result);
59  return $count;
60  } else {
61  $ret = array();
62  while (list ($id, $count) = $this->handler->db->fetchRow($result)) {
63  $ret[$id] = $count;
64  }
65  return $ret;
66  }
67  }
68 
75  function getCounts($criteria = null)
76  {
77  $ret = array();
78  $sql_where = '';
79  $limit = null;
80  $start = null;
81  $groupby_key = $this->handler->keyName;
82  if (isset($criteria) && is_subclass_of($criteria, "criteriaelement")) {
83  $sql_where = $criteria->renderWhere();
84  $limit = $criteria->getLimit();
85  $start = $criteria->getStart();
86  if ($groupby = $criteria->groupby) {
87  $groupby_key = $groupby;
88  }
89  }
90  $sql = "SELECT {$groupby_key}, COUNT(*) AS count"
91  . " FROM `{$this->handler->table}`"
92  . " {$sql_where}"
93  . " GROUP BY {$groupby_key}";
94  if (!$result = $this->handler->db->query($sql, $limit, $start)) {
95  return $ret;
96  }
97  while (list ($id, $count) = $this->handler->db->fetchRow($result)) {
98  $ret[$id] = $count;
99  }
100  return $ret;
101  }
102 }
103 
104 ?>