diff --git a/module/doc/control.php b/module/doc/control.php index 6f6d662d8d..9aab232af3 100755 --- a/module/doc/control.php +++ b/module/doc/control.php @@ -2517,6 +2517,40 @@ class doc extends control */ public function manageScope() { + $scopePairs = $this->doc->getTemplateScopePairs(); + + if(!empty($_POST)) + { + $scopes = $this->post->scopes; + + $oldScopes = $newScopes = array(); + foreach($scopes as $id => $name) + { + if(strpos((string)$id, 'id') !== false) + { + $scopeID = str_replace('id', '', $id); + $oldScopes[$scopeID] = $name; + } + else + { + $newScopes[$id] = $name; + } + } + + $deletedScopes = array_diff_key($scopePairs, $oldScopes); + if(!empty($deletedScopes)) $this->doc->deleteTemplateScopes($deletedScopes); + if(dao::isError()) return $this->sendError(array('message' => dao::getError())); + + if(!empty($oldScopes)) $this->doc->updateTemplateScopes($oldScopes); + if(dao::isError()) return $this->sendError(array('message' => dao::getError())); + + if(!empty($newScopes)) $this->doc->insertTemplateScopes($newScopes); + if(dao::isError()) return $this->sendError(array('message' => dao::getError())); + + return $this->sendSuccess(array('closeModal' => true)); + } + + $this->view->scopePairs = $scopePairs; $this->display(); } } diff --git a/module/doc/model.php b/module/doc/model.php index ab06b6d0a5..1f9ef40bd3 100644 --- a/module/doc/model.php +++ b/module/doc/model.php @@ -4426,4 +4426,70 @@ class docModel extends model return $items; } + + /** + * 获取文档模板的范围。 + * Get the scope of template. + * + * @access public + * @return array + */ + public function getTemplateScopePairs() + { + return $this->dao->select('id,name')->from(TABLE_DOCLIB)->where('type')->eq('template')->andWhere('vision')->eq($this->config->vision)->fetchPairs('id'); + } + + /** + * 更新模板范围。 + * Update the scope of template. + * + * @param array scopeList + * @access public + * @return void + */ + public function updateTemplateScopes(array $scopeList = array()) + { + foreach($scopeList as $id => $name) + { + $this->dao->update(TABLE_DOCLIB)->set('name')->eq($name)->where('id')->eq($id)->andWhere('vision')->eq($this->config->vision)->exec(); + } + } + + /** + * 插入模板范围。 + * Insert the scope of template. + * + * @param array scopeList + * @access public + * @return void + */ + public function insertTemplateScopes(array $scopeList = array()) + { + foreach($scopeList as $name) + { + if(empty($name)) continue; + + $scope = new stdClass(); + $scope->name = $name; + $scope->type = 'template'; + $scope->main = '0'; + $scope->vision = $this->config->vision; + $scope->addedBy = $this->app->user->account; + $scope->addedDate = helper::now(); + $this->dao->insert(TABLE_DOCLIB)->data($scope)->exec(); + } + } + + /** + * 删除模板范围。 + * Delete the scope of template. + * + * @param array scopeList + * @access public + * @return void + */ + public function deleteTemplateScopes(array $scopeList = array()) + { + $this->dao->delete()->from(TABLE_DOCLIB)->where('id')->in(array_keys($scopeList))->exec(); + } } diff --git a/module/doc/ui/managescope.html.php b/module/doc/ui/managescope.html.php index d15db1c35a..3a6ab712c7 100644 --- a/module/doc/ui/managescope.html.php +++ b/module/doc/ui/managescope.html.php @@ -9,3 +9,25 @@ declare(strict_types=1); * @link https://www.zentao.net */ namespace zin; + +modalHeader(set::title($lang->docTemplate->manageScope), set::titleClass('text-lg font-bold')); + +$scopeItems = array(); +$scopeItems[] = array('name' => 'scopes'); + +$dataItems = array(); +foreach($scopePairs as $scopeID => $scopeName) +{ + $item = new stdClass(); + $item->id = 'id' . $scopeID; + $item->scopes = $scopeName; + $dataItems[] = $item; +} + +formBatchPanel +( + set::items($scopeItems), + set::data($dataItems), + set::minRows(6), + set::actionsText('') +);