39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @note If you need deliveries by delivery type or class name or id.
|
|
*
|
|
* @param id - filter deliveries by id
|
|
* @param type - filter deliveries by Delivery::$type
|
|
* @param class_name - filter deliveries by Delivery::$className
|
|
* @param figure - get only figure deliveries - default is true
|
|
*
|
|
* @return array|void
|
|
*/
|
|
function smarty_function_get_deliveries($params, &$smarty)
|
|
{
|
|
$deliveries = Delivery::getAll($params['figure'] ?? true);
|
|
|
|
if ($id = ($params['id'] ?? false)) {
|
|
$deliveries = array_filter($deliveries ?? [], function ($delivery) use ($id) {
|
|
return $delivery->id == $id;
|
|
});
|
|
}
|
|
if ($type = ($params['type'] ?? false)) {
|
|
$deliveries = array_filter($deliveries ?? [], function ($delivery) use ($type) {
|
|
return $delivery->getType() == $type;
|
|
});
|
|
}
|
|
if ($className = ($params['class_name'] ?? false)) {
|
|
$deliveries = array_filter($deliveries ?? [], function ($delivery) use ($className) {
|
|
return $delivery->getClassName() == $className;
|
|
});
|
|
}
|
|
|
|
if (!empty($params['assign'])) {
|
|
$smarty->assign($params['assign'], $deliveries);
|
|
} else {
|
|
return $deliveries;
|
|
}
|
|
}
|