Completed
Pull Request — develop (#186)
by
unknown
07:55
created

AbstractLayoutPack::getThemeRelations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
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
18
namespace PhpOffice\PhpPresentation\Writer\PowerPoint2007\LayoutPack;
19
20
/**
21
 * \PhpOffice\PhpPresentation\Writer\PowerPoint2007\LayoutPack
22
 */
23
abstract class AbstractLayoutPack
24
{
25
    /**
26
     * Master slides
27
     *
28
     * Structure:
29
     * - masterid
30
     * - body
31
     *
32
     * @var array
33
     */
34
    protected $masterSlides = array();
35
36
    /**
37
     * Master slide relations
38
     *
39
     * Structure:
40
     * - master id
41
     * - id (relation id)
42
     * - type
43
     * - contentType
44
     * - target (full path in OpenXML package)
45
     * - contents (body)
46
     *
47
     * @var array
48
     */
49
    protected $masterSlideRels = array();
50
51
    /**
52
     * Themes
53
     *
54
     * Structure:
55
     * - masterid
56
     * - body
57
     *
58
     * @var array
59
     */
60
    protected $themes = '';
61
62
    /**
63
     * Theme relations
64
     *
65
     * Structure:
66
     * - masterid
67
     * - id (relation id)
68
     * - type
69
     * - contentType
70
     * - target (full path in OpenXML package)
71
     * - contents (body)
72
     *
73
     * @var array
74
     */
75
    protected $themeRelations = array();
76
77
    /**
78
     * Array of slide layouts.
79
     *
80
     * These are all an array consisting of:
81
     * - id (int)
82
     * - masterid (int)
83
     * - name (string)
84
     * - body (string)
85
     *
86
     * @var array
87
     */
88
    protected $layouts = array();
89
90
    /**
91
     * Layout relations
92
     *
93
     * Structure:
94
     * - layoutId (referencing layout id in layouts array)
95
     * - id (relation id)
96
     * - type
97
     * - contentType
98
     * - target (full path in OpenXML package)
99
     * - contents (body)
100
     *
101
     * @var array
102
     */
103
    protected $layoutRelations = array();
104
105
    /**
106
     * Get master slides
107
     *
108
     * @return array
109
     */
110 75
    public function getMasterSlides()
111
    {
112 75
        return $this->masterSlides;
113
    }
114
115
    /**
116
     * Get master slide relations
117
     *
118
     * @return array
119
     */
120 75
    public function getMasterSlideRelations()
121
    {
122 75
        return $this->masterSlideRels;
123
    }
124
125
    /**
126
     * Get themes
127
     *
128
     * @return array
129
     */
130 75
    public function getThemes()
131
    {
132 75
        return $this->themes;
133
    }
134
135
    /**
136
     * Get theme relations
137
     *
138
     * @return array
139
     */
140 75
    public function getThemeRelations()
141
    {
142 75
        return $this->themeRelations;
143
    }
144
145
    /**
146
     * Get array of slide layouts
147
     *
148
     * @return array
149
     */
150 78
    public function getLayouts()
151
    {
152 78
        return $this->layouts;
153
    }
154
155
    /**
156
     * Get array of slide layout relations
157
     *
158
     * @return array
159
     */
160 75
    public function getLayoutRelations()
161
    {
162 75
        return $this->layoutRelations;
163
    }
164
165
    /**
166
     * Find specific slide layout.
167
     *
168
     * This is an array consisting of:
169
     * - masterid
170
     * - name (string)
171
     * - body (string)
172
     *
173
     * @param string $name
174
     * @param int $masterId
175
     * @return array
176
     * @throws \Exception
177
     */
178 2
    public function findLayout($name = '', $masterId = 1)
179
    {
180 2
        foreach ($this->layouts as $layout) {
181 2
            if ($layout['name'] == $name && $layout['masterid'] == $masterId) {
182 2
                return $layout;
183
            }
184
        }
185
186 1
        throw new \Exception("Could not find slide layout $name in current layout pack.");
187
    }
188
189
    /**
190
     * Find specific slide layout id.
191
     *
192
     * @param string $name
193
     * @param int $masterId
194
     * @return int
195
     * @throws \Exception
196
     */
197 77
    public function findLayoutId($name = '', $masterId = 1)
198
    {
199 77
        foreach ($this->layouts as $layoutId => $layout) {
200 77
            if ($layout['name'] == $name && $layout['masterid'] == $masterId) {
201 77
                return $layoutId;
202
            }
203
        }
204
205 1
        throw new \Exception("Could not find slide layout $name in current layout pack.");
206
    }
207
208
    /**
209
     * Find specific slide layout name.
210
     *
211
     * @param int $idLayout
212
     * @param int $masterId
213
     * @return int
214
     * @throws \Exception
215
     */
216 5
    public function findLayoutName($idLayout = '', $masterId = 1)
217
    {
218 5
        foreach ($this->layouts as $layoutId => $layout) {
219 5
            if ($layoutId == $idLayout && $layout['masterid'] == $masterId) {
220 5
                return $layout['name'];
221
            }
222
        }
223
224 1
        throw new \Exception("Could not find slide layout $idLayout in current layout pack.");
225
    }
226
}
227