Completed
Pull Request — develop (#207)
by Franck
06:53
created

Pictures::render()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 22
ccs 13
cts 13
cp 1
rs 8.6737
cc 5
eloc 13
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
     */
14
15 57
    public function render()
16
    {
17 57
        $arrMedia = array();
18 57
        for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) {
19 28
            $shape = $this->getDrawingHashTable()->getByIndex($i);
20 28
            if (!($shape instanceof Drawing\AbstractDrawingAdapter)) {
21 21
                continue;
22
            }
23 8
            $arrMedia[] = $shape->getIndexedFilename();
24 8
            $this->getZip()->addFromString('Pictures/' . $shape->getIndexedFilename(), $shape->getContents());
25
        }
26
27 57
        foreach ($this->getPresentation()->getAllSlides() as $keySlide => $oSlide) {
28
            // Add background image slide
29 57
            $oBkgImage = $oSlide->getBackground();
30 57
            if ($oBkgImage instanceof Image) {
31 57
                $this->getZip()->addFromString('Pictures/'.$oBkgImage->getIndexedFilename($keySlide), file_get_contents($oBkgImage->getPath()));
32
            }
33
        }
34
        
35 57
        return $this->getZip();
36
    }
37
}
38