From 1d1ee42f14ece802b5df57d11c5afb4cd7abf9d2 Mon Sep 17 00:00:00 2001 From: sunguangming Date: Thu, 29 May 2025 07:09:34 +0000 Subject: [PATCH] * [dao] auto filter tpl. --- lib/base/dao/dao.class.php | 28 ++++++++++++++-------------- module/action/model.php | 6 +++--- module/doc/model.php | 2 +- module/execution/model.php | 5 ++--- module/my/model.php | 2 +- module/pivot/tao.php | 2 +- module/product/model.php | 4 ++-- module/product/tao.php | 4 ++-- module/program/model.php | 2 +- module/project/control.php | 3 +-- module/project/model.php | 8 +++++--- 11 files changed, 33 insertions(+), 33 deletions(-) diff --git a/lib/base/dao/dao.class.php b/lib/base/dao/dao.class.php index f0e6ab0ecf..c1d1b289ad 100644 --- a/lib/base/dao/dao.class.php +++ b/lib/base/dao/dao.class.php @@ -164,13 +164,13 @@ class baseDAO public $autoLang; /** - * 是否自动增加isTpl条件。 - * If auto add isTpl statement. + * 是否自动过滤模板数据。 + * If auto filter template data. * * @var bool * @access public */ - public $autoTpl; + static public $filterTpl = true; /** * 上一次插入的数据id。 @@ -311,16 +311,16 @@ class baseDAO } /** - * 设置autoTpl项。 - * Set autoTpl item. + * 设置是否过滤模板数据。 + * Set if filter template data. * - * @param bool $autoTpl + * @param bool $filterTpl * @access public * @return void */ - public function setAutoTpl($autoTpl) + public function filterTpl($filterTpl) { - $this->autoTpl = $autoTpl; + dao::$filterTpl = $filterTpl; return $this; } @@ -339,7 +339,7 @@ class baseDAO $this->setMode(''); $this->setMethod(''); $this->setAutoLang(isset($this->config->framework->autoLang) and $this->config->framework->autoLang); - $this->setAutoTpl(true); + $this->filterTpl(true); } //-----根据请求的方式,调用sql类相应的方法(Call according method of sql class by query method. -----// @@ -741,7 +741,6 @@ class baseDAO { $this->setTable($table); if($this->mode == 'raw') $this->sqlobj->from($table); - if((strpos($table, "`{$this->config->db->prefix}project`") !== false || strpos($table, "`{$this->config->db->prefix}task`") !== false) && defined('AUTOTPL')) $this->autoTpl = AUTOTPL; return $this; } @@ -845,11 +844,10 @@ class baseDAO * 处理sql语句,替换表和字段。 * Process the sql, replace the table, fields. * - * @param string $filterTpl * @access public * @return string the sql string after process. */ - public function processSQL($filterTpl = true) + public function processSQL() { $sql = $this->sqlobj->get(); @@ -884,7 +882,7 @@ class baseDAO $sql .= '(`' . implode('`,`', array_keys($values)) . '`)' . ' VALUES(' . implode(',', $values) . ')'; } - elseif($this->method == 'select' && $filterTpl && $this->autoTpl) + elseif($this->method == 'select' && dao::$filterTpl) { /* 过滤模板类型的数据 */ foreach(array('project', 'task') as $table) @@ -1294,7 +1292,9 @@ class baseDAO */ public function fetch($field = '') { - $sql = $this->processSQL(false); + dao::$filterTpl = false; // 获取单个记录时,不过滤模板数据。 + + $sql = $this->processSQL(); $key = $this->createCacheKey('fetch', md5($sql)); $result = $this->getCache($key); if($result === self::CACHE_MISS) diff --git a/module/action/model.php b/module/action/model.php index b445212d24..7f11a290df 100755 --- a/module/action/model.php +++ b/module/action/model.php @@ -2169,7 +2169,7 @@ class actionModel extends model } elseif(strpos(",{$this->config->action->needGetProjectType},", ",{$objectType},") !== false || $objectType == 'project' || $objectType == 'execution') { - $objectInfo = $this->dao->select("id, project, {$field} AS name")->from($table)->where('id')->in($objectIdList)->setAutoTpl(false)->orderBy('id_asc')->fetchAll(); + $objectInfo = $this->dao->select("id, project, {$field} AS name")->from($table)->where('id')->in($objectIdList)->filterTpl(false)->orderBy('id_asc')->fetchAll(); foreach($objectInfo as $object) { $objectName[$object->id] = $objectType == 'gapanalysis' ? zget($users, $object->name) : $object->name; // Get user realname if objectType is gapanalysis. @@ -2180,7 +2180,7 @@ class actionModel extends model { if($objectType == 'team') $table = TABLE_PROJECT; $objectField = $objectType == 'story' ? 'id,title,type' : 'id,team AS title,type'; - $objectInfo = $this->dao->select($objectField)->from($table)->where('id')->in($objectIdList)->setAutoTpl(false)->orderBy('id_asc')->fetchAll(); + $objectInfo = $this->dao->select($objectField)->from($table)->where('id')->in($objectIdList)->filterTpl(false)->orderBy('id_asc')->fetchAll(); foreach($objectInfo as $object) { $objectName[$object->id] = $object->title; @@ -2200,7 +2200,7 @@ class actionModel extends model } else { - $objectName = $this->dao->select("id, {$field} AS name")->from($table)->where('id')->in($objectIdList)->setAutoTpl(false)->orderBy('id_asc')->fetchPairs(); + $objectName = $this->dao->select("id, {$field} AS name")->from($table)->where('id')->in($objectIdList)->filterTpl(false)->orderBy('id_asc')->fetchPairs(); } return array($objectName, $relatedProject, $requirements, $epics); } diff --git a/module/doc/model.php b/module/doc/model.php index 28f7146cf2..ec02f17058 100644 --- a/module/doc/model.php +++ b/module/doc/model.php @@ -1411,7 +1411,7 @@ class docModel extends model } if($type == 'project') { - $projects = $this->loadModel('project')->getListByCurrentUser(); + $projects = $this->loadModel('project')->getListByCurrentUser('*', false); $involvedProjects = $this->project->getInvolvedListByCurrentUser(); $spaceID = $this->project->checkAccess($spaceID, $projects); diff --git a/module/execution/model.php b/module/execution/model.php index d25e4c7f64..368834a044 100755 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -147,7 +147,7 @@ class executionModel extends model /* 模板执行过滤部分导航菜单。 */ if(!empty($execution->isTpl)) { - define('AUTOTPL', false); + dao::$filterTpl = false; /* 模板执行不显示1.5级导航。 */ $this->config->hasDropmenuApps = array_diff($this->config->hasDropmenuApps, array('project', 'execution')); @@ -590,8 +590,7 @@ class executionModel extends model public function batchChangeStatus(array $executionIdList, string $status): array { /* Sort the IDs, the child stage comes first, and the parent stage follows. */ - if(!defined('AUTOTPL')) define('AUTOTPL', false); - $executionList = $this->dao->select('id,name,status,grade,deliverable')->from(TABLE_EXECUTION)->where('id')->in($executionIdList)->orderBy('grade_desc')->fetchAll('id'); + $executionList = $this->dao->select('id,name,status,grade,deliverable')->from(TABLE_EXECUTION)->where('id')->in($executionIdList)->filterTpl(false)->orderBy('grade_desc')->fetchAll('id'); $this->loadModel('programplan'); $message = array('byChild' => '', 'byDeliverable' => ''); diff --git a/module/my/model.php b/module/my/model.php index 65a24a1280..1d868d3767 100644 --- a/module/my/model.php +++ b/module/my/model.php @@ -1511,7 +1511,7 @@ class myModel extends model ->beginIF($type == 'undone')->andWhere('t1.status')->eq('normal')->fi() ->beginIF($type == 'ownbyme')->andWhere('t1.PO')->eq($this->app->user->account)->fi() ->beginIF(!$this->app->user->admin)->andWhere('t1.id')->in($this->app->user->view->products)->fi() - ->setAutoTpl(false) + ->filterTpl(false) ->orderBy('t1.order_asc') ->fetchAll('id'); diff --git a/module/pivot/tao.php b/module/pivot/tao.php index f2222a8246..7633b7a363 100644 --- a/module/pivot/tao.php +++ b/module/pivot/tao.php @@ -79,7 +79,7 @@ class pivotTao extends pivotModel ->beginIF($productID)->andWhere('t1.id')->eq($productID)->fi() ->beginIF($productStatus)->andWhere('t1.status')->eq($productStatus)->fi() ->beginIF($productType)->andWhere('t1.type')->eq($productType)->fi() - ->setAutoTpl(false) + ->filterTpl(false) ->orderBy('t2.order_asc, t1.line_desc, t1.order_asc') ->fetchAll('id'); } diff --git a/module/product/model.php b/module/product/model.php index 0f143b857e..f0cd44d2bc 100755 --- a/module/product/model.php +++ b/module/product/model.php @@ -90,7 +90,7 @@ class productModel extends model ->andWhere('t1.shadow')->eq(0) ->beginIF(!$this->app->user->admin)->andWhere('t1.id')->in($this->app->user->view->products)->fi() ->beginIF($this->config->vision != 'or')->andWhere("FIND_IN_SET('{$this->config->vision}', t1.vision)")->fi() - ->setAutoTpl(false) + ->filterTpl(false) ->orderBy('t1.order_asc') ->fetchAll('id'); } @@ -1654,7 +1654,7 @@ class productModel extends model ->andWhere("FIND_IN_SET('{$this->app->user->account}', t1.reviewers)") ->andWhere('t1.reviewStatus')->eq('doing') ->fi() - ->setAutoTpl(false) + ->filterTpl(false) ->orderBy("{$programOrder}t1.line_desc, t1.order_asc") ->beginIF($limit > 0)->limit($limit)->fi() ->fetchAll('id'); diff --git a/module/product/tao.php b/module/product/tao.php index 3ee8d2f95e..714b6f7eb5 100644 --- a/module/product/tao.php +++ b/module/product/tao.php @@ -65,7 +65,7 @@ class productTao extends productModel ->beginIF(!$this->app->user->admin && $this->config->vision != 'lite' && $this->app->rawModule != 'repo')->andWhere('t1.id')->in($this->app->user->view->products)->fi() ->markRight(1) ->beginIF($append)->orWhere('(t1.id')->in($append)->markRight(1)->fi() - ->setAutoTpl(false) + ->filterTpl(false) ->orderBy("isClosed,t2.order_asc,t1.line_desc,t1.order_asc") ->fetchPairs('id', 'name'); } @@ -151,7 +151,7 @@ class productTao extends productModel return $this->dao->select('t1.*')->from(TABLE_PRODUCT)->alias('t1') ->leftJoin(TABLE_PROGRAM)->alias('t2')->on('t1.program = t2.id') ->where('t1.id')->in($productIDs) - ->setAutoTpl(false) + ->filterTpl(false) ->orderBy('t2.order_asc, t1.line_desc, t1.order_asc') ->page($pager) ->fetchAll('id'); diff --git a/module/program/model.php b/module/program/model.php index 89f2b90e1a..ae746cc2fd 100644 --- a/module/program/model.php +++ b/module/program/model.php @@ -110,7 +110,7 @@ class programModel extends model ->beginIF($mode == 'assign')->andWhere('t1.program')->eq($programID)->fi() ->beginIF(strpos($status, 'noclosed') !== false)->andWhere('t1.status')->ne('closed')->fi() ->beginIF(!$this->app->user->admin)->andWhere('t1.id')->in($views)->fi() - ->setAutoTpl(false) + ->filterTpl(false) ->orderBy('t2.order_asc,t1.line_desc,t1.order_asc'); if(!$withProgram) return $dao->fetchPairs('id', 'name'); diff --git a/module/project/control.php b/module/project/control.php index 18e0c1d80a..fe76dbbec2 100755 --- a/module/project/control.php +++ b/module/project/control.php @@ -102,10 +102,9 @@ class project extends control $_COOKIE['showClosed'] = 1; $project = $this->project->fetchByID($projectID); - if(!empty($project->isTpl) && !defined('AUTOTPL')) define('AUTOTPL', false); /* Query user's project and program. */ - $projects = $this->project->getListByCurrentUser(); + $projects = $this->project->getListByCurrentUser('*', !$project->isTpl); $involvedProjects = $this->project->getInvolvedListByCurrentUser(); $programs = $this->loadModel('program')->getPairs(true); diff --git a/module/project/model.php b/module/project/model.php index 07c38eda21..617e5b24e5 100755 --- a/module/project/model.php +++ b/module/project/model.php @@ -47,7 +47,7 @@ class projectModel extends model return $this->dao->select('id, project, type, parent, path, openedBy, PO, PM, QD, RD, acl')->from(TABLE_PROJECT) ->where('acl')->in($acl) ->beginIF($type)->andWhere('type')->in($type)->fi() - ->setAutoTpl(false) + ->filterTpl(false) ->fetchAll('id'); } @@ -69,16 +69,18 @@ class projectModel extends model * Get project list by current user. * * @param string $fields + * @param bool $filterTpl * @access public * @return array */ - public function getListByCurrentUser(string $fields = '*') :array + public function getListByCurrentUser(string $fields = '*', bool $filterTpl = true) :array { return $this->dao->select($fields)->from(TABLE_PROJECT) ->where('type')->eq('project') ->beginIF($this->config->vision)->andWhere('vision')->eq($this->config->vision)->fi() ->andWhere('deleted')->eq(0) ->beginIF(!$this->app->user->admin)->andWhere('id')->in($this->app->user->view->projects)->fi() + ->filterTpl($filterTpl) ->orderBy('order_asc,id_desc') ->fetchAll('id'); } @@ -2295,7 +2297,7 @@ class projectModel extends model if($this->app->getModuleName() == 'repo' || $this->app->getModuleName() == 'mr') $this->loadModel('repo')->setHideMenu($projectID); - if(!empty($project->isTpl)) define('AUTOTPL', false); + if(!empty($project->isTpl)) dao::$filterTpl = false; return $projectID; }