<?php

/**
 * Smarty plugin.
 */

/**
 * Smarty {get_statuses} plugin.
 *
 * Type:     function<br>
 * Name:     url<br>
 * Purpose:  get statuses
 *
 * @param array                    $params parameters
 * @param Smarty_Internal_Template $smarty
 *
 * @return string
 */
function smarty_function_get_today_selled_items($params, &$smarty)
{
    $last_item = end($params['items']);

    if (empty($last_item['date'])) {
        return $params['items'];
    }

    $last_datetime = (new DateTime($last_item['date']))->modify('-1 hours');

    $items = [];
    foreach ($params['items'] as $item) {
        $datetime = new DateTime($item['date']);
        if ($last_datetime < $datetime) {
            $items[] = $item;
        }
    }

    if (empty($items)) {
        return $params['items'];
    }

    if (!empty($params['assign'])) {
        $smarty->assign($params['assign'], $items);
    } else {
        return $items;
    }
}
