<?php

/**
 * This file contains package_quiqqer_tour_ajax_getListForGrid
 */

QUI::$Ajax->registerFunction(
    'package_quiqqer_tour_ajax_getListForGrid',
    function () {
        $result = array();
        $list   = QUI\Tour\TourHandler::getInstance()->getList(QUI::getUserBySession()->getLang());

        foreach ($list as $package => $tours) {
            $result = array_merge($result, $tours);
        }

        // translation
        foreach ($result as $key => $tour) {
            if (is_array($tour['title'])) {
                $result[$key]['title'] = QUI::getLocale()->get(
                    $tour['title'][0],
                    $tour['title'][1]
                );
            }

            if (is_array($tour['description'])) {
                $result[$key]['description'] = QUI::getLocale()->get(
                    $tour['description'][0],
                    $tour['description'][1]
                );
            }
        }

        return $result;
    }
);
