<?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 ItinerariesModel extends ModelList
{
    /**
     * @var string
     */
    public $context = "itineraries";
    /**
     * @var string
     */
    public $table_name = "itinerary";

    public function getListQuery()
    {

        $query=$this->db->getQuery(true);
        $query->select("a.*")
            ->from($this->getTableName().' AS a')

        ;
        $query->order('a.id desc');

        return $query;
    }

    public function getList()
    {
        $db=Factory::getDBO();
        $query=$this->getListQuery();

        $list_itinerary =  $db->setQuery($query)->loadObjectList();
        foreach ($list_itinerary as &$itinerary) {
            $query = $this->_db->getQuery(true);
            $query->clear()
                ->select('tour.name AS tour_name')
                ->from($this->getTableName('tour').' AS tour')
                ->where('tour.id='.(int)$itinerary->tour_id)
                ;
            $itinerary->tour_name=$this->_db->setQuery($query)->loadResult();
        }
        return $list_itinerary;
    }

}
