<?php
/*
* 2007-2016 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <contact@prestashop.com>
*  @copyright  2007-2016 PrestaShop SA
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/


/**
 * @since 1.6.0
 */
class AdminPaxyprestaController extends ModuleAdminController
{
    public function __construct()
    {
        $this->display = 'view';
        $this->bootstrap = true;
        parent::__construct();
    }

    private function getActiveCarriers()
    {
        $sql = new DbQuery();
        $sql->select('*');
        $sql->from('carrier', 'c');
        $sql->where('c.active = 1');
        $sql->where('c.deleted = 0');
        return Db::getInstance()->executeS($sql);
    }

    private function getPickupPointsCarriers()
    {
        $sql = new DbQuery();
        $sql->select('paxy_couriers.id, c.id_carrier as id_carrier, c.name, paxy_couriers.is_pickup_point, paxy_couriers.widget_pickup_point, paxy_couriers.paxy_parcel_type, paxy_couriers.paxy_courier_name, paxy_couriers.paxy_country_name');
        $sql->from('paxy_presta_couriers', 'paxy_couriers');
        $sql->innerJoin('carrier', 'c', 'paxy_couriers.id_reference = c.id_reference');
        $sql->where('c.active = 1');
        $sql->where('c.deleted = 0');
        return Db::getInstance()->executeS($sql);
    }

    public function renderView()
    {
        $clCarriers = $this->getPickupPointsCarriers();
        foreach ($clCarriers as $key => $clCarrier) {
            $clCarriers[$key]['prettyPointName'] = $this->mapPointValueToLabel($clCarrier['widget_pickup_point']);
        }

        $this->tpl_view_vars = array(
            'clCarriers' => $clCarriers,
            'createUrl' => $this->context->link->getAdminLink('AdminPaxyprestacreate'),
            'deleteUrl' => $this->context->link->getAdminLink('AdminPaxyprestadelete'),
        );

        $this->base_tpl_view = 'pickup_carriers_list.tpl';

        return parent::renderView();
    }

    private function mapPointValueToLabel($value)
    {
        switch ($value) {
            case "cp_balikovna":
                return "Balíkovna - Česká pošta";
            case "cp_napostu":
                return "Balík Na poštu - Česká pošta";
            case "sps_parcelshop_":
                return "SPS ParcelShop";
            case "sps_balikomat_":
                return "SPS Balikomat";
            case "econt":
                return "Econt Office";
            case "sameday":
                return "SameDay (RO)";
            case "samedayhu":
                return "SameDay (HU)";
            case "samedaybg_":
                return "SameDay (BG)";
            case "wedo_point_":
                return "WeDo Point";
            case "wedo_box_":
                return "WeDo Box";
            case "sppoczta":
                return "Slovenská pošta";
            case "sppoczta_office_":
                return "Balík na poštu - Slovenská pošta";
            case "sppoczta_point_":
                return "BalíkoBOX - Slovenská pošta";
            case "mpl_office_":
                return "Csomagautomata - Magyar Posta";
            case "mpl_point_":
                return "PostaPont - Magyar Posta";
            case "mpl_postapont_":
                return "PostaPont - Magyar Posta";
            case "mpl_csomagautomata_":
                return "Csomagautomata - Magyar Posta";
            case "lpexpress":
                return "LPExpress Point";
            case "sp_point_":
                return "Balík na poštu - Slovenská pošta";
            case "sp_office_":
                return "BalíkoBOX - Slovenská pošta";
            case "postask_napostu_":
                return "Balík na poštu - Slovenská pošta";
            case "postask_balikobox_":
                return "BalíkoBOX - Slovenská pošta";
            case "ppl_parcelbox_":
                return "PPL ParcelBox";
            case "ppl_parcelshop_":
                return "PPL ParcelShop";
            case "fancourier_fanbox_":
                return "FanCourier FanBOX";
            case "fancourier_point_":
                return "FanCourier Point";
            case "fancourier_collectpoint_":
                return "FanCourier CollectPoint";
            case "venipaklt_locker_":
                return "Venipak Locker (LT)";
            case "venipaklt_pickup_":
                return "Venipak Pickup (LT)";
            case "venipaklv_locker_":
                return "Venipak Locker (LV)";
            case "venipaklv_pickup_":
                return "Venipak Pickup (LV)";
            case "venipakee_locker_":
                return "Venipak Locker (EE)";
            case "venipakee_pickup_":
                return "Venipak Pickup (EE)";
            case "postahr_napostu_":
                return "Post Office - Hrvatska pošta";
            case "postahr_paketomat_":
                return "Paketomat - Hrvatska pošta";
            case "cargus_":
                return "Cargus Locker";
            case "hermes_":
                return "Hermes Paketversand";
            case "posteitaliane_":
                return "Poste Italiane";
            case "postnordse_":
                return "PostNord (SE)";
            case "postnordfi_":
                return "PostNord (FI)";
            case "postnorddk_":
                return "PostNord (DK)";
            default:
                return $value;
        }
    }

}
