| [ Index ] |
PHP Cross Reference of Xoops v2.3.1 |
|
[Global whois Lookup] [Ranchi, Jharkhand, India website] [Hindi Magazine] [Desi Community website in tristate area] [B 4 Bollywood] [Internet nation of India] |
|
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Extended object handlers 4 * 5 * You may not change or alter any portion of this comment or credits 6 * of supporting developers from this source code or any supporting source code 7 * which is considered copyrighted (c) material of the original comment or credit authors. 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 * 12 * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ 13 * @license http://www.fsf.org/copyleft/gpl.html GNU public license 14 * @package kernel 15 * @subpackage model 16 * @since 2.3.0 17 * @author Taiwen Jiang <phppp@users.sourceforge.net> 18 * @version $Id: stats.php 2071 2008-09-12 07:12:34Z phppp $ 19 */ 20 21 /** 22 * Object stats handler class. 23 * 24 * @author Taiwen Jiang <phppp@users.sourceforge.net> 25 * @copyright The XOOPS project http://www.xoops.org/ 26 * 27 * {@link XoopsObjectAbstract} 28 * 29 */ 30 31 class XoopsModelStats extends XoopsModelAbstract 32 { 33 /** 34 * count objects matching a condition 35 * 36 * @param object $criteria {@link CriteriaElement} to match 37 * @return int count of objects 38 */ 39 function getCount($criteria = null) 40 { 41 $field = ""; 42 $groupby = false; 43 if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { 44 if ($criteria->groupby != "") { 45 $groupby = true; 46 $field = $criteria->groupby . ", "; 47 } 48 } 49 $sql = "SELECT {$field} COUNT(*) FROM `{$this->handler->table}`"; 50 if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { 51 $sql .= ' ' . $criteria->renderWhere(); 52 $sql .= $criteria->getGroupby(); 53 } 54 $result = $this->handler->db->query($sql); 55 if (!$result) { 56 return 0; 57 } 58 if ($groupby == false) { 59 list($count) = $this->handler->db->fetchRow($result); 60 return $count; 61 } else { 62 $ret = array(); 63 while (list($id, $count) = $this->handler->db->fetchRow($result)) { 64 $ret[$id] = $count; 65 } 66 return $ret; 67 } 68 } 69 70 /** 71 * get counts matching a condition 72 * 73 * @param object $criteria {@link CriteriaElement} to match 74 * @return array of conunts 75 */ 76 function getCounts($criteria = null) 77 { 78 $ret = array(); 79 80 $sql_where = ""; 81 $limit = null; 82 $start = null; 83 $groupby_key = $this->handler->keyName; 84 if (isset($criteria) && is_subclass_of($criteria, "criteriaelement")) { 85 $sql_where = $criteria->renderWhere(); 86 $limit = $criteria->getLimit(); 87 $start = $criteria->getStart(); 88 if($groupby = $criteria->groupby) { 89 $groupby_key = $groupby; 90 } 91 } 92 $sql = " SELECT {$groupby_key}, COUNT(*) AS count" . 93 " FROM `{$this->handler->table}`" . 94 " {$sql_where}" . 95 " GROUP BY {$groupby_key}"; 96 if (!$result = $this->handler->db->query($sql, $limit, $start)) { 97 return $ret; 98 } 99 while (list($id, $count) = $this->handler->db->fetchRow($result)) { 100 $ret[$id] = $count; 101 } 102 103 return $ret; 104 } 105 } 106 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
|
[ Xoops] [PhpNuke] [PostNuke] [Joomla] [Drupal] [E107] [NucleusCms] |
|||
|
[Php-Fusion] [PhpBB] [WordPress] [Typo3] |
|||
| Generated: Mon Oct 27 11:51:45 2008 | |||