From 5579ce6db4cc27bc5496af0ee4fac2c156dddefc Mon Sep 17 00:00:00 2001 From: leiyong <1549684884@qq.com> Date: Sat, 20 Feb 2021 10:58:08 +0800 Subject: [PATCH] * Finish task#36079. --- module/project/control.php | 16 +++++++++------- module/project/model.php | 10 ++++++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/module/project/control.php b/module/project/control.php index 06e6d1395b..a5a5f9e462 100644 --- a/module/project/control.php +++ b/module/project/control.php @@ -117,17 +117,11 @@ class project extends control if(!$projectID) $this->locate($this->createLink('program', 'PRJbrowse')); setCookie("lastPRJ", $projectID, $this->config->cookieLife, $this->config->webRoot, '', false, true); - /* Save the recently five executions visited in the cookie. */ - $recentExecutions = $this->cookie->recentExecutions ? explode('join', $this->cookie->recentExecutions) : array(); - array_unshift($recentExecutions, $executionID); - $recentExecutions = array_unique($recentExecutions); - $recentExecutions = array_slice($recentExecutions, 0, 5); - setcookie("recentExecutions", implode('join', $recentExecutions), $this->config->cookieLife, $this->config->webRoot, '', false, true); - $this->loadModel('tree'); $this->loadModel('search'); $this->loadModel('task'); $this->loadModel('datatable'); + $this->loadModel('setting'); if(common::hasPriv('project', 'create')) $this->lang->TRActions = html::a($this->createLink('project', 'create', ''), " " . $this->lang->project->create, '', "class='btn btn-primary'"); @@ -140,6 +134,14 @@ class project extends control $products = $this->loadModel('product')->getProductPairsByProject($executionID); setcookie('preProjectID', $executionID, $this->config->cookieLife, $this->config->webRoot, '', false, true); + /* Save the recently five executions visited in the cookie. */ + $recentExecutions = isset($this->config->project->recentExecutions) ? explode(',', $this->config->project->recentExecutions) : array(); + array_unshift($recentExecutions, $executionID); + $recentExecutions = array_unique($recentExecutions); + $recentExecutions = array_slice($recentExecutions, 0, 5); + $this->setting->setItem($this->app->user->account . 'common.project.recentExecutions', implode(',', $recentExecutions)); + $this->setting->setItem($this->app->user->account . 'common.project.lastExecution', $executionID); + if($this->cookie->preProjectID != $executionID) { $_COOKIE['moduleBrowseParam'] = $_COOKIE['productBrowseParam'] = 0; diff --git a/module/project/model.php b/module/project/model.php index bc7c3ddd8b..3ce014e86d 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -276,12 +276,18 @@ class projectModel extends model */ public function saveState($executionID, $executions) { + /* When the cookie and session do not exist, get it from the database. */ + if(empty($executionID) && isset($this->config->project->lastExecution) && isset($executions[$this->config->project->lastExecution])) + { + $this->session->set('project', $this->config->project->lastExecution); + return $this->session->project; + } + if($executionID > 0) $this->session->set('project', (int)$executionID); if($executionID == 0 and $this->cookie->lastProject) { /* Project link is project-task. */ $executionID = (int)$this->cookie->lastProject; - $executions = $this->getExecutionPairs($this->session->PRJ); $executionID = in_array($executionID, array_keys($executions)) ? $executionID : key($executions); $this->session->set('project', $executionID); } @@ -3608,7 +3614,7 @@ class projectModel extends model $projectPairs = $this->loadModel('program')->getPRJPairsByIdList($projectIdList); $productPairs = $this->getStageLinkProductPairs($stageIdList); - $recentExecutions = explode('join', $this->cookie->recentExecutions); + $recentExecutions = isset($this->config->project->recentExecutions) ? explode(',', $this->config->project->recentExecutions) : array(); $allExecution = array('recent' => array(), 'mine' => array()); foreach($executions as $execution) {