git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@782 97e9348a-65ac-dc4b-aefc-98561f571b83
65 lines
1.7 KiB
PHP
65 lines
1.7 KiB
PHP
<?php
|
|
class UnitSize extends AppModel {
|
|
|
|
var $belongsTo =
|
|
array(
|
|
'UnitType',
|
|
);
|
|
|
|
var $hasMany =
|
|
array(
|
|
'Unit',
|
|
);
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* function: stats
|
|
* - Returns summary data from the requested unit size.
|
|
*/
|
|
|
|
function stats($id = null) {
|
|
$this->prEnter(compact('id'));
|
|
|
|
// Right now, we only work with id not null
|
|
if (!$id)
|
|
return null;
|
|
|
|
$stats = array();
|
|
|
|
// Get the total number of units this size
|
|
$stats['all'] =
|
|
$this->find('count',
|
|
array('link' => array('Unit'),
|
|
'conditions' => array(array('UnitSize.id' => $id)),
|
|
));
|
|
|
|
// Get numbers for units in the various states
|
|
foreach (array('unavailable', 'vacant', 'occupied', 'locked', 'liened') AS $status) {
|
|
$statusfunc = 'condition' . ucfirst($status);
|
|
$stats[$status] =
|
|
$this->find('count',
|
|
array('link' => array('Unit'),
|
|
'conditions' => array(array('UnitSize.id' => $id),
|
|
$this->Unit->{$statusfunc}()),
|
|
));
|
|
}
|
|
|
|
// Count up each unit by physical status
|
|
foreach
|
|
($this->find('all',
|
|
array('link' => array('Unit' => array('fields' => array())),
|
|
'fields' => array('Unit.status', 'COUNT(Unit.id) AS total'),
|
|
'conditions' => array(array('UnitSize.id' => $id)),
|
|
'group' => 'Unit.status',
|
|
)) AS $status) {
|
|
$stats['status'][$status['Unit']['status']] = $status[0]['total'];
|
|
}
|
|
|
|
// Return the collection
|
|
return $this->prReturn($stats);
|
|
}
|
|
|
|
}
|