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:
238
controllers/unit_sizes_controller.php
Normal file
238
controllers/unit_sizes_controller.php
Normal file
@@ -0,0 +1,238 @@
|
||||
<?php
|
||||
|
||||
class UnitSizesController extends AppController {
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* override: addGridViewSideMenuLinks
|
||||
* - Adds grid view navigation side menu links
|
||||
*/
|
||||
|
||||
function addGridViewSideMenuLinks() {
|
||||
parent::addGridViewSideMenuLinks();
|
||||
|
||||
$this->addSideMenuLink('1 Bedroom',
|
||||
array('controller' => 'unit_sizes', 'action' => 'bd1'), null,
|
||||
'CONTROLLER');
|
||||
$this->addSideMenuLink('2 Bedroom',
|
||||
array('controller' => 'unit_sizes', 'action' => 'bd2'), null,
|
||||
'CONTROLLER');
|
||||
$this->addSideMenuLink('3 Bedroom',
|
||||
array('controller' => 'unit_sizes', 'action' => 'bd3'), null,
|
||||
'CONTROLLER');
|
||||
$this->addSideMenuLink('4+ Bedroom',
|
||||
array('controller' => 'unit_sizes', 'action' => 'bd4'), null,
|
||||
'CONTROLLER');
|
||||
$this->addSideMenuLink('Auto',
|
||||
array('controller' => 'unit_sizes', 'action' => 'auto'), null,
|
||||
'CONTROLLER');
|
||||
$this->addSideMenuLink('Boat',
|
||||
array('controller' => 'unit_sizes', 'action' => 'boat'), null,
|
||||
'CONTROLLER');
|
||||
$this->addSideMenuLink('RV',
|
||||
array('controller' => 'unit_sizes', 'action' => 'rv'), null,
|
||||
'CONTROLLER');
|
||||
$this->addSideMenuLink('All',
|
||||
array('controller' => 'unit_sizes', 'action' => 'all'), null,
|
||||
'CONTROLLER');
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: index / unavailable / vacant / occupied / all
|
||||
* - Generate a listing of units
|
||||
*/
|
||||
|
||||
function index() { $this->all(); }
|
||||
function bd1() { $this->gridView('Sizes for 1 Bedroom'); }
|
||||
function bd2() { $this->gridView('Sizes for 2 Bedrooms'); }
|
||||
function bd3() { $this->gridView('Sizes for 3 Bedroom'); }
|
||||
function bd4() { $this->gridView('Sizes for 4+ Bedroom'); }
|
||||
function auto() { $this->gridView('Sizes for an Automobile'); }
|
||||
function boat() { $this->gridView('Sizes for a Boat'); }
|
||||
function rv() { $this->gridView('Sizes for an RV'); }
|
||||
function all() { $this->gridView('All Unit Sizes', 'all'); }
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* virtuals: gridData
|
||||
* - With the application controller handling the gridData action,
|
||||
* these virtual functions ensure that the correct data is passed
|
||||
* to jqGrid.
|
||||
*/
|
||||
|
||||
function gridDataCountTables(&$params, &$model) {
|
||||
return array('link' => array('UnitType'));
|
||||
}
|
||||
|
||||
function gridDataTables(&$params, &$model) {
|
||||
$tables = $this->gridDataCountTables($params, $model);
|
||||
$tables['link']['Unit'] = array();
|
||||
return $tables;
|
||||
}
|
||||
|
||||
function gridDataFields(&$params, &$model) {
|
||||
$fields = parent::gridDataFields($params, $model);
|
||||
$fields[] = 'ROUND(UnitSize.width/12, 1) AS width';
|
||||
$fields[] = 'ROUND(UnitSize.depth/12, 1) AS depth';
|
||||
$fields[] = 'ROUND(UnitSize.height/12, 1) AS height';
|
||||
$fields[] = 'ROUND(UnitSize.width/12 * UnitSize.depth/12, 0) AS sqft';
|
||||
$fields[] = 'ROUND(UnitSize.width/12 * UnitSize.depth/12 * UnitSize.height/12, 0) AS cuft';
|
||||
$fields[] = 'ROUND(UnitSize.rent / (UnitSize.width/12 * UnitSize.depth/12), 2) AS sqcost';
|
||||
$fields[] = 'ROUND(UnitSize.rent / (UnitSize.width/12 * UnitSize.depth/12 * UnitSize.height/12), 2) AS cucost';
|
||||
|
||||
$fields[] = 'COUNT(Unit.id) AS units';
|
||||
$fields[] = 'SUM(IF(' . $this->UnitSize->Unit->conditionUnavailable() . ', 1, 0)) AS unavailable';
|
||||
$fields[] = 'SUM(IF(' . $this->UnitSize->Unit->conditionAvailable() . ', 1, 0)) AS available';
|
||||
$fields[] = 'SUM(IF(' . $this->UnitSize->Unit->conditionOccupied() . ', 1, 0)) AS occupied';
|
||||
$fields[] = 'SUM(IF(' . $this->UnitSize->Unit->conditionOccupied() . ', 0, 1)) / COUNT(unit.id) AS vacancy';
|
||||
$fields[] = 'SUM(IF(' . $this->UnitSize->Unit->conditionOccupied() . ', 1, 0)) / COUNT(unit.id) AS occupancy';
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
function gridDataConditions(&$params, &$model) {
|
||||
$conditions = parent::gridDataConditions($params, $model);
|
||||
|
||||
// REVISIT <AP>: 20090825
|
||||
// Sizes should come from the database.
|
||||
// For now, I took an assumed average need, then bracketed
|
||||
// with +/- 50 sqft. This gives a 100sqft range for each.
|
||||
if ($params['action'] === 'bd1') { // 75 sqft
|
||||
$conditions[] = array('UnitType.id' => array_keys($this->UnitSize->UnitType->enclosedTypes()));
|
||||
$conditions[] = '(UnitSize.width/12 * UnitSize.depth/12) <= 125';
|
||||
}
|
||||
elseif ($params['action'] === 'bd2') { // 125 sqft
|
||||
$conditions[] = array('UnitType.id' => array_keys($this->UnitSize->UnitType->enclosedTypes()));
|
||||
$conditions[] = '(UnitSize.width/12 * UnitSize.depth/12) >= 75';
|
||||
$conditions[] = '(UnitSize.width/12 * UnitSize.depth/12) <= 175';
|
||||
}
|
||||
elseif ($params['action'] === 'bd3') { // 175 sqft
|
||||
$conditions[] = array('UnitType.id' => array_keys($this->UnitSize->UnitType->enclosedTypes()));
|
||||
$conditions[] = '(UnitSize.width/12 * UnitSize.depth/12) >= 125';
|
||||
$conditions[] = '(UnitSize.width/12 * UnitSize.depth/12) <= 225';
|
||||
}
|
||||
elseif ($params['action'] === 'bd4') { // 225 sqft
|
||||
$conditions[] = array('UnitType.id' => array_keys($this->UnitSize->UnitType->enclosedTypes()));
|
||||
$conditions[] = '(UnitSize.width/12 * UnitSize.depth/12) >= 175';
|
||||
}
|
||||
elseif (in_array($params['action'], array('auto', 'boat', 'rv'))) {
|
||||
$conditions[] = array('UnitType.id' =>
|
||||
array_merge(array_keys($this->UnitSize->UnitType->enclosedTypes()),
|
||||
array_keys($this->UnitSize->UnitType->outdoorTypes())));
|
||||
list($width, $depth, $height) = array(8, 15, null);
|
||||
if ($params['action'] === 'auto')
|
||||
$depth = 15;
|
||||
elseif ($params['action'] === 'boat')
|
||||
$depth = 15;
|
||||
elseif ($params['action'] === 'rv')
|
||||
list($width, $depth, $height) = array(10, 25, 12);
|
||||
|
||||
$conditions[] = "(UnitSize.width/12) >= $width";
|
||||
$conditions[] = "(UnitSize.depth/12) >= $depth";
|
||||
if (isset($height))
|
||||
$conditions[] = array('OR' =>
|
||||
array("(UnitSize.height/12) >= $height",
|
||||
//"UnitSize.height IS NULL",
|
||||
array('UnitType.id' =>
|
||||
array_keys($this->UnitSize->UnitType->outdoorTypes())),
|
||||
));
|
||||
}
|
||||
|
||||
return $conditions;
|
||||
}
|
||||
|
||||
function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
|
||||
$links['UnitSize'] = array('name');
|
||||
return parent::gridDataPostProcessLinks($params, $model, $records, $links);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: view
|
||||
* - Displays information about a specific entry
|
||||
*/
|
||||
|
||||
function view($id = null) {
|
||||
if (!$id) {
|
||||
$this->Session->setFlash(__('Invalid Item.', true));
|
||||
$this->redirect(array('controller' => 'accounts', 'action'=>'index'));
|
||||
}
|
||||
|
||||
// Get the UnitSize and related fields
|
||||
$this->UnitSize->id = $id;
|
||||
$size = $this->UnitSize->find
|
||||
('first', array
|
||||
('contain' => array('UnitType'),
|
||||
'fields' => array('UnitSize.*', 'UnitType.*',
|
||||
'ROUND(UnitSize.width/12, 1) AS width',
|
||||
'ROUND(UnitSize.depth/12, 1) AS depth',
|
||||
'ROUND(UnitSize.height/12, 1) AS height',
|
||||
'ROUND(UnitSize.width/12 * UnitSize.depth/12, 0) AS sqft',
|
||||
'ROUND(UnitSize.width/12 * UnitSize.depth/12 * UnitSize.height/12, 0) AS cuft'),
|
||||
));
|
||||
$size['UnitSize'] = $size[0] + $size['UnitSize'];
|
||||
unset($size[0]);
|
||||
|
||||
$this->set(compact('size'));
|
||||
$this->set('stats', $this->UnitSize->stats($id));
|
||||
|
||||
// Prepare to render.
|
||||
$title = "Unit Size : {$size['UnitSize']['name']}";
|
||||
$this->set(compact('title'));
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: edit
|
||||
* - Edit unit_size information
|
||||
*/
|
||||
|
||||
function edit($id = null) {
|
||||
$this->INTERNAL_ERROR('NOT READY');
|
||||
if (isset($this->data)) {
|
||||
// Check to see if the operation was cancelled.
|
||||
if (isset($this->params['form']['cancel'])) {
|
||||
if (empty($this->data['UnitSize']['id']))
|
||||
$this->redirect(array('action'=>'index'));
|
||||
|
||||
$this->redirect(array('action'=>'view', $this->data['UnitSize']['id']));
|
||||
}
|
||||
|
||||
// Make sure we have unit_size data
|
||||
if (empty($this->data['UnitSize']) || empty($this->data['UnitSize']['id']))
|
||||
$this->redirect(array('action'=>'index'));
|
||||
|
||||
// Save the unit_size and all associated data
|
||||
$this->UnitSize->create();
|
||||
$this->UnitSize->id = $this->data['UnitSize']['id'];
|
||||
if (!$this->UnitSize->save($this->data, false)) {
|
||||
$this->Session->setFlash("UNIT_SIZE SAVE FAILED", true);
|
||||
pr("UNIT_SIZE SAVE FAILED");
|
||||
}
|
||||
|
||||
$this->redirect(array('action'=>'view', $this->UnitSize->id));
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$this->data = $this->UnitSize->findById($id);
|
||||
} else {
|
||||
$this->redirect(array('action'=>'index'));
|
||||
}
|
||||
|
||||
// Prepare to render.
|
||||
$title = ('UnitSize ' . $this->data['UnitSize']['name'] .
|
||||
" : Edit");
|
||||
$this->set(compact('title'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user