64 lines
1.6 KiB
PHP
64 lines
1.6 KiB
PHP
<?php
|
|
|
|
/* SECTIONS HELPERS */
|
|
if( !function_exists( 'section_must_be' ) ){
|
|
|
|
function section_must_be( array|string $sections, string $item ): bool
|
|
{
|
|
if( is_array($sections) ){
|
|
return in_array( $item, $sections );
|
|
}
|
|
return $sections === $item;
|
|
}
|
|
|
|
}
|
|
|
|
if( !function_exists( 'section_must_not_be' ) ){
|
|
|
|
function section_must_not_be( array|string $sections, string $item ): bool
|
|
{
|
|
if( is_array($sections) ){
|
|
return ! in_array( $item, $sections );
|
|
}
|
|
return $sections !== $item;
|
|
}
|
|
|
|
}
|
|
|
|
if( !function_exists( 'databaseRoute' ) ){
|
|
|
|
function databaseRoute( array $params = [] ): string
|
|
{
|
|
$defaults = [
|
|
'types' => [],
|
|
'platforms' => [],
|
|
'genres' => [],
|
|
'games' => [],
|
|
'statuses' => [],
|
|
'authors' => [],
|
|
'authorsMode' => 'or',
|
|
'languages' => [],
|
|
'languagesMode' => 'or',
|
|
'modifications' => [],
|
|
'modificationsMode' => 'or',
|
|
'sort' => 'created_at',
|
|
'dir' => 'desc',
|
|
's' => ''
|
|
];
|
|
|
|
$query = array_filter(
|
|
array_merge($defaults, $params),
|
|
fn($v,$k) => match(true){
|
|
is_array($v) => !empty($v),
|
|
in_array($k, ['authorsMode', 'languagesMode', 'modificationsMode']) => $v !== 'or',
|
|
$k === 'sort' => $v !== 'created_at',
|
|
$k === 'dir' => $v !== 'desc',
|
|
default => $v !== '',
|
|
},
|
|
ARRAY_FILTER_USE_BOTH
|
|
);
|
|
|
|
return route('entries.index', $query );
|
|
}
|
|
}
|