Mise à jour Camille
This commit is contained in:
parent
1dd4060314
commit
b373875a61
33 changed files with 883 additions and 150 deletions
33
site/controllers/index.php
Normal file
33
site/controllers/index.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
return function($page) {
|
||||
function array_flatten($array) {
|
||||
if (!is_array($array)) {
|
||||
return false;
|
||||
}
|
||||
$result = array();
|
||||
foreach ($array as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$result = array_merge($result, array_flatten($value));
|
||||
} else {
|
||||
$result = array_merge($result, array($key => $value));
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function getSingleCategories($pages) {
|
||||
$categoriesRawFields = $pages->pluck('category'); // return ["A, B, C", "A, B"]
|
||||
$splittedCategoriesFields = array_map(function($field) {
|
||||
return explode(',', $field);
|
||||
}, $categoriesRawFields); // return ’[["A", "B", "C",], ["A", "B"]]
|
||||
$flattenedCategories = array_flatten($splittedCategoriesFields);
|
||||
$filters = array_unique($flattenedCategories);
|
||||
|
||||
return $filters;
|
||||
}
|
||||
|
||||
return [
|
||||
'categories' => getSingleCategories($page->children())
|
||||
];
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue