From 7b5e252aa1744db546001113b8e56d8db2f55eee Mon Sep 17 00:00:00 2001 From: hujunqing Date: Fri, 14 Nov 2025 07:43:21 +0000 Subject: [PATCH] Test code for Zai model. --- module/zai/model.php | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/module/zai/model.php b/module/zai/model.php index 787b6f1d47..90b7c4dc42 100644 --- a/module/zai/model.php +++ b/module/zai/model.php @@ -1771,4 +1771,51 @@ class zaiModel extends model return $markdown; } + + /** + * 将 OPPORTUNITY 对象转换为 Markdown。 + * Convert opportunity object to Markdown format. + * + * @access public + * @param object $opportunity + * @param array|null $langData + * @return array + */ + public static function convertOpportunityToMarkdown($opportunity, ?array $langData = null): array + { + $langData = is_array($langData) ? $langData : array(); + + $id = $opportunity->id ?? 0; + $title = trim((string)($opportunity->name ?? '')); + + $typeName = isset($langData['common']) ? $langData['common'] : ''; + $header = trim(($typeName !== '' ? "{$typeName} " : '') . "#$id $title"); + if($header === '') $header = "#$id $title"; + + $markdown = array('id' => $id, 'title' => $header); + $content = array(); + $content[] = "# {$header}\n"; + + $sectionBasic = static::getSectionLabel($langData, 'basic'); + if($sectionBasic !== '') $content[] = "## {$sectionBasic}\n"; + + $fieldPairs = static::collectFieldPairs('opportunity', $langData, $opportunity); + static::appendFieldList($content, $langData, $fieldPairs); + + static::appendDetailSection($content, $langData, 'desc', $opportunity->desc ?? null); + static::appendDetailSection($content, $langData, 'prevention', $opportunity->prevention ?? null); + + $markdown['content'] = implode("\n", $content); + $markdown['attrs'] = array( + 'status' => $opportunity->status ?? '', + 'benefit' => $opportunity->benefit ?? ($opportunity->impact ?? ''), + 'chance' => $opportunity->chance ?? '', + 'type' => $opportunity->type ?? '', + 'strategy' => $opportunity->strategy ?? '', + 'assignedTo' => $opportunity->assignedTo ?? '', + 'project' => $opportunity->project ?? '', + ); + + return $markdown; + } }