diff --git a/module/bug/control.php b/module/bug/control.php
index c375c21e42..f0b5df5d34 100755
--- a/module/bug/control.php
+++ b/module/bug/control.php
@@ -2291,10 +2291,10 @@ class bug extends control
{
if($_POST)
{
- $this->loadModel('file');
- $this->loadModel('branch');
-
- $this->fetch('port', 'export', 'model=bug¶ms=productID=' . $productID . ',executionID=' . $executionID);
+ $this->loadModel('port');
+ $this->session->set('bugPortParams', array('productID' => $productID, 'executionID' => $executionID));
+ $this->port->export('bug');
+ $this->fetch('file', 'export2' . $_POST['fileType'], $_POST);
}
$fileName = $this->lang->bug->common;
diff --git a/module/port/config.php b/module/port/config.php
index 1d60629e14..445802d3e8 100644
--- a/module/port/config.php
+++ b/module/port/config.php
@@ -11,10 +11,6 @@ $config->port->fieldList['class'] = '';
$config->port->fieldList['sort'] = '';
$config->port->fieldList['dataSource'] = array('module' => '', 'method' => '', 'params' => '', 'pairs' => '', 'sql' => '', 'lang' => '');
-$config->port->table['mainTable']['name'] = '';
-$config->port->table['mainTable']['fields'] = explode(',', "");
-$config->port->table['mainTable']['foreignKey'] = '';
-
$config->port->initFunction = 'title,control,required,';
$config->port->dateFeilds = 'estStarted,realStarted,deadline,openedDate,assignedDate,finishedDate,canceledDate,closedDate,lastEditedDate,';
$config->port->datetimeFeilds = '';
diff --git a/module/story/config.php b/module/story/config.php
index 3cd8e6e6f1..1b90abc3e0 100644
--- a/module/story/config.php
+++ b/module/story/config.php
@@ -39,18 +39,13 @@ $config->story->exportFields = '
lastEditedBy, lastEditedDate,
childStories, linkStories, duplicateStory, files';
-$config->product->fieldList['product']['title'] = 'product';
-$config->product->fieldList['product']['foreignKey'] = true;
-$config->product->fieldList['product']['foreignKeySource'] = array('module' => 'product', 'method' => 'getPairs');
+$config->story->fieldList['product']['dataSource'] = array('module' => 'port', 'method' => 'getRelatedObjects', 'params' => 'story&product&id,name');
-$config->story->fieldList['branch']['foreignKey'] = true;
-$config->story->fieldList['branch']['foreignKeySource'] = array('module' => 'story', 'method' => 'getRelatedObjects', 'params' => 'branch&id,name');
+$config->story->fieldList['branch']['dataSource'] = array('module' => 'story', 'method' => 'getRelatedObjects', 'params' => 'branch&id,name');
-$config->story->fieldList['module']['foreignKey'] = true;
-$config->story->fieldList['module']['foreignKeySource'] = array('module' => 'tree', 'method' => 'getAllModulePairs', 'params' => 'story');
+$config->story->fieldList['module']['dataSource'] = array('module' => 'tree', 'method' => 'getAllModulePairs', 'params' => 'story');
-$config->story->fieldList['plan']['foreignKey'] = true;
-$config->story->fieldList['plan']['foreignKeySource'] = array('module' => 'story', 'method' => 'getRelatedObjects', 'params' => 'plan&id,title');
+$config->story->fieldList['plan']['dataSource'] = array('module' => 'story', 'method' => 'getRelatedObjects', 'params' => 'plan&id,title');
$config->story->list->customCreateFields = 'source,verify,pri,estimate,mailto,keywords';
$config->story->list->customBatchCreateFields = 'plan,spec,source,verify,pri,estimate,review,keywords';
diff --git a/module/story/control.php b/module/story/control.php
index c11cb56806..203abc8e5c 100644
--- a/module/story/control.php
+++ b/module/story/control.php
@@ -2436,260 +2436,10 @@ class story extends control
/* format the fields of every story in order to export data. */
if($_POST)
{
- $this->loadModel('file');
- $this->loadModel('branch');
- $storyLang = $this->lang->story;
- $storyConfig = $this->config->story;
-
+ $this->session->set('storyPortParams', array('productID' => $productID, 'executionID' => $executionID));
/* Create field lists. */
- $fields = $this->post->exportFields ? $this->post->exportFields : explode(',', $storyConfig->list->exportFields);
- foreach($fields as $key => $fieldName)
- {
- $fieldName = trim($fieldName);
- $fields[$fieldName] = isset($storyLang->$fieldName) ? $storyLang->$fieldName : $fieldName;
- unset($fields[$key]);
- }
-
- /* Get stories. */
- $stories = array();
- if($this->session->storyOnlyCondition)
- {
- if($this->post->exportType == 'selected')
- {
- $stories = $this->dao->select('*')->from(TABLE_STORY)->where('id')->in($this->cookie->checkedItem)->orderBy($orderBy)->fetchAll('id');
- }
- else
- {
- $stories = $this->dao->select('*')->from(TABLE_STORY)->where($this->session->storyQueryCondition)->orderBy($orderBy)->fetchAll('id');
- }
- }
- else
- {
- $field = $executionID ? 't2.id' : 't1.id';
- if($this->post->exportType == 'selected')
- {
- $stmt = $this->dbh->query("SELECT * FROM " . TABLE_STORY . "WHERE `id` IN({$this->cookie->checkedItem})" . " ORDER BY " . strtr($orderBy, '_', ' '));
- }
- else
- {
- $stmt = $this->dbh->query($this->session->storyQueryCondition . " ORDER BY " . strtr($orderBy, '_', ' '));
- }
- while($row = $stmt->fetch()) $stories[$row->id] = $row;
- }
- $storyIdList = array_keys($stories);
-
- if($stories)
- {
- $children = array();
- foreach($stories as $story)
- {
- if($story->parent > 0 and isset($stories[$story->parent]))
- {
- $children[$story->parent][$story->id] = $story;
- unset($stories[$story->id]);
- }
- }
-
- if(!empty($children))
- {
- $reorderStories = array();
- foreach($stories as $story)
- {
- $reorderStories[$story->id] = $story;
- if(isset($children[$story->id]))
- {
- foreach($children[$story->id] as $childrenID => $childrenStory)
- {
- $reorderStories[$childrenID] = $childrenStory;
- }
- }
- unset($stories[$story->id]);
- }
- $stories = $reorderStories;
- }
- }
-
- /* Get users, products and relations. */
- $users = $this->loadModel('user')->getPairs('noletter');
- $products = $this->product->getPairs('nocode');
- $relations = $this->story->getStoryRelationByIds($storyIdList, $type);
-
- /* Get related objects id lists. */
- $relatedProductIdList = array();
- $relatedStoryIdList = array();
- $relatedPlanIdList = array();
- $relatedBranchIdList = array();
- $relatedStoryIds = array();
-
- foreach($stories as $story)
- {
- $relatedProductIdList[$story->product] = $story->product;
- $relatedPlanIdList[$story->plan] = $story->plan;
- $relatedBranchIdList[$story->branch] = $story->branch;
- $relatedStoryIds[$story->id] = $story->id;
-
- if(isset($relations[$story->id])) $story->childStories = $story->childStories . ',' . $relations[$story->id];
-
- /* Process related stories. */
- $relatedStories = $story->childStories . ',' . $story->linkStories . ',' . $story->duplicateStory;
- $relatedStories = explode(',', $relatedStories);
- foreach($relatedStories as $storyID)
- {
- if($storyID) $relatedStoryIdList[$storyID] = trim($storyID);
- }
- }
-
- $storyTasks = $this->loadModel('task')->getStoryTaskCounts($relatedStoryIds);
- $storyBugs = $this->loadModel('bug')->getStoryBugCounts($relatedStoryIds);
- $storyCases = $this->loadModel('testcase')->getStoryCaseCounts($relatedStoryIds);
-
- /* Get related objects title or names. */
- $productsType = $this->dao->select('id, type')->from(TABLE_PRODUCT)->where('id')->in($relatedProductIdList)->fetchPairs();
- $relatedPlans = $this->dao->select('id, title')->from(TABLE_PRODUCTPLAN)->where('id')->in(join(',', $relatedPlanIdList))->fetchPairs();
- $relatedStories = $this->dao->select('id,title')->from(TABLE_STORY)->where('id')->in($relatedStoryIdList)->fetchPairs();
- $relatedFiles = $this->dao->select('id, objectID, pathname, title')->from(TABLE_FILE)->where('objectType')->eq($type)->andWhere('objectID')->in($storyIdList)->andWhere('extra')->ne('editor')->fetchGroup('objectID');
- $relatedSpecs = $this->dao->select('*')->from(TABLE_STORYSPEC)->where('`story`')->in($storyIdList)->orderBy('version desc')->fetchGroup('story');
- $relatedBranch = array('0' => $this->lang->branch->main) + $this->dao->select('id, name')->from(TABLE_BRANCH)->where('id')->in($relatedBranchIdList)->fetchPairs();
- $relatedModules = $this->loadModel('tree')->getAllModulePairs();
-
- foreach($stories as $story)
- {
- $story->spec = '';
- $story->verify = '';
- if(isset($relatedSpecs[$story->id]))
- {
- $storySpec = $relatedSpecs[$story->id][0];
- $story->title = $storySpec->title;
- $story->spec = $storySpec->spec;
- $story->verify = $storySpec->verify;
- }
-
- if($this->post->fileType == 'csv')
- {
- $story->spec = htmlspecialchars_decode($story->spec);
- $story->spec = str_replace("
", "\n", $story->spec);
- $story->spec = str_replace('"', '""', $story->spec);
- $story->spec = str_replace(' ', ' ', $story->spec);
-
- $story->verify = htmlspecialchars_decode($story->verify);
- $story->verify = str_replace("
", "\n", $story->verify);
- $story->verify = str_replace('"', '""', $story->verify);
- $story->verify = str_replace(' ', ' ', $story->verify);
- }
- /* fill some field with useful value. */
- if(isset($products[$story->product])) $story->product = $this->post->fileType == 'word' ? $products[$story->product] : $products[$story->product] . "(#$story->product)";
- if(isset($relatedModules[$story->module])) $story->module = $this->post->fileType == 'word' ? $relatedModules[$story->module] : $relatedModules[$story->module] . "(#$story->module)";
- if(isset($relatedBranch[$story->branch])) $story->branch = $relatedBranch[$story->branch] . "(#$story->branch)";
- if(isset($story->plan))
- {
- $plans = '';
- foreach(explode(',', $story->plan) as $planID)
- {
- if(empty($planID)) continue;
- if(isset($relatedPlans[$planID])) $plans .= $this->post->fileType == 'word' ? $relatedPlans[$planID] : $relatedPlans[$planID] . "(#$planID)";
- }
- $story->plan = $plans;
- }
- if(isset($relatedStories[$story->duplicateStory]) and $story->closedReason != 'duplicate') $story->duplicateStory = $relatedStories[$story->duplicateStory];
-
- if(isset($storyLang->priList[$story->pri])) $story->pri = $storyLang->priList[$story->pri];
- if(isset($storyLang->statusList[$story->status])) $story->status = $this->processStatus('story', $story);
- if(isset($storyLang->stageList[$story->stage])) $story->stage = $storyLang->stageList[$story->stage];
- if(isset($storyLang->reasonList[$story->closedReason])) $story->closedReason = $storyLang->reasonList[$story->closedReason];
- if(isset($storyLang->sourceList[$story->source])) $story->source = $storyLang->sourceList[$story->source];
- if(isset($storyLang->categoryList[$story->category])) $story->category = $storyLang->categoryList[$story->category];
-
- if(isset($users[$story->openedBy])) $story->openedBy = $users[$story->openedBy];
- if(isset($users[$story->assignedTo])) $story->assignedTo = $users[$story->assignedTo] . "(#$story->assignedTo)";
- if(isset($users[$story->lastEditedBy])) $story->lastEditedBy = $users[$story->lastEditedBy];
- if(isset($users[$story->closedBy])) $story->closedBy = $users[$story->closedBy];
-
- if(isset($storyTasks[$story->id])) $story->taskCountAB = $storyTasks[$story->id];
- if(isset($storyBugs[$story->id])) $story->bugCountAB = $storyBugs[$story->id];
- if(isset($storyCases[$story->id])) $story->caseCountAB = $storyCases[$story->id];
-
- $story->openedDate = substr($story->openedDate, 0, 10);
- $story->assignedDate = substr($story->assignedDate, 0, 10);
- $story->lastEditedDate = substr($story->lastEditedDate, 0, 10);
- $story->closedDate = substr($story->closedDate, 0, 10);
-
- if($story->linkStories)
- {
- $tmpLinkStories = array();
- $linkStoriesIdList = explode(',', $story->linkStories);
- foreach($linkStoriesIdList as $linkStoryID)
- {
- $linkStoryID = trim($linkStoryID);
- $tmpLinkStories[] = isset($relatedStories[$linkStoryID]) ? $relatedStories[$linkStoryID] : $linkStoryID;
- }
- $story->linkStories = join("; \n", $tmpLinkStories);
- }
-
- if($story->childStories)
- {
- $tmpChildStories = array();
- $childStoriesIdList = explode(',', $story->childStories);
- foreach($childStoriesIdList as $childStoryID)
- {
- if(empty($childStoryID)) continue;
-
- $childStoryID = trim($childStoryID);
- $tmpChildStories[] = isset($relatedStories[$childStoryID]) ? $relatedStories[$childStoryID] : $childStoryID;
- }
- $story->childStories = join("; \n", $tmpChildStories);
- }
-
- /* Set related files. */
- $story->files = '';
- if(isset($relatedFiles[$story->id]))
- {
- foreach($relatedFiles[$story->id] as $file)
- {
- $fileURL = common::getSysURL() . helper::createLink('file', 'download', "fileID=$file->id");
- $story->files .= html::a($fileURL, $file->title, '_blank') . '
';
- }
- }
-
- $story->mailto = trim(trim($story->mailto), ',');
- $mailtos = explode(',', $story->mailto);
- $story->mailto = '';
- foreach($mailtos as $mailto)
- {
- $mailto = trim($mailto);
- if(isset($users[$mailto])) $story->mailto .= $users[$mailto] . ',';
- }
- $story->mailto = rtrim($story->mailto, ',');
-
- $story->reviewedBy = trim(trim($story->reviewedBy), ',');
- $reviewedBys = explode(',', $story->reviewedBy);
- $story->reviewedBy = '';
- foreach($reviewedBys as $reviewedBy)
- {
- $reviewedBy = trim($reviewedBy);
- if(isset($users[$reviewedBy])) $story->reviewedBy .= $users[$reviewedBy] . ',';
- }
- $story->reviewedBy = rtrim($story->reviewedBy, ',');
-
- /* Set child story title. */
- if($story->parent > 0 && strpos($story->title, htmlentities('>', ENT_COMPAT | ENT_HTML401, 'UTF-8')) !== 0) $story->title = '>' . $story->title;
- }
-
- if($executionID)
- {
- $header = new stdclass();
- $header->name = 'execution';
- $header->tableName = TABLE_EXECUTION;
-
- $this->post->set('header', $header);
- }
- if(!(in_array('platform', $productsType) or in_array('branch', $productsType))) unset($fields['branch']);// If products's type are normal, unset branch field.
-
- if($this->config->edition != 'open') list($fields, $stories) = $this->loadModel('workflowfield')->appendDataFromFlow($fields, $stories);
-
- $this->post->set('fields', $fields);
- $this->post->set('rows', $stories);
- $this->post->set('kind', 'story');
- $this->fetch('file', 'export2' . $this->post->fileType, $_POST);
+ $this->post->set('rows', $this->getExportStorys($executionID, $orderBy));
+ $this->fetch('port', 'export', 'model=story');
}
$fileName = $type == 'requirement' ? $this->lang->URCommon : $this->lang->SRCommon;
@@ -2719,6 +2469,200 @@ class story extends control
$this->display();
}
+ /**
+ * Get export storys .
+ *
+ * @param int $executionID
+ * @param string $orderBy
+ * @access public
+ * @return void
+ */
+ public function getExportStorys($executionID, $orderBy = 'id_desc')
+ {
+ $this->loadModel('file');
+ $this->loadModel('branch');
+ $storyLang = $this->lang->story;
+ $storyConfig = $this->config->story;
+
+ /* Create field lists. */
+ $fields = $this->post->exportFields ? $this->post->exportFields : explode(',', $storyConfig->list->exportFields);
+ foreach($fields as $key => $fieldName)
+ {
+ $fieldName = trim($fieldName);
+ $fields[$fieldName] = isset($storyLang->$fieldName) ? $storyLang->$fieldName : $fieldName;
+ unset($fields[$key]);
+ }
+
+ /* Get stories. */
+ $stories = array();
+ if($this->session->storyOnlyCondition)
+ {
+ if($this->post->exportType == 'selected')
+ {
+ $stories = $this->dao->select('id,title,linkStories,childStories,parent,mailto,reviewedBy')->from(TABLE_STORY)->where('id')->in($this->cookie->checkedItem)->orderBy($orderBy)->fetchAll('id');
+ }
+ else
+ {
+ $stories = $this->dao->select('id,title,linkStories,childStories,parent,mailto,reviewedBy')->from(TABLE_STORY)->where($this->session->storyQueryCondition)->orderBy($orderBy)->fetchAll('id');
+ }
+ }
+ else
+ {
+ $field = $executionID ? 't2.id' : 't1.id';
+ if($this->post->exportType == 'selected')
+ {
+ $stmt = $this->dbh->query("SELECT * FROM " . TABLE_STORY . "WHERE `id` IN({$this->cookie->checkedItem})" . " ORDER BY " . strtr($orderBy, '_', ' '));
+ }
+ else
+ {
+ $stmt = $this->dbh->query($this->session->storyQueryCondition . " ORDER BY " . strtr($orderBy, '_', ' '));
+ }
+ while($row = $stmt->fetch()) $stories[$row->id] = $row;
+ }
+ $storyIdList = array_keys($stories);
+
+ if($stories)
+ {
+ $children = array();
+ foreach($stories as $story)
+ {
+ if($story->parent > 0 and isset($stories[$story->parent]))
+ {
+ $children[$story->parent][$story->id] = $story;
+ unset($stories[$story->id]);
+ }
+ }
+
+ if(!empty($children))
+ {
+ $reorderStories = array();
+ foreach($stories as $story)
+ {
+ $reorderStories[$story->id] = $story;
+ if(isset($children[$story->id]))
+ {
+ foreach($children[$story->id] as $childrenID => $childrenStory)
+ {
+ $reorderStories[$childrenID] = $childrenStory;
+ }
+ }
+ unset($stories[$story->id]);
+ }
+ $stories = $reorderStories;
+ }
+ }
+
+ /* Get users, products and relations. */
+ $users = $this->loadModel('user')->getPairs('noletter');
+ $products = $this->product->getPairs('nocode');
+ $relatedStoryIds = array();
+ foreach($stories as $story)
+ {
+ $relatedStoryIds[$story->id] = $story->id;
+ }
+
+
+ $storyTasks = $this->loadModel('task')->getStoryTaskCounts($relatedStoryIds);
+ $storyBugs = $this->loadModel('bug')->getStoryBugCounts($relatedStoryIds);
+ $storyCases = $this->loadModel('testcase')->getStoryCaseCounts($relatedStoryIds);
+
+ /* Get related objects title or names. */
+ $relatedSpecs = $this->dao->select('*')->from(TABLE_STORYSPEC)->where('`story`')->in($storyIdList)->orderBy('version desc')->fetchGroup('story');
+
+ foreach($stories as $story)
+ {
+ $story->spec = '';
+ $story->verify = '';
+ if(isset($relatedSpecs[$story->id]))
+ {
+ $storySpec = $relatedSpecs[$story->id][0];
+ $story->title = $storySpec->title;
+ $story->spec = $storySpec->spec;
+ $story->verify = $storySpec->verify;
+ }
+
+ if($this->post->fileType == 'csv')
+ {
+ $story->spec = htmlspecialchars_decode($story->spec);
+ $story->spec = str_replace("
", "\n", $story->spec);
+ $story->spec = str_replace('"', '""', $story->spec);
+ $story->spec = str_replace(' ', ' ', $story->spec);
+
+ $story->verify = htmlspecialchars_decode($story->verify);
+ $story->verify = str_replace("
", "\n", $story->verify);
+ $story->verify = str_replace('"', '""', $story->verify);
+ $story->verify = str_replace(' ', ' ', $story->verify);
+ }
+ /* fill some field with useful value. */
+
+ if(isset($storyTasks[$story->id])) $story->taskCountAB = $storyTasks[$story->id];
+ if(isset($storyBugs[$story->id])) $story->bugCountAB = $storyBugs[$story->id];
+ if(isset($storyCases[$story->id])) $story->caseCountAB = $storyCases[$story->id];
+
+ if($story->linkStories)
+ {
+ $tmpLinkStories = array();
+ $linkStoriesIdList = explode(',', $story->linkStories);
+ foreach($linkStoriesIdList as $linkStoryID)
+ {
+ $linkStoryID = trim($linkStoryID);
+ $tmpLinkStories[] = isset($relatedStories[$linkStoryID]) ? $relatedStories[$linkStoryID] : $linkStoryID;
+ }
+ $story->linkStories = join("; \n", $tmpLinkStories);
+ }
+
+ if($story->childStories)
+ {
+ $tmpChildStories = array();
+ $childStoriesIdList = explode(',', $story->childStories);
+ foreach($childStoriesIdList as $childStoryID)
+ {
+ if(empty($childStoryID)) continue;
+
+ $childStoryID = trim($childStoryID);
+ $tmpChildStories[] = isset($relatedStories[$childStoryID]) ? $relatedStories[$childStoryID] : $childStoryID;
+ }
+ $story->childStories = join("; \n", $tmpChildStories);
+ }
+
+ /* Set related files. */
+ $story->files = '';
+ if(isset($relatedFiles[$story->id]))
+ {
+ foreach($relatedFiles[$story->id] as $file)
+ {
+ $fileURL = common::getSysURL() . helper::createLink('file', 'download', "fileID=$file->id");
+ $story->files .= html::a($fileURL, $file->title, '_blank') . '
';
+ }
+ }
+
+ $story->mailto = trim(trim($story->mailto), ',');
+ $mailtos = explode(',', $story->mailto);
+ $story->mailto = '';
+ foreach($mailtos as $mailto)
+ {
+ $mailto = trim($mailto);
+ if(isset($users[$mailto])) $story->mailto .= $users[$mailto] . ',';
+ }
+ $story->mailto = rtrim($story->mailto, ',');
+
+ $story->reviewedBy = trim(trim($story->reviewedBy), ',');
+ $reviewedBys = explode(',', $story->reviewedBy);
+ $story->reviewedBy = '';
+ foreach($reviewedBys as $reviewedBy)
+ {
+ $reviewedBy = trim($reviewedBy);
+ if(isset($users[$reviewedBy])) $story->reviewedBy .= $users[$reviewedBy] . ',';
+ }
+ $story->reviewedBy = rtrim($story->reviewedBy, ',');
+
+ /* Set child story title. */
+ if($story->parent > 0 && strpos($story->title, htmlentities('>', ENT_COMPAT | ENT_HTML401, 'UTF-8')) !== 0) $story->title = '>' . $story->title;
+ }
+
+ return $stories;
+ }
+
/**
* AJAX: get stories of a user in html select.
*
diff --git a/module/testcase/config.php b/module/testcase/config.php
index 8e4b5afa1d..a2013331e4 100644
--- a/module/testcase/config.php
+++ b/module/testcase/config.php
@@ -25,7 +25,7 @@ $config->testcase->exportFields = '
$config->testcase->fieldList['product']['title'] = 'product';
$config->testcase->fieldList['product']['control'] = 'hidden';
-$config->testcase->fieldList['product']['dataSource'] = array('module' => 'port', 'method' => 'getRelatedObjects', 'params' => 'testcase&product&id,name');
+$config->testcase->fieldList['product']['dataSource'] = array('module' => 'port', 'method' => 'getRelatedObjects', 'params' => 'testcase&product&id,name');
$config->testcase->fieldList['branch']['title'] = 'branch';
$config->testcase->fieldList['branch']['dataSource'] = array('module' => 'port', 'method' => 'getRelatedObjects', 'params' => 'testcase&branch&id,name');