<?php
namespace TourOperatorProAdmin\app\models;
defined('_TOUROPERATOR_EXEC') or die;

use TourOperatorPro\Factory;
use TourOperatorPro\Mvc\Model\ModelForm;
use TourOperatorPro\Form\Form;
use TourOperatorPro\Mvc\Model\ModelList;
use TourOperatorPro\Registry\Registry;
class CustomerModel extends ModelForm
{
    /**
     * @var string
     */
    public $context = "customer";
    /**
     * @var string
     */
    public $table_name = "customer";

    public function change_country_code_order($customer_id, $country_code)
    {
        $data = array(
            "id" => $customer_id,
            "countryname" => $country_code
        );
        $order = parent::save($data);
        return $order;
    }

    public function getItem($id = 0)
    {
        $customer =  parent::getItem($id); // TODO: Change the autogenerated stub
        $query= $this->_db->getQuery(true);
        if(!empty((array)$customer)) {
            $query->clear()
                ->select('country.countryname')
                ->from($this->getTableName('country').' AS country')
                ->where('country.phonecode='.(int)$customer->phonecode)
                ->where('country.countrycode='.$query->quote($customer->countrycode))
            ;
            $customer->country_name = $this->_db->setQuery($query)->loadResult();
        }

        return $customer;
    }

}
