Skip to content

Commit

Permalink
Plugin: AI Helper: Add styles link for header in lp content using Ope…
Browse files Browse the repository at this point in the history
…nAi - refs #4606

Author: @christianbeeznest
  • Loading branch information
christianbeeznest committed Feb 27, 2023
1 parent 95c138c commit 03d246b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion plugin/ai_helper/tool/learnpath.php
Expand Up @@ -4,6 +4,9 @@
/**
Create a learnpath with contents based on existing knowledge.
*/

use Chamilo\CoreBundle\Component\Utils\ChamiloApi;

require_once __DIR__.'/../../../main/inc/global.inc.php';
require_once __DIR__.'/../AiHelperPlugin.php';
require_once api_get_path(SYS_CODE_PATH).'exercise/export/aiken/aiken_classes.php';
Expand Down Expand Up @@ -44,6 +47,13 @@

$lpItems = [];
if (!empty($resultText)) {
$style = api_get_css_asset('bootstrap/dist/css/bootstrap.min.css');
$style .= api_get_css_asset('fontawesome/css/font-awesome.min.css');
$style .= api_get_css(ChamiloApi::getEditorDocStylePath());
$style .= api_get_css_asset('ckeditor/plugins/codesnippet/lib/highlight/styles/default.css');
$style .= api_get_asset('ckeditor/plugins/codesnippet/lib/highlight/highlight.pack.js');
$style .= '<script>hljs.initHighlightingOnLoad();</script>';

$items = explode(',', $resultText);
$position = 1;
foreach ($items as $item) {
Expand All @@ -54,7 +64,13 @@
$messageGetItemContent = 'In the context of "%s", generate a document with HTML tags in "%s" with %d words of content or less, about "%s"';
$promptItem = sprintf($messageGetItemContent, $topic, $courseLanguage, $wordsCount, $title);
$resultContentText = $plugin->openAiGetCompletionText($promptItem, 'learnpath');
$lpItems[$position]['content'] = (!empty($resultContentText) ? trim($resultContentText) : '');
$lpItemContent = (!empty($resultContentText) ? trim($resultContentText) : '');
if (false !== stripos($lpItemContent, '</head>')) {
$lpItemContent = preg_replace("|</head>|i", "\r\n$style\r\n\\0", $lpItemContent);
} else {
$lpItemContent = '<html><head><title>'.trim($title).'</title>'.$style.'</head><body>'.$lpItemContent.'</body></html>';
}
$lpItems[$position]['content'] = $lpItemContent;
$position++;
}
}
Expand Down

0 comments on commit 03d246b

Please sign in to comment.