Further progress on the site map. The scale is off at the moment, but it's working well enough that it's worth a snapshot.

git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@33 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-05-29 02:45:23 +00:00
parent 9fc5562dd8
commit 4e33c58246
2 changed files with 116 additions and 163 deletions

View File

@@ -3,88 +3,118 @@
class MapsController extends AppController {
var $helpers = array('Html');
/**************************************************************************
**************************************************************************
**************************************************************************
* action: index
* - Generates a list of all site maps
*
* REVISIT <AP> 20090528:
* We'll need to present only those site area maps that correspond
* to the users particular site.
*/
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));
$this->set('maps', $this->paginate());
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: view
* - Generates a site map page
*/
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); */
/* } */
$this->set('info', $this->mapInfo($id));
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: map
* - Produces a PNG site map image
*/
function map($id = null, $requested_width = 600) {
if (!$id) {
$this->Session->setFlash(__('Invalid Item.', true));
$this->redirect(array('action'=>'index'));
}
$this->image($this->mapInfo($id), $requested_width);
}
/**************************************************************************
**************************************************************************
**************************************************************************
* mapInfo
*/
function mapInfo($id) {
// Set up array to hold the map information
$info = array('extents' => array(), 'units' => array(),
'map_id' => $id, 'border' => true);
/* // Find all of the map/unit information from this SiteArea */
/* $this->Map->SiteArea->recursive = 3; */
/* $this->Map->SiteArea->Site->unbindModel(array('hasMany' => array('SiteArea'))); */
/* $this->Map->unbindModel(array('belongsTo' => array('SiteArea'))); */
/* $map = $this->Map->SiteArea->read(null, $site_area_id); */
// Find all of the map/unit information from this SiteArea
$this->Map->recursive = 2;
$this->Map->SiteArea->unbindModel(array('hasOne' => array('Map')));
$map = $this->Map->read(null, $id);
//pr($map);
// Get the overall site limits, and then compute the
// actual boundary extents, adjusting for a border
$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;
// Go through each unit in the map, calculating the map location
foreach ($map['Unit'] AS $unit) {
$lft = $unit['MapsUnit']['pt_left'] + $left_adjustment;
$top = $unit['MapsUnit']['pt_top'] + $top_adjustment;
$width =
$unit['MapsUnit']['transpose']
? $unit['UnitSize']['depth']
: $unit['UnitSize']['width'];
$depth =
$unit['MapsUnit']['transpose']
? $unit['UnitSize']['width']
: $unit['UnitSize']['depth'];
$info['units'][$unit['id']] =
array( 'id' => $unit['id'],
'name' => $unit['name'],
'left' => $lft,
'right' => $lft + $width,
'top' => $top,
'bottom' => $top + $depth,
'width' => $width,
'depth' => $depth,
'n-s' => $unit['MapsUnit']['transpose'] ? 0 : 1,
'status' => $unit['status']
);
}
//pr($info);
return $info;
}
// Temporary function
function unitStatusList() {
return
@@ -102,12 +132,12 @@ class MapsController extends AppController {
);
}
function map($id = null, $requested_width = 600) {
$info = $this->mapInfo($id);
$info['border'] = true;
$info['clickable'] = true;
$this->image($info, $requested_width);
}
/**************************************************************************
**************************************************************************
**************************************************************************
* action: legend
* - Produces a PNG color legend image
*/
function legend($id = null, $requested_width = 400) {
$status = $this->unitStatusList();
@@ -140,6 +170,14 @@ class MapsController extends AppController {
$this->image($info, $requested_width, true);
}
/**************************************************************************
**************************************************************************
**************************************************************************
* helper: image
* - used by actions map & legend to set up unit information and
* color palates before rendering the PNG image.
*/
function image($info, $requested_width, $legend = false) {
//var $helpers = array('Html', 'Form', 'Javascript', 'Graph');
$this->layout = null;
@@ -217,91 +255,6 @@ class MapsController extends AppController {
/**************************************************************************
**************************************************************************
**************************************************************************
* 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; */
}
}

View File

@@ -3,8 +3,8 @@
<DIV>
<?php
echo $html->image(array('controller' => 'maps',
'action' => 'map',
$map['Map']['id']),
'action' => 'map',
$info['map_id']),
array('alt' => 'Site Map',
'class' => 'imagemap',
'usemap' => '#mapimg'));