Skip to content

Commit db96a0a

Browse files
devX2712Progi1984
authored andcommitted
BUGFIX while cloning an existant slide
BUGFIX while cloning an existant slide : - considere if existing object - cloning each object into collection - cloning each paragraph for RichText
1 parent afc58c0 commit db96a0a

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

src/PhpPresentation/AbstractShape.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,22 @@ public function __construct()
135135
public function __clone()
136136
{
137137
$this->container = null;
138-
$this->fill = clone $this->fill;
139-
$this->border = clone $this->border;
140-
$this->shadow = clone $this->shadow;
138+
$this->name = $this->name;
139+
if (isset($this->fill)) {
140+
$this->fill = clone $this->fill;
141+
}
142+
if (isset($this->border)) {
143+
$this->border = clone $this->border;
144+
}
145+
if (isset($this->shadow)) {
146+
$this->shadow = clone $this->shadow;
147+
}
148+
if (isset($this->placeholder)) {
149+
$this->placeholder = clone $this->placeholder;
150+
}
151+
if (isset($this->hyperlink)) {
152+
$this->hyperlink = clone $this->hyperlink;
153+
}
141154
}
142155

143156
/**

src/PhpPresentation/Shape/RichText.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,23 @@ public function __construct()
185185
}
186186

187187
/**
188-
* Get active paragraph index.
188+
* Magic Method : clone
189+
*/
190+
public function __clone()
191+
{
192+
// Call perent clonage for heritage
193+
parent::__clone();
194+
// Clone each paragraph
195+
if (isset($this->richTextParagraphs)) {
196+
foreach ($this->richTextParagraphs as &$paragraph) {
197+
$paragraph = clone $paragraph;
198+
}}
199+
}
200+
201+
/**
202+
* Get active paragraph index
203+
*
204+
* @return int
189205
*/
190206
public function getActiveParagraphIndex(): int
191207
{

src/PhpPresentation/Slide.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,29 @@ public function setSlideMasterId($masterId = 1)
132132
return $this;
133133
}
134134

135+
136+
public function __clone()
137+
{
138+
// Set parent
139+
$this->parent = clone $this->parent;
140+
// Shape collection
141+
if (isset($this->shapeCollection)) {
142+
$this->shapeCollection = clone $this->shapeCollection;
143+
foreach ($this->shapeCollection as &$shape) {
144+
$shape = clone $shape;
145+
}
146+
}
147+
// Transition object
148+
if (isset($this->slideTransition)) {
149+
$this->slideTransition = clone $this->slideTransition;
150+
}
151+
// Note object
152+
if (isset($this->slideNote)) {
153+
$this->slideNote = clone $this->slideNote;
154+
}
155+
156+
}
157+
135158
/**
136159
* Copy slide (!= clone!).
137160
*

0 commit comments

Comments
 (0)