<?php
/*
* lib/Customer.php
*
* Developed by Ondrej Jombik <nepto@platon.sk>
* Copyright (c) 2004 Platon SDG, http://platon.sk/
* Licensed under terms of GNU General Public License.
* All rights reserved.
*
* Changelog:
* 2004-06-20 - created
*
*/
/* $Platon$ */
require_once 'DB.php';
class Customer
{
function getList() /* {{{ */
{
global $cfg, $dbh;
$query = sprintf('SELECT * FROM %s', $cfg['tables']['customers']);
return $dbh->getAll($query);
} /* }}} */
function getListExtended() /* {{{ */
{
global $cfg, $dbh;
$ret_ar = Customer::getList();
$query_total = sprintf('SELECT customer_id, COUNT(*)'
.' FROM %s GROUP BY customer_id', $cfg['tables']['projects']);
$query_opened = sprintf('SELECT customer_id, COUNT(*)'
.' FROM %s WHERE state != "done" AND state != "abandoned"'
.' GROUP BY customer_id', $cfg['tables']['projects']);
$counts_total = $dbh->getAssoc($query_total, false, array(), DB_FETCHMODE_ORDERED);
$counts_opened = $dbh->getAssoc($query_opened, false, array(), DB_FETCHMODE_ORDERED);
$counts_total_keys = array_keys($counts_total);
$counts_opened_keys = array_keys($counts_opened);
foreach ($ret_ar as $key => $val) {
if (in_array($val['id'], $counts_total_keys)) {
$ret_ar[$key]['projects_total'] = $counts_total[$val['id']];
} else {
$ret_ar[$key]['projects_total'] = 0;
}
if (in_array($val['id'], $counts_opened_keys)) {
$ret_ar[$key]['projects_opened'] = $counts_opened[$val['id']];
} else {
$ret_ar[$key]['projects_opened'] = 0;
}
}
return $ret_ar;
} /* }}} */
}
/* Modeline for ViM {{{
* vim: set ts=4:
* vim600: fdm=marker fdl=0 fdc=0:
* }}} */
?>
Platon Group <platon@platon.sk> http://platon.sk/
|