Skip to content

Commit 1b84fa8

Browse files
committed
Merge pull request #189 from Progi1984/issue116
#116 : Support for Comments
2 parents 9ac06b0 + 85a2e21 commit 1b84fa8

File tree

21 files changed

+993
-22
lines changed

21 files changed

+993
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- PhpOffice\PhpPresentation\Writer\PowerPoint2007 : Move to Design Pattern Decorator - @Progi1984
1010

1111
### Features
12+
- ODPresentation / PowerPoint2007 Writer : Add support for Comment - @Progi1984 GH-116
1213
- ODPresentation Writer : Thumbnail of the presentation - @Progi1984 GH-125
1314
- PowerPoint2007 Writer : Thumbnail of the presentation - @Progi1984 GH-125
1415
- ODPresentation Writer : Add Font Support For Chart Axis - @jrking4 GH-186

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ PHPPresentation is a library written in pure PHP that provides a set of classes
3333
:caption: Shapes
3434

3535
shapes_chart
36+
shapes_comment
3637
shapes_table
3738

3839
Indices and tables

docs/shapes.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ To create a line, use `createLineShape` method of slide.
6464
Chart
6565
-------
6666

67-
The Chart has now :ref:`its own page <shapes_chart>`.
67+
The Chart has now :ref:`its own page <shapes_chart>`.
68+
69+
Comment
70+
-------
71+
72+
The Comment has now :ref:`its own page <shapes_comment>`.
6873

6974
Drawing
7075
-------

docs/shapes_chart.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Example:
1212
$chartShape = $slide->createChartShape();
1313
1414
Parts
15-
-------
15+
-----
1616

1717
Title
1818
^^^^^
@@ -29,7 +29,7 @@ For hiding it, you define its visibility to false.
2929
$oShape->getTitle()->setVisible(false);
3030
3131
Types
32-
-------
32+
-----
3333

3434
Area
3535
^^^^

docs/shapes_comment.rst

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
.. _shapes_chart:
2+
3+
Comments
4+
========
5+
6+
To create a comment, create an object `Comment`.
7+
8+
Example:
9+
10+
.. code-block:: php
11+
12+
use PhpOffice\PhpPresentation\Shape\Comment;
13+
14+
$oComment = new Comment();
15+
$oSlide->addShape($oComment);
16+
17+
You can define text and date with setters.
18+
19+
Example:
20+
21+
.. code-block:: php
22+
23+
use PhpOffice\PhpPresentation\Shape\Comment;
24+
25+
$oComment = new Comment();
26+
$oComment->setText('Text of the Comment');
27+
$oComment->setDate(time());
28+
$oSlide->addShape($oComment);
29+
30+
31+
Author
32+
------
33+
34+
For a comment, you can define the author.
35+
36+
Example:
37+
38+
.. code-block:: php
39+
40+
use PhpOffice\PhpPresentation\Shape\Comment;
41+
use PhpOffice\PhpPresentation\Shape\Comment\Author;
42+
43+
$oAuthor = new Author();
44+
$oComment = new Comment();
45+
$oComment->setAuthor($oAuthor);
46+
$oSlide->addShape($oComment);
47+
48+
You can define name and initials with setters.
49+
50+
Example:
51+
52+
.. code-block:: php
53+
54+
use PhpOffice\PhpPresentation\Shape\Comment;
55+
use PhpOffice\PhpPresentation\Shape\Comment\Author;
56+
57+
$oAuthor = new Author();
58+
$oAuthor->setName('Name of the author');
59+
$oAuthor->setInitals('Nota');
60+
$oComment = new Comment();
61+
$oComment->setAuthor($oAuthor);
62+
$oSlide->addShape($oComment);

samples/Sample_17_Comment.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
include_once 'Sample_Header.php';
4+
5+
use PhpOffice\PhpPresentation\PhpPresentation;
6+
use PhpOffice\PhpPresentation\Slide\Background\Color;
7+
use PhpOffice\PhpPresentation\Style\Color as StyleColor;
8+
use \PhpOffice\PhpPresentation\Slide\Background\Image;
9+
10+
// Create new PHPPresentation object
11+
echo date('H:i:s') . ' Create new PHPPresentation object' . EOL;
12+
$objPHPPresentation = new PhpPresentation();
13+
14+
// Create slide
15+
echo date('H:i:s') . ' Create slide'.EOL;
16+
$oSlide1 = $objPHPPresentation->getActiveSlide();
17+
$oSlide1->addShape(clone $oShapeDrawing);
18+
$oSlide1->addShape(clone $oShapeRichText);
19+
20+
$oAuthor = new \PhpOffice\PhpPresentation\Shape\Comment\Author();
21+
$oAuthor->setName('Progi1984');
22+
$oAuthor->setInitials('P');
23+
24+
// Add Comment 1
25+
echo date('H:i:s') . ' Add Comment 1'.EOL;
26+
$oComment1 = new \PhpOffice\PhpPresentation\Shape\Comment();
27+
$oComment1->setText('Text A');
28+
$oComment1->setOffsetX(10);
29+
$oComment1->setOffsetY(55);
30+
$oComment1->setDate(time());
31+
$oComment1->setAuthor($oAuthor);
32+
$oSlide1->addShape($oComment1);
33+
34+
// Add Comment
35+
echo date('H:i:s') . ' Add Comment 2'.EOL;
36+
$oComment2 = new \PhpOffice\PhpPresentation\Shape\Comment();
37+
$oComment2->setText('Text B');
38+
$oComment2->setOffsetX(170);
39+
$oComment2->setOffsetY(180);
40+
$oComment2->setDate(time());
41+
$oComment2->setAuthor($oAuthor);
42+
$oSlide1->addShape($oComment2);
43+
44+
// Save file
45+
echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers);
46+
if (!CLI) {
47+
include_once 'Sample_Footer.php';
48+
}

