AbstractLayoutPack::getLayoutRelations()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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