d8c1a2e0
Yarik
Big commit artbox
|
1
2
3
4
5
6
7
8
9
10
11
12
|
<?php
namespace common\components\artboxtree;
use yii\base\Object;
use yii\helpers\ArrayHelper;
class ArtboxTreeHelper extends Object {
public static function treeMap($tree, $from, $to, $symbol = '.')
{
$result = [];
|
8af13427
Yarik
For leha commit.
|
13
|
self::recursiveTreeMap($result, $tree, $from, $to, $symbol);
|
d8c1a2e0
Yarik
Big commit artbox
|
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
return $result;
}
public static function setArrayField($path, $as_string = false) {
if (is_array($path)) {
if ($as_string) {
foreach ($path as &$item) {
$item = "'$item'";
}
}
$path = implode(',', $path);
}
return '{'. $path .'}';
}
public static function getArrayField($path) {
$path = trim($path, '{}');
return empty($path) ? [] : explode(',', $path);
}
|
8af13427
Yarik
For leha commit.
|
35
|
protected static function recursiveTreeMap(&$result, $tree, $from, $to, $symbol = '–') {
|
d8c1a2e0
Yarik
Big commit artbox
|
36
37
38
39
40
41
42
|
foreach ($tree as $item) {
$element = $item['item'];
$key = ArrayHelper::getValue($element, $from);
$value = ArrayHelper::getValue($element, $to);
$row = str_repeat($symbol, $element->depth+1) . $value;
$result[$key] = $row;
if (!empty($item['children'])) {
|
8af13427
Yarik
For leha commit.
|
43
|
self::recursiveTreeMap($result, $item['children'], $from, $to, $symbol);
|
d8c1a2e0
Yarik
Big commit artbox
|
44
45
46
47
|
}
}
}
}
|