|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Admingenerator\GeneratorBundle\Builder\Admin; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* This builder generates php for lists actions |
|
7
|
|
|
* @author cedric Lombardot |
|
8
|
|
|
*/ |
|
9
|
|
|
class NestedListBuilder extends ListBuilder |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var array |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $treeConfiguration = array(); |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var mixed |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $indentationColumnIndex = null; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* (non-PHPdoc) |
|
23
|
|
|
* @see Admingenerator\GeneratorBundle\Builder.BaseBuilder::getYamlKey() |
|
24
|
|
|
*/ |
|
25
|
|
|
public function getYamlKey() |
|
26
|
|
|
{ |
|
27
|
|
|
return 'nested_list'; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Returns tree configuration, an array containing nested tree fields identifiers: |
|
32
|
|
|
* array: |
|
33
|
|
|
* root => root field |
|
34
|
|
|
* left => left field |
|
35
|
|
|
* right => right field |
|
36
|
|
|
* parent => parent field |
|
37
|
|
|
* |
|
38
|
|
|
* @return array |
|
39
|
|
|
*/ |
|
40
|
|
|
public function getTreeConfiguration() |
|
41
|
|
|
{ |
|
42
|
|
|
if (empty($this->treeConfiguration)) { |
|
43
|
|
|
$this->findTreeConfiguration(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
return $this->treeConfiguration; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Get the indentation field that should be used. |
|
51
|
|
|
* No validity is made uppon the field name. |
|
52
|
|
|
* |
|
53
|
|
|
* @return mixed |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getIndentationColumnIndex() |
|
56
|
|
|
{ |
|
57
|
|
|
if (null === $this->indentationColumnIndex) { |
|
58
|
|
|
$field = $this->getGenerator()->getFromYaml('builders.nested_list.indentation.field'); |
|
59
|
|
|
if (!$field) { |
|
60
|
|
|
return $this->indentationColumnIndex = 0; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$this->indentationColumnIndex = array_search($field, array_keys($this->getColumns())); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return $this->indentationColumnIndex; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Extract tree configuration from generator. |
|
71
|
|
|
* If none defined, default is: |
|
72
|
|
|
* array: |
|
73
|
|
|
* root => root |
|
74
|
|
|
* left => lft |
|
75
|
|
|
* right => rgt |
|
76
|
|
|
* parent => parent |
|
77
|
|
|
*/ |
|
78
|
|
|
protected function findTreeConfiguration() |
|
79
|
|
|
{ |
|
80
|
|
|
$this->treeConfiguration = array_merge(array( |
|
81
|
|
|
'root' => 'root', |
|
82
|
|
|
'left' => 'lft', |
|
83
|
|
|
'right' => 'rgt', |
|
84
|
|
|
'parent' => 'parent' |
|
85
|
|
|
), $this->getGenerator()->getFromYaml('builders.nested_list.tree') ?: array()); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|