51 lines
1.7 KiB
PHP
51 lines
1.7 KiB
PHP
<?php
|
|
class UnitType extends AppModel {
|
|
|
|
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'); }
|
|
|
|
}
|