You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.6 KiB
62 lines
1.6 KiB
<?php
|
|
|
|
if (!function_exists('generate_tree')) {
|
|
function generate_tree(
|
|
array $flatArray,
|
|
int $parentId = 0,
|
|
array $existsArr = []
|
|
): array {
|
|
$tree = [];
|
|
foreach ($flatArray as $item) {
|
|
if ($item['parent_id'] === $parentId) {
|
|
$node = $item;
|
|
if ($existsArr) {
|
|
$node['is_show'] = in_array($item['id'], $existsArr) ? 1
|
|
: 0;
|
|
}
|
|
$node['children'] = generate_tree(
|
|
$flatArray,
|
|
$item['id'],
|
|
$existsArr
|
|
);
|
|
$tree[] = $node;
|
|
}
|
|
}
|
|
return $tree;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('get_datetime')) {
|
|
function get_datetime(string $type = 'datetime', int $times = 0): string
|
|
{
|
|
if (!$times) {
|
|
$times = time();
|
|
}
|
|
$format = match ($type) {
|
|
'date' => 'Y-m-d',
|
|
'datetime' => 'Y-m-d H:i:s',
|
|
};
|
|
return date($format, $times);
|
|
}
|
|
}
|
|
|
|
if (!function_exists('get_select_data')) {
|
|
function get_select_data(
|
|
array $data = [],
|
|
bool $is_all = false,
|
|
string $str1 = 'label',
|
|
string $str2 = 'value'
|
|
): array {
|
|
$newData = [];
|
|
if ($is_all) {
|
|
$newData[] = [$str1 => __('admin.all'), $str2 => ''];
|
|
}
|
|
foreach ($data as $key => $value) {
|
|
$newData[] = [
|
|
$str1 => $value,
|
|
$str2 => $key
|
|
];
|
|
}
|
|
return $newData;
|
|
}
|
|
}
|
|
|