home > controller : shuffle slides + déplacer logique depuis template
All checks were successful
Deploy / Deploy to Production (push) Successful in 3s
All checks were successful
Deploy / Deploy to Production (push) Successful in 3s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
06fc040f80
commit
5d6fa47606
6 changed files with 102 additions and 80 deletions
33
site/controllers/home.php
Normal file
33
site/controllers/home.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
return function($site) {
|
||||
$files = $site->slideshow()->toFiles();
|
||||
$count = $files->count();
|
||||
|
||||
$units = [];
|
||||
$i = 0;
|
||||
|
||||
while ($i < $count) {
|
||||
$file = $files->nth($i);
|
||||
$nextFile = $files->nth($i + 1);
|
||||
|
||||
$isPortrait = $file->type() === 'image' && $file->orientation() === 'portrait';
|
||||
$nextIsPortrait = $nextFile && $nextFile->type() === 'image' && $nextFile->orientation() === 'portrait';
|
||||
|
||||
if ($isPortrait && $nextIsPortrait) {
|
||||
$units[] = ['pair' => true, 'a' => $file, 'b' => $nextFile];
|
||||
$i += 2;
|
||||
} else {
|
||||
$units[] = ['pair' => false, 'file' => $file];
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($site->areSlidesShuffled()->isTrue()) {
|
||||
shuffle($units);
|
||||
}
|
||||
|
||||
return [
|
||||
'slides' => $units,
|
||||
];
|
||||
};
|
||||
|
|
@ -1,26 +1,26 @@
|
|||
<?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 {
|
||||
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;
|
||||
}
|
||||
}
|
||||
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"]]
|
||||
}, $categoriesRawFields); // return '[["A", "B", "C",], ["A", "B"]]
|
||||
$flattenedCategories = array_flatten($splittedCategoriesFields);
|
||||
$trimmed = array_map('trim', $flattenedCategories);
|
||||
$filtered = array_filter($trimmed, fn($v) => $v !== '');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue