Merge in from pre_0.1 branch
git-svn-id: file:///svn-source/pmgr/trunk/site@847 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -1,16 +1,50 @@
|
||||
<?php
|
||||
class UnitType extends AppModel {
|
||||
|
||||
var $name = 'UnitType';
|
||||
var $validate = array(
|
||||
'id' => array('numeric'),
|
||||
'code' => array('notempty'),
|
||||
'name' => array('notempty')
|
||||
);
|
||||
var $hasMany =
|
||||
array(
|
||||
'UnitSize',
|
||||
);
|
||||
|
||||
var $hasMany = array(
|
||||
'UnitSize',
|
||||
);
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: relatedTypes
|
||||
* - Returns an array of types related by similar attributes
|
||||
*/
|
||||
|
||||
function relatedTypes($attribute, $extra = null) {
|
||||
$this->cacheQueries = true;
|
||||
$types = $this->find('all', array
|
||||
('fields' => array('UnitType.id', 'UnitType.name'),
|
||||
'conditions' => array('UnitType.'.$attribute => true),
|
||||
'order' => array('UnitType.name'),
|
||||
) + (isset($extra) ? $extra : array())
|
||||
);
|
||||
$this->cacheQueries = false;
|
||||
|
||||
// Rearrange to be of the form (id => name)
|
||||
$rel_types = array();
|
||||
foreach ($types AS $type) {
|
||||
$rel_types[$type['UnitType']['id']] = $type['UnitType']['name'];
|
||||
}
|
||||
|
||||
return $rel_types;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: xxxTypes
|
||||
* - Returns an array of types suitable for activity xxx
|
||||
*/
|
||||
|
||||
function residentialTypes() { return $this->relatedTypes('residential'); }
|
||||
function enclosedTypes() { return $this->relatedTypes('enclosed'); }
|
||||
function climateTypes() { return $this->relatedTypes('climate'); }
|
||||
function outdoorTypes() { return $this->relatedTypes('outdoor'); }
|
||||
function coveredTypes() { return $this->relatedTypes('covered'); }
|
||||
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user