From c61bf7893bed8cc489217085895bb9f57dc22aa9 Mon Sep 17 00:00:00 2001 From: hufangzhou Date: Tue, 4 Apr 2023 10:01:12 +0800 Subject: [PATCH] * Adjust the function to adapt to the new database structure. --- module/group/model.php | 53 +++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/module/group/model.php b/module/group/model.php index f5a9f1792a..5bea0d50c5 100644 --- a/module/group/model.php +++ b/module/group/model.php @@ -1338,9 +1338,10 @@ class groupModel extends model public function getPrivByID($privID, $lang = '') { if(empty($lang)) $lang = $this->app->getClientLang(); - return $this->dao->select('t1.*,t2.name,t2.desc')->from(TABLE_PRIV)->alias('t1') - ->leftJoin(TABLE_PRIVLANG)->alias('t2')->on('t1.id=t2.priv') + return $this->dao->select('t1.*,t2.key,t2.value,t2.desc')->from(TABLE_PRIV)->alias('t1') + ->leftJoin(TABLE_PRIVLANG)->alias('t2')->on('t1.id=t2.objectID') ->where('t1.id')->eq($privID) + ->andWhere('t2.objectType')->eq('priv') ->andWhere('t2.lang')->eq($lang) ->fetch(); } @@ -1354,10 +1355,11 @@ class groupModel extends model */ public function getPrivByIdList($privIdList) { - return $this->dao->select('t1.*,t2.name,t2.desc')->from(TABLE_PRIV)->alias('t1') - ->leftJoin(TABLE_PRIVLANG)->alias('t2')->on('t1.id=t2.priv') + return $this->dao->select('t1.*,t2.key,t2.value,t2.desc')->from(TABLE_PRIV)->alias('t1') + ->leftJoin(TABLE_PRIVLANG)->alias('t2')->on('t1.id=t2.objectID') ->where('t1.id')->in($privIdList) ->andWhere('t2.lang')->eq($this->app->getClientLang()) + ->andWhere('t2.objectType')->eq('priv') ->fetchAll('id'); } @@ -1370,15 +1372,22 @@ class groupModel extends model */ public function getPrivByModule($modules) { - $stmt = $this->dao->select('t1.*,t2.name,t2.desc')->from(TABLE_PRIV)->alias('t1') - ->leftJoin(TABLE_PRIVLANG)->alias('t2')->on('t1.id=t2.priv') - ->where('t1.module')->in($modules) + $moduleIdList = $this->dao->select('id')->from(TABLE_PRIVMANAGER) + ->where('code')->in($modules) + ->andWhere('`type`')->eq('module') + ->fetchAll('id'); + + $stmt = $this->dao->select('t1.*,t3.`parent` as moduleID,t2.`key`,t2.value,t2.`desc`')->from(TABLE_PRIV)->alias('t1') + ->leftJoin(TABLE_PRIVLANG)->alias('t2')->on('t1.id=t2.objectID') + ->leftJoin(TABLE_PRIVMANAGER)->alias('t3')->on('t1.package=t3.id') + ->where('t3.code')->in($modules) ->andWhere('t2.lang')->eq($this->app->getClientLang()) + ->andWhere('t2.objectType')->eq('priv') ->orderBy('`order`') ->query(); $privs = array(); - while($priv = $stmt->fetch()) $privs[$priv->module][$priv->package][$priv->id] = $priv; + while($priv = $stmt->fetch()) $privs[$priv->moduleID][$priv->package][$priv->id] = $priv; return $privs; } @@ -1900,4 +1909,32 @@ class groupModel extends model } return $pairs; } + + /** + * Transform priv lang. + * + * @param array $privs + * @access public + * @return array + */ + public function transformPrivLang($privs) + { + foreach($privs as $privID => $priv) + { + $priv->name = ''; + if(!empty($priv->value)) + { + $priv->name = $priv->value; + } + else + { + list($moduleName, $methodLang) = explode('-', $priv->key); + $this->app->loadLang($moduleName); + + $priv->name = $this->lang->{$moduleName}->$methodLang; + } + } + + return $privs; + } }