From 86dce76a529667edd86e86bbf4df79abb3817ab2 Mon Sep 17 00:00:00 2001 From: xieqiyu Date: Tue, 10 Jun 2025 13:35:06 +0800 Subject: [PATCH] * [task#144512,doing,2h] Add built-in doc template by type. --- module/doc/model.php | 57 ++++++++++++++++++++++++++++++++++++++++ module/upgrade/model.php | 4 +++ 2 files changed, 61 insertions(+) diff --git a/module/doc/model.php b/module/doc/model.php index 38dc0d61cb..00e59cee41 100644 --- a/module/doc/model.php +++ b/module/doc/model.php @@ -4644,4 +4644,61 @@ class docModel extends model return $newTemplateList; } + + /** + * 添加内置文档模板。 + * Add the built-in doc template. + * + * @param array typeList + * @access public + * @return void + */ + public function addBuiltInDocTemplateByType(array $typeList) + { + $rndScopeMaps = $this->loadModel('setting')->getItem('vision=rnd&owner=system&module=doc&key=builtInScopeMaps'); + $rndScopeMaps = json_decode($rndScopeMaps, true); + $projectScopeID = $rndScopeMaps['project']; + $modulePairs = $this->dao->select('short,id')->from(TABLE_MODULE)->where('root')->eq($projectScopeID)->andWhere('type')->eq('docTemplate')->fetchPairs('short'); + + $builtInTemplate = new stdClass(); + $builtInTemplate->lib = $projectScopeID; + $builtInTemplate->type = 'text'; + $builtInTemplate->addedBy = 'system'; + $builtInTemplate->addedDate = helper::now(); + + $templateContent = new stdClass(); + $templateContent->type = 'doc'; + $templateContent->version = 1; + $templateContent->addedBy = 'system'; + $templateContent->addedDate = helper::now(); + + $this->loadModel('action'); + $this->loadModel('upgrade'); + $this->app->loadLang('baseline'); + foreach($typeList as $type) + { + /* 创建与分类同名的内置文档模板。*/ + /* Add the doc template with the same name as the type. */ + $builtInTemplate->module = $modulePairs[$type]; + $builtInTemplate->title = $this->lang->baseline->objectList[$type]; + $builtInTemplate->templateType = $type; + $this->dao->insert(TABLE_DOC)->data($builtInTemplate)->exec(); + $templateID = $this->dao->lastInsertID(); + + /* 获取模板的动态区块。*/ + /* Get the block of doc template. */ + $templateBlock = $this->upgrade->getTemplateBlock($templateID); + $templateHtml = empty($templateBlock) ? '' : "
"; + + /* 添加模板内容。*/ + /* Add the content of doc template. */ + $templateContent->content = $templateHtml; + $templateContent->rawContent = json_encode(array('$migrate' => 'html', '$data' => $templateHtml)); + $templateContent->doc = $templateID; + $templateContent->title = $builtInTemplate->title; + $this->dao->insert(TABLE_DOCCONTENT)->data($templateContent)->exec(); + + $this->action->create('docTemplate', $templateID, 'Created'); + } + } } diff --git a/module/upgrade/model.php b/module/upgrade/model.php index 28a0081798..8ee6acbda0 100644 --- a/module/upgrade/model.php +++ b/module/upgrade/model.php @@ -11228,5 +11228,9 @@ class upgradeModel extends model if(!isset($hasSystemDataTemplateTypes[$type])) $noSystemDataTemplateTypes[] = $type; } if(empty($noSystemDataTemplateTypes)) return; + + /* 根据类型添加内置模板。*/ + /* Add built-in templates based on type. */ + $this->loadModel('doc')->addBuiltInDocTemplateByType($noSystemDataTemplateTypes); } }