ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
Comments.php
Go to the documentation of this file.
1 <?php
37 {
45  public function writeComments(PHPExcel_Worksheet $pWorksheet = null)
46  {
47  // Create XML writer
48  $objWriter = null;
49  if ($this->getParentWriter()->getUseDiskCaching()) {
50  $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
51  } else {
53  }
54 
55  // XML header
56  $objWriter->startDocument('1.0','UTF-8','yes');
57 
58  // Comments cache
59  $comments = $pWorksheet->getComments();
60 
61  // Authors cache
62  $authors = array();
63  $authorId = 0;
64  foreach ($comments as $comment) {
65  if (!isset($authors[$comment->getAuthor()])) {
66  $authors[$comment->getAuthor()] = $authorId++;
67  }
68  }
69 
70  // comments
71  $objWriter->startElement('comments');
72  $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main');
73 
74  // Loop through authors
75  $objWriter->startElement('authors');
76  foreach ($authors as $author => $index) {
77  $objWriter->writeElement('author', $author);
78  }
79  $objWriter->endElement();
80 
81  // Loop through comments
82  $objWriter->startElement('commentList');
83  foreach ($comments as $key => $value) {
84  $this->_writeComment($objWriter, $key, $value, $authors);
85  }
86  $objWriter->endElement();
87 
88  $objWriter->endElement();
89 
90  // Return
91  return $objWriter->getData();
92  }
93 
103  public function _writeComment(PHPExcel_Shared_XMLWriter $objWriter = null, $pCellReference = 'A1', PHPExcel_Comment $pComment = null, $pAuthors = null)
104  {
105  // comment
106  $objWriter->startElement('comment');
107  $objWriter->writeAttribute('ref', $pCellReference);
108  $objWriter->writeAttribute('authorId', $pAuthors[$pComment->getAuthor()]);
109 
110  // text
111  $objWriter->startElement('text');
112  $this->getParentWriter()->getWriterPart('stringtable')->writeRichText($objWriter, $pComment->getText());
113  $objWriter->endElement();
114 
115  $objWriter->endElement();
116  }
117 
125  public function writeVMLComments(PHPExcel_Worksheet $pWorksheet = null)
126  {
127  // Create XML writer
128  $objWriter = null;
129  if ($this->getParentWriter()->getUseDiskCaching()) {
130  $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
131  } else {
133  }
134 
135  // XML header
136  $objWriter->startDocument('1.0','UTF-8','yes');
137 
138  // Comments cache
139  $comments = $pWorksheet->getComments();
140 
141  // xml
142  $objWriter->startElement('xml');
143  $objWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
144  $objWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
145  $objWriter->writeAttribute('xmlns:x', 'urn:schemas-microsoft-com:office:excel');
146 
147  // o:shapelayout
148  $objWriter->startElement('o:shapelayout');
149  $objWriter->writeAttribute('v:ext', 'edit');
150 
151  // o:idmap
152  $objWriter->startElement('o:idmap');
153  $objWriter->writeAttribute('v:ext', 'edit');
154  $objWriter->writeAttribute('data', '1');
155  $objWriter->endElement();
156 
157  $objWriter->endElement();
158 
159  // v:shapetype
160  $objWriter->startElement('v:shapetype');
161  $objWriter->writeAttribute('id', '_x0000_t202');
162  $objWriter->writeAttribute('coordsize', '21600,21600');
163  $objWriter->writeAttribute('o:spt', '202');
164  $objWriter->writeAttribute('path', 'm,l,21600r21600,l21600,xe');
165 
166  // v:stroke
167  $objWriter->startElement('v:stroke');
168  $objWriter->writeAttribute('joinstyle', 'miter');
169  $objWriter->endElement();
170 
171  // v:path
172  $objWriter->startElement('v:path');
173  $objWriter->writeAttribute('gradientshapeok', 't');
174  $objWriter->writeAttribute('o:connecttype', 'rect');
175  $objWriter->endElement();
176 
177  $objWriter->endElement();
178 
179  // Loop through comments
180  foreach ($comments as $key => $value) {
181  $this->_writeVMLComment($objWriter, $key, $value);
182  }
183 
184  $objWriter->endElement();
185 
186  // Return
187  return $objWriter->getData();
188  }
189 
198  public function _writeVMLComment(PHPExcel_Shared_XMLWriter $objWriter = null, $pCellReference = 'A1', PHPExcel_Comment $pComment = null)
199  {
200  // Metadata
201  list($column, $row) = PHPExcel_Cell::coordinateFromString($pCellReference);
202  $column = PHPExcel_Cell::columnIndexFromString($column);
203  $id = 1024 + $column + $row;
204  $id = substr($id, 0, 4);
205 
206  // v:shape
207  $objWriter->startElement('v:shape');
208  $objWriter->writeAttribute('id', '_x0000_s' . $id);
209  $objWriter->writeAttribute('type', '#_x0000_t202');
210  $objWriter->writeAttribute('style', 'position:absolute;margin-left:' . $pComment->getMarginLeft() . ';margin-top:' . $pComment->getMarginTop() . ';width:' . $pComment->getWidth() . ';height:' . $pComment->getHeight() . ';z-index:1;visibility:' . ($pComment->getVisible() ? 'visible' : 'hidden'));
211  $objWriter->writeAttribute('fillcolor', '#' . $pComment->getFillColor()->getRGB());
212  $objWriter->writeAttribute('o:insetmode', 'auto');
213 
214  // v:fill
215  $objWriter->startElement('v:fill');
216  $objWriter->writeAttribute('color2', '#' . $pComment->getFillColor()->getRGB());
217  $objWriter->endElement();
218 
219  // v:shadow
220  $objWriter->startElement('v:shadow');
221  $objWriter->writeAttribute('on', 't');
222  $objWriter->writeAttribute('color', 'black');
223  $objWriter->writeAttribute('obscured', 't');
224  $objWriter->endElement();
225 
226  // v:path
227  $objWriter->startElement('v:path');
228  $objWriter->writeAttribute('o:connecttype', 'none');
229  $objWriter->endElement();
230 
231  // v:textbox
232  $objWriter->startElement('v:textbox');
233  $objWriter->writeAttribute('style', 'mso-direction-alt:auto');
234 
235  // div
236  $objWriter->startElement('div');
237  $objWriter->writeAttribute('style', 'text-align:left');
238  $objWriter->endElement();
239 
240  $objWriter->endElement();
241 
242  // x:ClientData
243  $objWriter->startElement('x:ClientData');
244  $objWriter->writeAttribute('ObjectType', 'Note');
245 
246  // x:MoveWithCells
247  $objWriter->writeElement('x:MoveWithCells', '');
248 
249  // x:SizeWithCells
250  $objWriter->writeElement('x:SizeWithCells', '');
251 
252  // x:Anchor
253  //$objWriter->writeElement('x:Anchor', $column . ', 15, ' . ($row - 2) . ', 10, ' . ($column + 4) . ', 15, ' . ($row + 5) . ', 18');
254 
255  // x:AutoFill
256  $objWriter->writeElement('x:AutoFill', 'False');
257 
258  // x:Row
259  $objWriter->writeElement('x:Row', ($row - 1));
260 
261  // x:Column
262  $objWriter->writeElement('x:Column', ($column - 1));
263 
264  $objWriter->endElement();
265 
266  $objWriter->endElement();
267  }
268 }