Skip to content

Commit 0e5dd85

Browse files
devX2712Progi1984
authored andcommitted
ADD usefull function te search shape into a slide
For modifing existing slide, usefull to search shape and doing action on it
1 parent 0e03232 commit 0e5dd85

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/PhpPresentation/Slide/AbstractSlide.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,25 @@ public function getShapeCollection()
118118
}
119119

120120
/**
121-
* Get collection of shapes.
121+
* Search into collection of shapes for a name (eventually filtered by type ex: RichText)
122122
*
123-
* @param array<int, AbstractShape>|ArrayObject<int, AbstractShape> $shapeCollection
123+
* @param string $name The name to find into the shape collection
124+
* @param PhpOffice\PhpPresentation\Shape\RichText | PhpOffice\PhpPresentation\Shape\... $type Type of the class
125+
* @return \ArrayObject|\PhpOffice\PhpPresentation\AbstractShape[]
126+
*/
127+
public function searchShapeByName(string $name, ?string $type=null)
128+
{
129+
if (isset($this->shapeCollection)) {
130+
foreach ($this->shapeCollection as $shape) {
131+
if ($shape->getName() == $name) {
132+
if (!isset($type) || get_class($shape) == $type) {
133+
return $shape;
134+
}}}}
135+
return null;
136+
}
137+
138+
/**
139+
* Get collection of shapes
124140
*
125141
* @return AbstractSlide
126142
*/

0 commit comments

Comments
 (0)