Skip to content

Commit

Permalink
ADD usefull function te search shape into a slide
Browse files Browse the repository at this point in the history
For modifing existing slide, usefull to search shape and doing action on it
  • Loading branch information
devX2712 authored and Progi1984 committed Dec 13, 2023
1 parent 0e03232 commit 0e5dd85
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/PhpPresentation/Slide/AbstractSlide.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,25 @@ public function getShapeCollection()
}

/**
* Get collection of shapes.
* Search into collection of shapes for a name (eventually filtered by type ex: RichText)
*
* @param array<int, AbstractShape>|ArrayObject<int, AbstractShape> $shapeCollection
* @param string $name The name to find into the shape collection
* @param PhpOffice\PhpPresentation\Shape\RichText | PhpOffice\PhpPresentation\Shape\... $type Type of the class
* @return \ArrayObject|\PhpOffice\PhpPresentation\AbstractShape[]
*/
public function searchShapeByName(string $name, ?string $type=null)
{
if (isset($this->shapeCollection)) {
foreach ($this->shapeCollection as $shape) {
if ($shape->getName() == $name) {
if (!isset($type) || get_class($shape) == $type) {
return $shape;
}}}}
return null;
}

/**
* Get collection of shapes
*
* @return AbstractSlide
*/
Expand Down

0 comments on commit 0e5dd85

Please sign in to comment.