ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilAssSelfAssessmentQuestionFormatter.php
Go to the documentation of this file.
1 <?php
2 
23 {
29  public function format($string): string
30  {
31  $string = $this->handleLineBreaks($string);
32  $string = ilRTE::_replaceMediaObjectImageSrc($string, 1);
33  $string = ilRTE::replaceLatexSpan($string);
34  $string = str_replace("</li><br />", "</li>", $string);
35  $string = str_replace("</li><br>", "</li>", $string);
36  $string = str_replace('{', '&#123;', $string);
37  $string = str_replace('}', '&#125;', $string);
38 
39  return $string;
40  }
41 
46  protected function handleLineBreaks($string): string
47  {
48  if (!ilUtil::isHTML($string)) {
49  $string = nl2br($string);
50  }
51 
52  return $string;
53  }
54 
59  protected function stripHtmlExceptSelfAssessmentTags($string): string
60  {
61  $tags = self::getSelfAssessmentTags();
62 
63  $tstr = "";
64 
65  foreach ($tags as $t) {
66  $tstr .= "<" . $t . ">";
67  }
68 
69  $string = ilUtil::secureString($string, true, $tstr);
70 
71  return $string;
72  }
73 
78  public function migrateToLmContent($string): string
79  {
80  $string = ilRTE::replaceLatexSpan($string);
81  $string = $this->stripHtmlExceptSelfAssessmentTags($string);
82  return $string;
83  }
84 
88  public static function prepareQuestionForLearningModule(assQuestion $question): void
89  {
90  $question->migrateContentForLearningModule(new self());
91  }
92 
97  public static function getSelfAssessmentTags(): array
98  {
99  // set tags we allow in self assessment mode
100  $st = ilUtil::getSecureTags();
101 
102  $not_supported = ['img'];
103  $tags = ['br', 'table', 'td', 'tr', 'th'] + array_diff($st, $not_supported);
104 
105  return $tags;
106  }
107 }
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
static getSelfAssessmentTags()
Get tags allowed in question tags in self assessment mode.
migrateContentForLearningModule(ilAssSelfAssessmentMigrator $migrator)
format($string)
Original code copied from ::formatSAQuestion (author: akill)
static isHTML(string $a_text)
Checks if a given string contains HTML or not.
static secureString(string $a_str, bool $a_strip_html=true, string $a_allow="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getSecureTags()
static replaceLatexSpan(string $text)
Replace the latex delimiters used by the rich text editor Unfortunately these can&#39;t be processed by M...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...