git-svn-id: file:///svn-source/pmgr/branches/initial_20090526/site@32 97e9348a-65ac-dc4b-aefc-98561f571b83
308 lines
13 KiB
PHP
308 lines
13 KiB
PHP
<?php
|
|
|
|
class MapsController extends AppController {
|
|
var $helpers = array('Html');
|
|
|
|
function index() {
|
|
$this->Map->recursive = 0;
|
|
/* $this->Map->MapSize->unbindModel(array('hasMany' => array('Map'))); */
|
|
/* $this->Map->MapSize->MapType->unbindModel(array('hasMany' => array('MapSize'))); */
|
|
//$this->Map->bindModel(array('hasOne' => array('MapType')));
|
|
//function paginate($conditions, $fields, $order, $limit, $page = 1, $recursive = null) {
|
|
$this->set('maps', $this->paginate(null, null, null, null, null, 0));
|
|
}
|
|
|
|
function view($id = null) {
|
|
if (!$id) {
|
|
$this->Session->setFlash(__('Invalid Item.', true));
|
|
$this->redirect(array('action'=>'index'));
|
|
}
|
|
$this->Map->recursive = 0;
|
|
$this->set('map', $this->Map->read(null, $id));
|
|
|
|
/* $this->Map->MapSize->unbindModel(array('hasMany' => array('Map'))); */
|
|
/* $this->Map->MapSize->MapType->unbindModel(array('hasMany' => array('MapSize'))); */
|
|
/* $this->Map->Lease->unbindModel(array('belongsTo' => array('Map'))); */
|
|
/* $this->Map->Lease->LeaseType->unbindModel(array('hasMany' => array('Lease'))); */
|
|
/* $this->Map->Lease->Charge->unbindModel(array('belongsTo' => array('Lease'))); */
|
|
/* $this->Map->Lease->Charge->ChargeType->unbindModel(array('hasMany' => array('Charge'))); */
|
|
/* $this->Map->Lease->Charge->Receipt->unbindModel(array('hasMany' => array('ChargesReceipt'))); */
|
|
|
|
/* //$this->Map->Lease->unbindModel(array('hasMany' => array('Contact'))); */
|
|
/* $this->Map->Lease->unbindModel(array('hasAndBelongsToMany' => array('Contact'))); */
|
|
/* //$this->Map->Lease->unbindModel(array('hasOne' => array('Contact'))); */
|
|
/* //$this->Map->Lease->unbindModel(array('belongsTo' => array('Contact'))); */
|
|
/* //$this->Map->Lease->bindModel(array('hasOne' => array('ContactsLease'))); */
|
|
/* //$this->Map->Lease->bindModel(array('hasOne' => array('Contact'))); */
|
|
/* /\* $this->Map->Lease->bindModel(array('hasOne' => array('ContactsLease', *\/ */
|
|
/* /\* 'Contact' => array( *\/ */
|
|
/* /\* 'foreignKey' => false, *\/ */
|
|
/* /\* 'conditions' => *\/ */
|
|
/* /\* array('Contact.id = ContactsLease.contact_id', *\/ */
|
|
/* /\* //'ContactsLease.type = "TENANT"' *\/ */
|
|
/* /\* ))))); *\/ */
|
|
|
|
/* $this->Map->bindModel(array('hasOne' => array('Lease' => array( */
|
|
/* 'foreignKey' => false, */
|
|
/* 'conditions' => array('Lease.map_id = Map.id') */
|
|
/* ), */
|
|
/* 'ContactsLease' => array( */
|
|
/* 'foreignKey' => false, */
|
|
/* 'conditions' => array('ContactsLease.lease_id = Lease.id') */
|
|
/* ), */
|
|
/* 'Contact' => array( */
|
|
/* 'foreignKey' => false, */
|
|
/* 'conditions' => array('Contact.id = ContactsLease.contact_id') */
|
|
/* ))), */
|
|
/* false); */
|
|
|
|
|
|
/* $this->Map->Lease->bindModel(array('hasOne' => array('Contact' => array( */
|
|
/* 'className' => 'ContactsLease', */
|
|
/* 'foreignKey' => false, */
|
|
/* 'conditions' => */
|
|
/* array('ContactsLease.lease_id = Lease.id', */
|
|
/* 'ContactsLease.type = "TENANT"'))))); */
|
|
|
|
/* # 'hasOne' => array( */
|
|
/* # 'RecipesTag', */
|
|
/* # 'FilterTag' => array( */
|
|
/* # 'className' => 'Tag', */
|
|
/* # 'foreignKey' => false, */
|
|
/* # 'conditions' => array('FilterTag.id = RecipesTag.tag_id') */
|
|
/* # )))); */
|
|
|
|
/* $this->Map->id = $id; */
|
|
/* if ($id !== null && $id !== false) { */
|
|
/* $this->Map->data = $this->Map->find('first', */
|
|
/* array('conditions' => array( */
|
|
/* $this->Map->alias . '.' . $this->Map->primaryKey => $id, */
|
|
/* 'ContactsLease.type = "TENANT"' */
|
|
/* ) */
|
|
/* )); */
|
|
/* $this->set('map', $this->Map->data); */
|
|
/* } */
|
|
}
|
|
|
|
|
|
// Temporary function
|
|
function unitStatusList() {
|
|
return
|
|
array('DELETED' => array(),
|
|
'DAMAGED' => array(),
|
|
'COMPANY' => array(),
|
|
'UNAVAILABLE' => array(),
|
|
'RESERVED' => array(),
|
|
'DIRTY' => array(),
|
|
'VACANT' => array(),
|
|
'OCCUPIED' => array(),
|
|
'LATE' => array(),
|
|
'LOCKED' => array(),
|
|
'LIENED' => array(),
|
|
);
|
|
}
|
|
|
|
function map($id = null, $requested_width = 600) {
|
|
$info = $this->mapInfo($id);
|
|
$info['border'] = true;
|
|
$info['clickable'] = true;
|
|
$this->image($info, $requested_width);
|
|
}
|
|
|
|
function legend($id = null, $requested_width = 400) {
|
|
$status = $this->unitStatusList();
|
|
$cols = 6;
|
|
$rows = (int)((count($status) + $cols - 1) / $cols);
|
|
|
|
$info = array('extents' => array(), 'units' => array(), 'legend' => array());
|
|
$info['legend']['width'] = 360;
|
|
$info['legend']['depth'] = 120;
|
|
|
|
$info['extents']['right'] = $info['legend']['width'] * $cols;
|
|
$info['extents']['bottom'] = $info['legend']['depth'] * $rows;
|
|
|
|
$top = $lft = 0;
|
|
foreach ($status AS $code => $color) {
|
|
$info['units'][] = array('name' => $code,
|
|
'status' => $code,
|
|
'width' => $info['legend']['width'],
|
|
'depth' => $info['legend']['depth'],
|
|
'left' => $lft,
|
|
'right' => $lft + $info['legend']['width'],
|
|
'top' => $top,
|
|
'bottom' => $top + $info['legend']['depth']);
|
|
$top += $info['legend']['depth'];
|
|
if ($top >= $info['legend']['depth'] * $rows) {
|
|
$top = 0; $lft += $info['legend']['width'];
|
|
}
|
|
}
|
|
|
|
$this->image($info, $requested_width, true);
|
|
}
|
|
|
|
function image($info, $requested_width, $legend = false) {
|
|
//var $helpers = array('Html', 'Form', 'Javascript', 'Graph');
|
|
$this->layout = null;
|
|
$this->autoLayout = false;
|
|
Configure::write('debug', '0');
|
|
|
|
// Define our color palate
|
|
// REVISIT <AP>: 20090513
|
|
// Get colors from DB option tables
|
|
$info['palate']['main']['layout']['bg'] = array('red' => 255, 'green' => 255, 'blue' => 255);
|
|
$info['palate']['main']['layout']['border'] = array('red' => 192, 'green' => 192, 'blue' => 192);
|
|
$info['palate']['main']['layout']['wall'] = array('red' => 0, 'green' => 0, 'blue' => 0);
|
|
$info['palate']['unit']['DELETED']['bg'] = array('red' => 0, 'green' => 0, 'blue' => 0);
|
|
$info['palate']['unit']['DAMAGED']['bg'] = array('red' => 192, 'green' => 128, 'blue' => 128);
|
|
$info['palate']['unit']['COMPANY']['bg'] = array('red' => 128, 'green' => 192, 'blue' => 128);
|
|
$info['palate']['unit']['UNAVAILABLE']['bg'] = array('red' => 128, 'green' => 128, 'blue' => 192);
|
|
$info['palate']['unit']['RESERVED']['bg'] = array('red' => 192, 'green' => 192, 'blue' => 128);
|
|
$info['palate']['unit']['DIRTY']['bg'] = array('red' => 128, 'green' => 192, 'blue' => 192);
|
|
$info['palate']['unit']['VACANT']['bg'] = array('red' => 0, 'green' => 255, 'blue' => 128);
|
|
$info['palate']['unit']['OCCUPIED']['bg'] = array('red' => 0, 'green' => 128, 'blue' => 255);
|
|
$info['palate']['unit']['LATE']['bg'] = array('red' => 255, 'green' => 64, 'blue' => 64);
|
|
$info['palate']['unit']['LOCKED']['bg'] = array('red' => 255, 'green' => 128, 'blue' => 128);
|
|
$info['palate']['unit']['LIENED']['bg'] = array('red' => 255, 'green' => 192, 'blue' => 192);
|
|
|
|
// Determine text color to go with each background
|
|
foreach ($info['palate']['unit'] AS &$code) {
|
|
$component = $code['bg'];
|
|
$method = 3;
|
|
if ($method == 1) {
|
|
foreach (array('red', 'green', 'blue') AS $prim)
|
|
$component[$prim] = 255 - $component[$prim];
|
|
} elseif ($method == 2) {
|
|
foreach (array('red', 'green', 'blue') AS $prim)
|
|
$component[$prim] = ($component[$prim]) >= 128 ? 0 : 255;
|
|
} elseif ($method == 3) {
|
|
$val = (sqrt(pow($component['red'], 2) +
|
|
pow($component['green'], 2) +
|
|
pow($component['blue'], 2)) >= sqrt(3) * 128) ? 0 : 255;
|
|
foreach (array('red', 'green', 'blue') AS $prim)
|
|
$component[$prim] = $val;
|
|
}
|
|
|
|
$code['fg'] = $component;
|
|
}
|
|
|
|
//pr($info);
|
|
|
|
/*****
|
|
* The preference would be to leave all things "screen" related
|
|
* to reside in the view. However, two separate views need this
|
|
* information. The 'view' needs it to include a clickable map
|
|
* that corresponds to the map image, and of course, the 'map'
|
|
* (or 'image') view needs it to render the image. So, in the
|
|
* controller for now, unless I come up with a better idea.
|
|
*****/
|
|
|
|
// Scale things according to desired display width
|
|
$screen_adjustment_factor = $requested_width / $info['extents']['right'];;
|
|
|
|
// Define image size
|
|
$info['width'] = $info['extents']['right'] * $screen_adjustment_factor;
|
|
$info['depth'] = $info['extents']['bottom'] * $screen_adjustment_factor;
|
|
|
|
// Go through each unit, adjusting map locations
|
|
foreach ($info['units'] AS $unit) {
|
|
$unit['left'] *= $screen_adjustment_factor;
|
|
$unit['right'] *= $screen_adjustment_factor;
|
|
$unit['top'] *= $screen_adjustment_factor;
|
|
$unit['bottom'] *= $screen_adjustment_factor;
|
|
}
|
|
|
|
$this->set(compact('info'));
|
|
$this->render('image');
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* mapInfo
|
|
*/
|
|
|
|
function mapInfo($site_area_id) {
|
|
// Set up array to hold the map information
|
|
$info = array('extents' => array(), 'units' => array());
|
|
|
|
$map = $this->Map->SiteArea->read(null, $site_area_id);
|
|
//pr($map);
|
|
|
|
$top_adjustment = 5;
|
|
$left_adjustment = 5;
|
|
$info['extents']['top'] = 0;
|
|
$info['extents']['left'] = 0;
|
|
$info['extents']['bottom'] = $top_adjustment + $map['Map']['depth'] + 5;
|
|
$info['extents']['right'] = $left_adjustment + $map['Map']['width'] + 5;
|
|
return $info;
|
|
|
|
// Get the overall site limits
|
|
$query = "SELECT M.id, M.width, M.depth";
|
|
$query .= " FROM pmgr_maps M";
|
|
$query .= " WHERE site_area_id = $site_area_id";
|
|
$result = $this->Map->query($query);
|
|
|
|
//pr($result);
|
|
$info['extents']['top'] = 0;
|
|
$info['extents']['left'] = 0;
|
|
$info['extents']['bottom'] = 360;
|
|
$info['extents']['right'] = 480;
|
|
$info['map_id'] = 1;
|
|
return $info;
|
|
|
|
/* // Fetch and verify the result */
|
|
/* $row = mysql_fetch_array($result); */
|
|
/* if (!$row) die("Site map query failed!"); */
|
|
/* mysql_free_result($result); */
|
|
|
|
/* // Compute the actual boundaries, adjusting for a border */
|
|
/* $top_adjustment = 5; */
|
|
/* $left_adjustment = 5; */
|
|
/* $info['extents']['top'] = 0; */
|
|
/* $info['extents']['left'] = 0; */
|
|
/* $info['extents']['bottom'] = $top_adjustment + $row['depth'] + 5; */
|
|
/* $info['extents']['right'] = $left_adjustment + $row['width'] + 5; */
|
|
/* $info['map_id'] = $row['id']; */
|
|
|
|
/* // Get list of units and positions */
|
|
/* $query = "SELECT U.id, U.name, U.status,"; */
|
|
/* $query .= " ($top_adjustment + Mu.pt_top) AS pt_top,"; */
|
|
/* $query .= " ($left_adjustment + Mu.pt_left) AS pt_left,"; */
|
|
/* //$query .= " ($top_adjustment + Mu.pt_bottom) AS pt_bottom,"; */
|
|
/* //$query .= " ($left_adjustment + Mu.pt_right) AS pt_right,"; */
|
|
/* $query .= " IF(Mu.transpose, S.depth, S.width) AS width,"; */
|
|
/* $query .= " IF(Mu.transpose, S.width, S.depth) AS depth"; */
|
|
/* //$query .= " Mu.transpose"; */
|
|
/* $query .= " FROM pmgr_maps_units Mu"; */
|
|
/* $query .= " JOIN pmgr_units U ON U.id = Mu.unit_id"; */
|
|
/* $query .= " JOIN pmgr_unit_sizes S ON S.id = U.size_id"; */
|
|
/* $query .= " WHERE Mu.map_id = $info[map_id]"; */
|
|
/* $result = sql_query($query); */
|
|
|
|
/* // Go through each one, calculating the map location */
|
|
/* while ($row = mysql_fetch_array($result)) { */
|
|
/* $info['units'][$row['id']] = */
|
|
/* array( 'id' => $row['id'], */
|
|
/* 'name' => $row['name'], */
|
|
/* 'left' => $row['pt_left'], */
|
|
/* 'right' => $row['pt_left'] + $row['width'], */
|
|
/* 'top' => $row['pt_top'], */
|
|
/* 'bottom' => $row['pt_top'] + $row['depth'], */
|
|
/* 'width' => $row['width'], */
|
|
/* 'depth' => $row['depth'], */
|
|
/* 'n-s' => $row['reverseWL'], */
|
|
/* 'status' => $row['status'] */
|
|
/* ); */
|
|
/* } */
|
|
|
|
/* // Free the result */
|
|
/* mysql_free_result($result); */
|
|
|
|
/* return $info; */
|
|
}
|
|
|
|
}
|
|
|
|
?>
|