ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
RichText.php
Go to the documentation of this file.
1<?php
2
4
8
9class RichText implements IComparable
10{
17
23 public function __construct(?Cell $pCell = null)
24 {
25 // Initialise variables
26 $this->richTextElements = [];
27
28 // Rich-Text string attached to cell?
29 if ($pCell !== null) {
30 // Add cell text and style
31 if ($pCell->getValue() != '') {
32 $objRun = new Run($pCell->getValue());
33 $objRun->setFont(clone $pCell->getWorksheet()->getStyle($pCell->getCoordinate())->getFont());
34 $this->addText($objRun);
35 }
36
37 // Set parent value
38 $pCell->setValueExplicit($this, DataType::TYPE_STRING);
39 }
40 }
41
49 public function addText(ITextElement $pText)
50 {
51 $this->richTextElements[] = $pText;
52
53 return $this;
54 }
55
63 public function createText($pText)
64 {
65 $objText = new TextElement($pText);
66 $this->addText($objText);
67
68 return $objText;
69 }
70
78 public function createTextRun($pText)
79 {
80 $objText = new Run($pText);
81 $this->addText($objText);
82
83 return $objText;
84 }
85
91 public function getPlainText()
92 {
93 // Return value
94 $returnValue = '';
95
96 // Loop through all ITextElements
97 foreach ($this->richTextElements as $text) {
98 $returnValue .= $text->getText();
99 }
100
101 return $returnValue;
102 }
103
109 public function __toString()
110 {
111 return $this->getPlainText();
112 }
113
119 public function getRichTextElements()
120 {
122 }
123
131 public function setRichTextElements(array $textElements)
132 {
133 $this->richTextElements = $textElements;
134
135 return $this;
136 }
137
143 public function getHashCode()
144 {
145 $hashElements = '';
146 foreach ($this->richTextElements as $element) {
147 $hashElements .= $element->getHashCode();
148 }
149
150 return md5(
151 $hashElements .
152 __CLASS__
153 );
154 }
155
159 public function __clone()
160 {
161 $vars = get_object_vars($this);
162 foreach ($vars as $key => $value) {
163 if (is_object($value)) {
164 $this->$key = clone $value;
165 } else {
166 $this->$key = $value;
167 }
168 }
169 }
170}
An exception for terminatinating execution or to throw for unit testing.
setRichTextElements(array $textElements)
Set Rich Text elements.
Definition: RichText.php:131
__construct(?Cell $pCell=null)
Create a new RichText instance.
Definition: RichText.php:23
__clone()
Implement PHP __clone to create a deep clone, not just a shallow copy.
Definition: RichText.php:159
createTextRun($pText)
Create text run.
Definition: RichText.php:78
getRichTextElements()
Get Rich Text elements.
Definition: RichText.php:119
addText(ITextElement $pText)
Add text.
Definition: RichText.php:49
$key
Definition: croninfo.php:18
$text
Definition: errorreport.php:18