Completed
Pull Request — develop (#230)
by Franck
07:48
created

SlideMaster::addSchemeColor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * This file is part of PHPPresentation - A pure PHP library for reading and writing
4
 * presentations documents.
5
 *
6
 * PHPPresentation is free software distributed under the terms of the GNU Lesser
7
 * General Public License version 3 as published by the Free Software Foundation.
8
 *
9
 * For the full copyright and license information, please read the LICENSE
10
 * file that was distributed with this source code. For the full list of
11
 * contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
12
 *
13
 * @link        https://github.com/PHPOffice/PHPPresentation
14
 * @copyright   2009-2015 PHPPresentation contributors
15
 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16
 */
17
namespace PhpOffice\PhpPresentation\Slide;
18
19
use PhpOffice\PhpPresentation\ComparableInterface;
20
use PhpOffice\PhpPresentation\PhpPresentation;
21
use PhpOffice\PhpPresentation\ShapeContainerInterface;
22
use PhpOffice\PhpPresentation\Slide\Background\Color as BackgroundColor;
23
use PhpOffice\PhpPresentation\Style\Color;
24
use PhpOffice\PhpPresentation\Style\ColorMap;
25
use PhpOffice\PhpPresentation\Style\SchemeColor;
26
use PhpOffice\PhpPresentation\Style\TextStyle;
27
28
/**
29
 * Class SlideMaster
30
 */
31
class SlideMaster extends AbstractSlide implements ComparableInterface, ShapeContainerInterface
32
{
33
    /**
34
     * Collection of Slide objects
35
     *
36
     * @var \PhpOffice\PhpPresentation\Slide\SlideLayout[]
37
     */
38
    protected $slideLayouts = array();
39
    /**
40
     * Mapping of colors to the theme
41
     *
42
     * @var \PhpOffice\PhpPresentation\Style\ColorMap
43
     */
44
    public $colorMap;
45
    /**
46
     * @var \PhpOffice\PhpPresentation\Style\TextStyle
47
     */
48
    protected $textStyles;
49
    /**
50
     * @var \PhpOffice\PhpPresentation\Style\SchemeColor[]
51
     */
52
    protected $arraySchemeColor = array();
53
    /**
54
     * @var array
55
     */
56
    protected $defaultSchemeColor = array(
57
        'dk1' => '000000',
58
        'lt1' => 'FFFFFF',
59
        'dk2' => '1F497D',
60
        'lt2' => 'EEECE1',
61
        'accent1' => '4F81BD',
62
        'accent2' => 'C0504D',
63
        'accent3' => '9BBB59',
64
        'accent4' => '8064A2',
65
        'accent5' => '4BACC6',
66
        'accent6' => 'F79646',
67
        'hlink' => '0000FF',
68
        'folHlink' => '800080',
69
    );
70
71
    /**
72
     * Create a new slideMaster
73
     *
74
     * @param PhpPresentation $pParent
75
     */
76 198
    public function __construct(PhpPresentation $pParent = null)
77
    {
78
        // Set parent
79 198
        $this->parent = $pParent;
80
        // Shape collection
81 198
        $this->shapeCollection = new \ArrayObject();
82
        // Set identifier
83 198
        $this->identifier = md5(rand(0, 9999) . time());
84
        // Set a basic colorMap
85 198
        $this->colorMap = new ColorMap();
86
        // Set a white background
87 198
        $this->background = new BackgroundColor();
88 198
        $this->background->setColor(new Color(Color::COLOR_WHITE));
89
        // Set basic textStyles
90 198
        $this->textStyles = new TextStyle(true);
91
        // Set basic scheme colors
92 198
        foreach ($this->defaultSchemeColor as $key => $value) {
93 198
            $oSchemeColor = new SchemeColor();
94 198
            $oSchemeColor->setValue($key);
95 198
            $oSchemeColor->setRGB($value);
96 198
            $this->addSchemeColor($oSchemeColor);
97
        }
98 198
    }
99
100
    /**
101
     * Create a slideLayout and add it to this presentation
102
     *
103
     * @return \PhpOffice\PhpPresentation\Slide\SlideLayout
104
     */
105 193
    public function createSlideLayout()
106
    {
107 193
        $newSlideLayout = new SlideLayout($this);
108 193
        $this->addSlideLayout($newSlideLayout);
109 193
        return $newSlideLayout;
110
    }
111
112
    /**
113
     * Add slideLayout
114
     *
115
     * @param  \PhpOffice\PhpPresentation\Slide\SlideLayout $slideLayout
116
     * @throws \Exception
117
     * @return \PhpOffice\PhpPresentation\Slide\SlideLayout
118
     */
119 193
    public function addSlideLayout(SlideLayout $slideLayout = null)
120
    {
121 193
        $this->slideLayouts[] = $slideLayout;
122 193
        return $slideLayout;
123
    }
124
125
    /**
126
     * @return SlideLayout[]
127
     */
128 100
    public function getAllSlideLayouts()
129
    {
130 100
        return $this->slideLayouts;
131
    }
132
133
    /**
134
     * @return TextStyle
135
     */
136 101
    public function getTextStyles()
137
    {
138 101
        return $this->textStyles;
139
    }
140
141
    /**
142
     * @param TextStyle $textStyle
143
     * @return $this
144
     */
145 5
    public function setTextStyles(TextStyle $textStyle)
146
    {
147 5
        $this->textStyles = $textStyle;
148 5
        return $this;
149
    }
150
151
    /**
152
     * @param SchemeColor $schemeColor
153
     * @return $this
154
     */
155 198
    public function addSchemeColor(SchemeColor $schemeColor)
156
    {
157 198
        $this->arraySchemeColor[$schemeColor->getValue()] = $schemeColor;
158 198
        return $this;
159
    }
160
161
    /**
162
     * @return \PhpOffice\PhpPresentation\Style\SchemeColor[]
163
     */
164 96
    public function getAllSchemeColors()
165
    {
166 96
        return $this->arraySchemeColor;
167
    }
168
}
169