First pass at implementing a new lock tracking mechnism. Not complete, but the basics seem to work
git-svn-id: file:///svn-source/pmgr/branches/v0.3_work@1038 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
152
site/controllers/locks_controller.php
Normal file
152
site/controllers/locks_controller.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
class LocksController extends AppController {
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* override: addGridViewSideMenuLinks
|
||||
* - Adds grid view navigation side menu links
|
||||
*/
|
||||
|
||||
function addGridViewSideMenuLinks() {
|
||||
parent::addGridViewSideMenuLinks();
|
||||
|
||||
$this->addSideMenuLink('Add',
|
||||
array('controller' => 'locks', 'action' => 'add'), null,
|
||||
'CONTROLLER');
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: index / all
|
||||
* - Generate a listing of locks
|
||||
*/
|
||||
|
||||
function index() { $this->all(); }
|
||||
function all() { $this->gridView('Locks', '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('Unit')); */
|
||||
/* } */
|
||||
|
||||
function gridDataTables(&$params, &$model) {
|
||||
$tables = parent::gridDataTables($params, $model);
|
||||
$tables['link']['LocksUnit'] = array();
|
||||
return $tables;
|
||||
}
|
||||
|
||||
function gridDataFields(&$params, &$model) {
|
||||
$fields = parent::gridDataFields($params, $model);
|
||||
$fields[] = 'COUNT(LocksUnit.id) AS inuse';
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* 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->Lock->id = $id;
|
||||
$lock = $this->Lock->find
|
||||
('first', array
|
||||
('contain' => array(),
|
||||
));
|
||||
//$lock['Lock'] = $lock[0] + $lock['lock'];
|
||||
//unset($lock[0]);
|
||||
|
||||
$this->addSideMenuLink('Edit',
|
||||
array('action' => 'edit', $id), null,
|
||||
'ACTION');
|
||||
|
||||
$this->set(compact('lock'));
|
||||
|
||||
// Prepare to render.
|
||||
$title = "Lock : {$lock['Lock']['name']}";
|
||||
$this->set(compact('title'));
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: edit
|
||||
* - Edit customer information
|
||||
*/
|
||||
|
||||
function edit($id = null) {
|
||||
if (isset($this->data)) {
|
||||
// Check to see if the operation was cancelled.
|
||||
if (isset($this->params['form']['cancel'])) {
|
||||
if (isset($this->data['Lock']['id']))
|
||||
$this->redirect(array('action'=>'view', $this->data['Lock']['id']));
|
||||
|
||||
$this->redirect(array('action'=>'index'));
|
||||
}
|
||||
|
||||
// Save the lock and all associated data
|
||||
if (!$this->Lock->saveLock($this->data)) {
|
||||
$this->Session->setFlash("LOCK SAVE FAILED", true);
|
||||
pr("LOCK SAVE FAILED");
|
||||
}
|
||||
|
||||
// View the lock by redirect
|
||||
$this->redirect(array('action'=>'view', $this->Lock->id));
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
// Get details on this customer, its contacts and leases
|
||||
$lock = $this->Lock->find
|
||||
('first', array
|
||||
('conditions' => array('Lock.id' => $id),
|
||||
));
|
||||
|
||||
$this->data = $lock;
|
||||
$title = 'Lock: ' . $this->data['Lock']['name'] . " : Edit";
|
||||
}
|
||||
else {
|
||||
$title = "Enter New Lock Information";
|
||||
$this->data = array();
|
||||
}
|
||||
|
||||
// Prepare to render.
|
||||
//pr($this->data);
|
||||
$this->set(compact('title'));
|
||||
$this->render('edit');
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: add
|
||||
* - Add a new lock
|
||||
*/
|
||||
|
||||
function add() {
|
||||
$this->edit();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -213,7 +213,7 @@ class UnitsController extends AppController {
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: lock/unlock
|
||||
* action: lock/unlock/lien
|
||||
* - Transitions the unit into / out of the LOCKED state
|
||||
*/
|
||||
|
||||
@@ -221,8 +221,73 @@ class UnitsController extends AppController {
|
||||
$this->Unit->updateStatus($id, $status, true);
|
||||
$this->redirect(array('action' => 'view', $id));
|
||||
}
|
||||
function lock($id) { $this->status($id, 'LOCKED'); }
|
||||
function unlock($id) { $this->status($id, 'OCCUPIED'); }
|
||||
|
||||
function lock($id) {
|
||||
if (isset($this->data)) {
|
||||
$id = $this->id = $this->data['Unit']['id'];
|
||||
|
||||
// Check to see if the operation was cancelled.
|
||||
if (isset($this->params['form']['cancel'])) {
|
||||
if (isset($id))
|
||||
$this->redirect(array('action'=>'view', $id));
|
||||
|
||||
$this->redirect(array('action'=>'index'));
|
||||
}
|
||||
|
||||
// Figure out which locks the user put on
|
||||
$locks = array();
|
||||
if (isset($this->data['Lock']) && is_array($this->data['Lock'])) {
|
||||
foreach ($this->data['Lock'] AS $lock) {
|
||||
$locks[] = $lock['id'];
|
||||
}
|
||||
}
|
||||
|
||||
// Save the lock and all associated data
|
||||
if (!$this->Unit->lockUnit($id, $locks)) {
|
||||
$this->Session->setFlash("UNIT LOCK FAILED", true);
|
||||
pr("UNIT LOCK FAILED");
|
||||
}
|
||||
|
||||
// If it's no longer locked, change status to OCCUPIED
|
||||
// Could still be liened... but that would be odd.
|
||||
if (count($locks) == 0)
|
||||
$this->status($id, 'OCCUPIED');
|
||||
|
||||
// If we're not liened, we must now just be locked
|
||||
if (!$this->Unit->liened($id))
|
||||
$this->status($id, 'LOCKED');
|
||||
|
||||
// Otherwise, don't change anything.
|
||||
$this->redirect(array('action' => 'view', $id));
|
||||
}
|
||||
|
||||
if (!$id)
|
||||
$this->INTERNAL_ERROR("$id cannot be NULL");
|
||||
|
||||
// Get all locks on this unit
|
||||
$this->data = $this->Unit->find
|
||||
('first',
|
||||
array('contain' => array('Lock' => array('id')),
|
||||
'fields' => array('id'),
|
||||
'conditions' => array('Unit.id' => $id)
|
||||
));
|
||||
|
||||
$locks = $this->Unit->Lock->lockList();
|
||||
/* $locksold = $locks; */
|
||||
/* foreach ($locksold AS $name) { */
|
||||
/* $locks[$name] = $name; */
|
||||
/* } */
|
||||
$this->set(compact('locks'));
|
||||
|
||||
// Prepare to render.
|
||||
//pr($this->data);
|
||||
$this->set(compact('title'));
|
||||
// $this->render('lock');
|
||||
}
|
||||
|
||||
|
||||
function unlock($id) { $this->lock($id); }
|
||||
function lien($id) { $this->status($id, 'LIENED'); }
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
@@ -339,15 +404,20 @@ class UnitsController extends AppController {
|
||||
if ($this->Unit->occupied($unit['Unit']['status']) &&
|
||||
!$this->Unit->locked($unit['Unit']['status']))
|
||||
$this->addSideMenuLink('Lock',
|
||||
array('action' => 'Lock', $id), null,
|
||||
array('action' => 'lock', $id), null,
|
||||
'ACTION');
|
||||
|
||||
// If the unit is locked, provide an option to unlock it,
|
||||
// unless it's locked due to lien, which is not so simple.
|
||||
if ($this->Unit->locked($unit['Unit']['status']))
|
||||
$this->addSideMenuLink('Relock/Unlock',
|
||||
array('action' => 'lock', $id), null,
|
||||
'ACTION');
|
||||
|
||||
// If the unit is locked, but not liened, give option to lien.
|
||||
if ($this->Unit->locked($unit['Unit']['status']) &&
|
||||
!$this->Unit->liened($unit['Unit']['status']))
|
||||
$this->addSideMenuLink('Unlock',
|
||||
array('action' => 'unlock', $id), null,
|
||||
$this->addSideMenuLink('Lien',
|
||||
array('action' => 'lien', $id), null,
|
||||
'ACTION');
|
||||
|
||||
// If there is a current lease on this unit, then provide
|
||||
|
||||
Reference in New Issue
Block a user