From 9bb957aff4b0d0ab2831f12ed52a54507cc3ed9b Mon Sep 17 00:00:00 2001 From: abijah Date: Sat, 4 Jul 2009 04:42:11 +0000 Subject: [PATCH] Got rid of the temporary function to determine unit status enums, and switched over to actually querying the database. Eliminated a legend entry for DELETED since no one should ever see a unit like that given that it should be, well, deleted. Modified the legend algorithm slightly to fix the number of rows instead of columns, since the placement algorithm works through the rows before moving to the next column. git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629/site@206 97e9348a-65ac-dc4b-aefc-98561f571b83 --- app_model.php | 2 +- controllers/maps_controller.php | 25 +++++-------------------- models/unit.php | 4 ++++ 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/app_model.php b/app_model.php index f2f0197..0f8aa86 100644 --- a/app_model.php +++ b/app_model.php @@ -72,7 +72,7 @@ class AppModel extends Model { //Get the values return array_flip(array_merge(array(''), // MySQL sets 0 to be the empty string - explode("','", preg_replace("/(enum)\('(.+?)'\)/","\\2", $types)) + explode("','", strtoupper(preg_replace("/(enum)\('(.+?)'\)/","\\2", $types))) )); } //end getEnumValues diff --git a/controllers/maps_controller.php b/controllers/maps_controller.php index 1684ce8..ebeb991 100644 --- a/controllers/maps_controller.php +++ b/controllers/maps_controller.php @@ -151,22 +151,6 @@ class MapsController extends AppController { return $info; } - // 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(), - ); - } /************************************************************************** ************************************************************************** @@ -176,9 +160,10 @@ class MapsController extends AppController { */ function legend($id = null, $requested_width = 400) { - $status = $this->unitStatusList(); - $cols = 6; - $rows = (int)((count($status) + $cols - 1) / $cols); + $status = $this->Map->Unit->activeStatusEnums(); + //pr($status); + $rows = 2; + $cols = (int)((count($status) + $rows - 1) / $rows); $info = array('units' => array()); @@ -206,7 +191,7 @@ class MapsController extends AppController { $item_width *= $screen_adjustment_factor; $item_depth *= $screen_adjustment_factor; - foreach ($status AS $code => $color) { + foreach ($status AS $code => $value) { $info['units'][] = array('name' => $code, 'status' => $code, 'width' => $item_width, diff --git a/models/unit.php b/models/unit.php index 2d1d519..a5abd89 100644 --- a/models/unit.php +++ b/models/unit.php @@ -40,6 +40,10 @@ class Unit extends AppModel { return $status_enums; } + function activeStatusEnums() { + return array_diff_key($this->statusEnums(), array(''=>1, 'DELETED'=>1)); + } + function statusValue($enum) { $enums = $this->statusEnums(); return $enums[$enum];