|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright: Deux Huit Huit 2017 |
|
4
|
|
|
* LICENCE: MIT https://deuxhuithuit.mit-license.org |
|
5
|
|
|
*/ |
|
6
|
|
|
class SectionsInfos |
|
7
|
|
|
{ |
|
8
|
|
|
private static $deepness = 0; |
|
9
|
|
|
private static $seenFields = array(); |
|
10
|
|
|
public static function fetch($sections) |
|
11
|
|
|
{ |
|
12
|
|
|
self::$deepness++; |
|
13
|
|
|
$options = array(); |
|
14
|
|
|
$sections = SectionManager::fetch($sections); |
|
15
|
|
|
if (!empty($sections)) { |
|
16
|
|
|
foreach ($sections as $section) { |
|
17
|
|
|
$section_fields = $section->fetchFields(); |
|
18
|
|
|
if(!is_array($section_fields)) { |
|
19
|
|
|
continue; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
$fields = array(); |
|
23
|
|
|
foreach($section_fields as $f) { |
|
24
|
|
|
$fd = General::intval($f->get('deepness')); |
|
25
|
|
|
if ($fd > 0 && self::$deepness > $fd) { |
|
26
|
|
|
continue; |
|
27
|
|
|
} |
|
28
|
|
|
if (in_array($f->get('id'), self::$seenFields)) { |
|
29
|
|
|
continue; |
|
30
|
|
|
} |
|
31
|
|
|
self::$seenFields[] = $f->get('id'); |
|
32
|
|
|
$modes = $f->fetchIncludableElements(); |
|
33
|
|
|
|
|
34
|
|
|
if (is_array($modes)) { |
|
35
|
|
|
// include default |
|
36
|
|
|
$fields[] = array( |
|
37
|
|
|
'id' => $f->get('id'), |
|
38
|
|
|
'name' => $f->get('label'), |
|
39
|
|
|
'handle' => $f->get('element_name'), |
|
40
|
|
|
'type' => $f->get('type'), |
|
41
|
|
|
'default' => true, |
|
42
|
|
|
); |
|
43
|
|
|
if (count($modes) > 1) { |
|
44
|
|
|
foreach ($modes as $mode) { |
|
45
|
|
|
$fields[] = array( |
|
46
|
|
|
'id' => $f->get('id'), |
|
47
|
|
|
'name' => $f->get('label'), |
|
48
|
|
|
'handle' => $mode, |
|
49
|
|
|
'type' => $f->get('type') |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$options[] = array( |
|
57
|
|
|
'name' => $section->get('name'), |
|
58
|
|
|
'handle' => $section->get('handle'), |
|
59
|
|
|
'fields' => $fields |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
self::$deepness--; |
|
64
|
|
|
if (self::$deepness === 0) { |
|
65
|
|
|
self::$seenFields = array(); |
|
66
|
|
|
} |
|
67
|
|
|
return $options; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|