Completed
Pull Request — develop (#565)
by
unknown
07:15
created

Pictures::render()   A

Complexity

Conditions 5
Paths 9

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 13
cts 13
cp 1
rs 9.2568
c 0
b 0
f 0
cc 5
nc 9
nop 0
crap 5
1
<?php
2
3
namespace PhpOffice\PhpPresentation\Writer\ODPresentation;
4
5
use PhpOffice\Common\Adapter\Zip\ZipInterface;
6
use PhpOffice\PhpPresentation\Shape\Drawing;
7
use PhpOffice\PhpPresentation\Slide\Background\Image;
8
9
class Pictures extends AbstractDecoratorWriter
10
{
11
    /**
12
     * @return ZipInterface
13
     * @throws \Exception
14
     */
15
16 62
    public function render()
17
    {
18 62
        $arrMedia = array();
19 62
        for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) {
20 32
            $shape = $this->getDrawingHashTable()->getByIndex($i);
21 32
            if (!($shape instanceof Drawing\AbstractDrawingAdapter)) {
22 24
                continue;
23
            }
24 9
            $arrMedia[] = $shape->getIndexedFilename();
25 9
            $this->getZip()->addFromString('Pictures/' . $shape->getIndexedFilename(), $shape->getContents());
26
        }
27
28 62
        foreach ($this->getPresentation()->getAllSlides() as $keySlide => $oSlide) {
29
            // Add background image slide
30 62
            $oBkgImage = $oSlide->getBackground();
31 62
            if ($oBkgImage instanceof Image) {
32 62
                $this->getZip()->addFromString('Pictures/'.$oBkgImage->getIndexedFilename($keySlide), file_get_contents($oBkgImage->getPath()));
33
            }
34
        }
35
        
36 62
        return $this->getZip();
37
    }
38
}
39