From 8ea3c3b1db703fa6ee9e278729f1fb7968285d1e Mon Sep 17 00:00:00 2001 From: wangyidong Date: Tue, 8 Jan 2013 08:03:02 +0000 Subject: [PATCH] * refactory. * mv objectTables to config/config.php from action/config.php. --- config/config.php | 15 +++++++++++++++ module/action/config.php | 15 --------------- module/action/model.php | 13 ++++++------- module/common/model.php | 11 ++--------- 4 files changed, 23 insertions(+), 31 deletions(-) diff --git a/config/config.php b/config/config.php index 51b1b8a8c0..76f30a5413 100644 --- a/config/config.php +++ b/config/config.php @@ -121,3 +121,18 @@ define('TABLE_FILE', '`' . $config->db->prefix . 'file`'); define('TABLE_HISTORY', '`' . $config->db->prefix . 'history`'); define('TABLE_EXTENSION', '`' . $config->db->prefix . 'extension`'); define('TABLE_WEBAPP', '`' . $config->db->prefix . 'webapp`'); + +$config->objectTables['product'] = TABLE_PRODUCT; +$config->objectTables['story'] = TABLE_STORY; +$config->objectTables['productplan'] = TABLE_PRODUCTPLAN; +$config->objectTables['release'] = TABLE_RELEASE; +$config->objectTables['project'] = TABLE_PROJECT; +$config->objectTables['task'] = TABLE_TASK; +$config->objectTables['build'] = TABLE_BUILD; +$config->objectTables['bug'] = TABLE_BUG; +$config->objectTables['case'] = TABLE_CASE; +$config->objectTables['testtask'] = TABLE_TESTTASK; +$config->objectTables['user'] = TABLE_USER; +$config->objectTables['doc'] = TABLE_DOC; +$config->objectTables['doclib'] = TABLE_DOCLIB; +$config->objectTables['todo'] = TABLE_TODO; diff --git a/module/action/config.php b/module/action/config.php index 40c263b121..bf0b275538 100644 --- a/module/action/config.php +++ b/module/action/config.php @@ -1,19 +1,4 @@ action->objectTables['product'] = TABLE_PRODUCT; -$config->action->objectTables['story'] = TABLE_STORY; -$config->action->objectTables['productplan'] = TABLE_PRODUCTPLAN; -$config->action->objectTables['release'] = TABLE_RELEASE; -$config->action->objectTables['project'] = TABLE_PROJECT; -$config->action->objectTables['task'] = TABLE_TASK; -$config->action->objectTables['build'] = TABLE_BUILD; -$config->action->objectTables['bug'] = TABLE_BUG; -$config->action->objectTables['case'] = TABLE_CASE; -$config->action->objectTables['testtask'] = TABLE_TESTTASK; -$config->action->objectTables['user'] = TABLE_USER; -$config->action->objectTables['doc'] = TABLE_DOC; -$config->action->objectTables['doclib'] = TABLE_DOCLIB; -$config->action->objectTables['todo'] = TABLE_TODO; - $config->action->objectNameFields['product'] = 'name'; $config->action->objectNameFields['story'] = 'title'; $config->action->objectNameFields['productplan'] = 'title'; diff --git a/module/action/model.php b/module/action/model.php index 6090db85e4..e2c70344b6 100644 --- a/module/action/model.php +++ b/module/action/model.php @@ -42,7 +42,7 @@ class actionModel extends model $action->extra = $extra; /* Get product and project for this object. */ - $productAndProject = $this->getProductAndProject($objectType, $objectID); + $productAndProject = $this->getProductAndProject($action->objectType, $objectID); $action->product = $productAndProject['product']; $action->project = $productAndProject['project']; @@ -119,7 +119,6 @@ class actionModel extends model */ public function getProductAndProject($objectType, $objectID) { - $objectType = strtolower($objectType); $emptyRecord = array('product' => ',0,', 'project' => 0); /* If objectType is product or project, return the objectID. */ @@ -134,7 +133,7 @@ class actionModel extends model /* Only process these object types. */ if(strpos('story, productplan, release, task, build. bug, case, testtask, doc', $objectType) !== false) { - if(!isset($this->config->action->objectTables[$objectType])) return $emptyRecord; + if(!isset($this->config->objectTables[$objectType])) return $emptyRecord; /* Set fields to fetch. */ if(strpos('story, productplan, case', $objectType) !== false) $fields = 'product'; @@ -142,7 +141,7 @@ class actionModel extends model if($objectType == 'release') $fields = 'product, build'; if($objectType == 'task') $fields = 'project, story'; - $record = $this->dao->select($fields)->from($this->config->action->objectTables[$objectType])->where('id')->eq($objectID)->fetch(); + $record = $this->dao->select($fields)->from($this->config->objectTables[$objectType])->where('id')->eq($objectID)->fetch(); /* Process story, release and task. */ if($objectType == 'story') $record->project = $this->dao->select('project')->from(TABLE_PROJECTSTORY)->where('story')->eq($objectID)->fetch('project'); @@ -236,7 +235,7 @@ class actionModel extends model foreach($typeTrashes as $objectType => $objectIds) { $objectIds = array_unique($objectIds); - $table = $this->config->action->objectTables[$objectType]; + $table = $this->config->objectTables[$objectType]; $field = $this->config->action->objectNameFields[$objectType]; $objectNames[$objectType] = $this->dao->select("id, $field AS name")->from($table)->where('id')->in($objectIds)->fetchPairs(); } @@ -471,10 +470,10 @@ class actionModel extends model foreach($actions as $object) $objectTypes[$object->objectType][] = $object->objectID; foreach($objectTypes as $objectType => $objectIds) { - if(!isset($this->config->action->objectTables[$objectType])) continue; // If no defination for this type, omit it. + if(!isset($this->config->objectTables[$objectType])) continue; // If no defination for this type, omit it. $objectIds = array_unique($objectIds); - $table = $this->config->action->objectTables[$objectType]; + $table = $this->config->objectTables[$objectType]; $field = $this->config->action->objectNameFields[$objectType]; if($table != '`zt_todo`') { diff --git a/module/common/model.php b/module/common/model.php index 70bca1c226..d9f03e8a5e 100644 --- a/module/common/model.php +++ b/module/common/model.php @@ -491,15 +491,8 @@ class commonModel extends model { $preAndNextObject = new stdClass(); - switch($type) - { - case 'story' : $table = TABLE_STORY; break; - case 'task' : $table = TABLE_TASK; break; - case 'bug' : $table = TABLE_BUG; break; - case 'testcase' : $table = TABLE_CASE; break; - case 'doc' : $table = TABLE_DOC; break; - default : return $preAndNextObject; - } + if(strpos('story, task, bug, testcase, doc', $type) === false) return $preAndNextObject; + $table = $this->config->objectTables[$type]; $typeIDs = $type . 'IDs'; if($this->session->$typeIDs and strpos($this->session->$typeIDs, ',' . $objectID . ',') !== false)