From 0e5dd8547dceab4a62a0e0d281dd5878acb1c83f Mon Sep 17 00:00:00 2001 From: devX2712 <69680982+devX2712@users.noreply.github.com> Date: Wed, 3 Feb 2021 17:06:59 +0100 Subject: [PATCH] ADD usefull function te search shape into a slide For modifing existing slide, usefull to search shape and doing action on it --- src/PhpPresentation/Slide/AbstractSlide.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/PhpPresentation/Slide/AbstractSlide.php b/src/PhpPresentation/Slide/AbstractSlide.php index b3d6fedfd..d67d51b16 100644 --- a/src/PhpPresentation/Slide/AbstractSlide.php +++ b/src/PhpPresentation/Slide/AbstractSlide.php @@ -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|ArrayObject $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 */