src/PhpPresentation/Shape/Comment.php

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
<?php
2+
/**
3+
* This file is part of PHPPresentation - A pure PHP library for reading and writing
4+
* presentations documents.
5+
*
6+
* PHPPresentation is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
12+
*
13+
* @link https://github.com/PHPOffice/PHPPresentation
14+
* @copyright 2009-2015 PHPPresentation contributors
15+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16+
*/
17+
18+
namespace PhpOffice\PhpPresentation\Shape;
19+
20+
use PhpOffice\PhpPresentation\AbstractShape;
21+
use PhpOffice\PhpPresentation\ComparableInterface;
22+
use PhpOffice\PhpPresentation\Shape\Comment\Author;
23+
24+
/**
25+
* Comment shape
26+
*/
27+
class Comment extends AbstractShape implements ComparableInterface
28+
{
29+
/**
30+
* @var Author
31+
*/
32+
protected $author;
33+
34+
/**
35+
* @var int
36+
*/
37+
protected $dtComment;
38+
39+
/**
40+
* @var string
41+
*/
42+
protected $text;
43+
44+
public function __construct()
45+
{
46+
parent::__construct();
47+
$this->setDate(time());
48+
}
49+
50+
/**
51+
* @return Author
52+
*/
53+
public function getAuthor()
54+
{
55+
return $this->author;
56+
}
57+
58+
/**
59+
* @param Author $author
60+
* @return Comment
61+
*/
62+
public function setAuthor(Author $author)
63+
{
64+
$this->author = $author;
65+
return $this;
66+
}
67+
68+
/**
69+
* @return int
70+
*/
71+
public function getDate()
72+
{
73+
return $this->dtComment;
74+
}
75+
76+
/**
77+
* @param int $dtComment timestamp of the comment
78+
* @return Comment
79+
*/
80+
public function setDate($dtComment)
81+
{
82+
$this->dtComment = (int)$dtComment;
83+
return $this;
84+
}
85+
86+
/**
87+
* @return string
88+
*/
89+
public function getText()
90+
{
91+
return $this->text;
92+
}
93+
94+
/**
95+
* @param string $text
96+
* @return Comment
97+
*/
98+
public function setText($text = '')
99+
{
100+
$this->text = $text;
101+
return $this;
102+
}
103+
104+
/**
105+
* Comment has not height
106+
*
107+
* @return null
108+
*/
109+
public function getHeight()
110+
{
111+
return null;
112+
}
113+
114+
/**
115+
* Set Height
116+
*
117+
* @param int $pValue
118+
* @return self
119+
*/
120+
public function setHeight($pValue = 0)
121+
{
122+
return $this;
123+
}
124+
125+
/**
126+
* Comment has not width
127+
*
128+
* @return null
129+
*/
130+
public function getWidth()
131+
{
132+
return null;
133+
}
134+
135+
/**
136+
* Set Width
137+
*
138+
* @param int $pValue
139+
* @return self
140+
*/
141+
public function setWidth($pValue = 0)
142+
{
143+
return $this;
144+
}
145+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
namespace PhpOffice\PhpPresentation\Shape\Comment;
4+
5+
class Author
6+
{
7+
/**
8+
* @var int
9+
*/
10+
protected $idxAuthor;
11+
12+
/**
13+
* @var string
14+
*/
15+
protected $initials;
16+
17+
/**
18+
* @var string
19+
*/
20+
protected $name;
21+
22+
/**
23+
* @return int
24+
*/
25+
public function getIndex()
26+
{
27+
return $this->idxAuthor;
28+
}
29+
30+
/**
31+
* @param int $idxAuthor
32+
* @return Author
33+
*/
34+
public function setIndex($idxAuthor)
35+
{
36+
$this->idxAuthor = (int) $idxAuthor;
37+
return $this;
38+
}
39+
40+
/**
41+
* @return mixed
42+
*/
43+
public function getInitials()
44+
{
45+
return $this->initials;
46+
}
47+
48+
/**
49+
* @param mixed $initials
50+
* @return Author
51+
*/
52+
public function setInitials($initials)
53+
{
54+
$this->initials = $initials;
55+
return $this;
56+
}
57+
58+
/**
59+
* @return string
60+
*/
61+
public function getName()
62+
{
63+
return $this->name;
64+
}
65+
66+
/**
67+
* @param string $name
68+
* @return Author
69+
*/
70+
public function setName($name)
71+
{
72+
$this->name = $name;
73+
return $this;
74+
}
75+
76+
/**
77+
* Get hash code
78+
*
79+
* @return string Hash code
80+
*/
81+
public function getHashCode()
82+
{
83+
return md5($this->getInitials() . $this->getName() . __CLASS__);
84+
}
85+
}

0 commit comments

Comments
 (0)