git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@782 97e9348a-65ac-dc4b-aefc-98561f571b83
119 lines
4.2 KiB
PHP
119 lines
4.2 KiB
PHP
<?php
|
|
|
|
class UnitSizesController extends AppController {
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* virtuals: gridData
|
|
* - With the application controller handling the gridData action,
|
|
* these virtual functions ensure that the correct data is passed
|
|
* to jqGrid.
|
|
*/
|
|
|
|
function gridDataTables(&$params, &$model) {
|
|
return array();
|
|
}
|
|
|
|
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';
|
|
return $fields;
|
|
}
|
|
|
|
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'));
|
|
}
|
|
}
|