|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpPresentation\Writer\PowerPoint2007; |
|
4
|
|
|
|
|
5
|
|
|
use PhpOffice\Common\Adapter\Zip\ZipInterface; |
|
6
|
|
|
use PhpOffice\Common\XMLWriter; |
|
7
|
|
|
use PhpOffice\PhpPresentation\Shape\Comment; |
|
8
|
|
|
use PhpOffice\PhpPresentation\Shape\Comment\Author; |
|
9
|
|
|
|
|
10
|
|
|
class CommentAuthors extends AbstractDecoratorWriter |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @return ZipInterface |
|
14
|
|
|
* @throws \Exception |
|
15
|
|
|
*/ |
|
16
|
115 |
|
public function render() |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var Author[] |
|
20
|
|
|
*/ |
|
21
|
115 |
|
$arrayAuthors = array(); |
|
22
|
115 |
|
foreach ($this->getPresentation()->getAllSlides() as $oSlide) { |
|
23
|
115 |
|
foreach ($oSlide->getShapeCollection() as $oShape) { |
|
24
|
88 |
|
if (!($oShape instanceof Comment)) { |
|
25
|
82 |
|
continue; |
|
26
|
|
|
} |
|
27
|
6 |
|
$oAuthor = $oShape->getAuthor(); |
|
28
|
6 |
|
if (!($oAuthor instanceof Author)) { |
|
29
|
2 |
|
continue; |
|
30
|
|
|
} |
|
31
|
4 |
|
if (array_key_exists($oAuthor->getHashCode(), $arrayAuthors)) { |
|
32
|
1 |
|
continue; |
|
33
|
|
|
} |
|
34
|
115 |
|
$arrayAuthors[$oAuthor->getHashCode()] = $oAuthor; |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
115 |
|
if (!empty($arrayAuthors)) { |
|
38
|
4 |
|
$this->getZip()->addFromString('ppt/commentAuthors.xml', $this->writeCommentsAuthors($arrayAuthors)); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
115 |
|
return $this->getZip(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param Author[] $arrayAuthors |
|
46
|
|
|
* @return string |
|
47
|
|
|
*/ |
|
48
|
4 |
|
protected function writeCommentsAuthors($arrayAuthors) |
|
49
|
|
|
{ |
|
50
|
4 |
|
$objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); |
|
51
|
4 |
|
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|
52
|
|
|
|
|
53
|
|
|
// p:cmAuthorLst |
|
54
|
4 |
|
$objWriter->startElement('p:cmAuthorLst'); |
|
55
|
4 |
|
$objWriter->writeAttribute('xmlns:p', 'http://schemas.openxmlformats.org/presentationml/2006/main'); |
|
56
|
|
|
|
|
57
|
4 |
|
$idxAuthor = 0; |
|
58
|
4 |
|
foreach ($arrayAuthors as $oAuthor) { |
|
59
|
4 |
|
$oAuthor->setIndex($idxAuthor++); |
|
60
|
|
|
|
|
61
|
|
|
// p:cmAuthor |
|
62
|
4 |
|
$objWriter->startElement('p:cmAuthor'); |
|
63
|
4 |
|
$objWriter->writeAttribute('id', $oAuthor->getIndex()); |
|
64
|
4 |
|
$objWriter->writeAttribute('name', $oAuthor->getName()); |
|
65
|
4 |
|
$objWriter->writeAttribute('initials', $oAuthor->getInitials()); |
|
66
|
4 |
|
$objWriter->writeAttribute('lastIdx', '2'); |
|
67
|
4 |
|
$objWriter->writeAttribute('clrIdx', 0); |
|
68
|
4 |
|
$objWriter->endElement(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
// ## p:cmAuthorLst |
|
72
|
4 |
|
$objWriter->endElement(); |
|
73
|
|
|
|
|
74
|
4 |
|
return $objWriter->getData(); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|