<?php
namespace WpBookingEventFrontend\app\models;
defined('_WPBOOKINGEVENT_EXEC') or die;

use WpBookingEvent\Factory;
use WpBookingEvent\Mvc\Model\ModelForm;
use WpBookingEvent\Form\Form;
use WpBookingEvent\Mvc\Model\ModelList;
use WpBookingEvent\Registry\Registry;
class LocationsModel extends ModelList
{
    /**
     * @var string
     */
    public $context = "locations";
    /**
     * @var string
     */
    public $table_name = "location";
    public function getList()
    {

        $db = Factory::getDBO();
        $query = $db->getQuery(true)
            ->select("location.*")
            ->from($this->getTableName('location').' AS location')
            ->leftJoin($this->getTableName('state').' AS state ON state.id=location.state_id')
            ->select('state.name AS state_name')
            ->leftJoin($this->getTableName('country'). ' AS country ON country.id=state.country_id')
            ->select('country.countryname AS country_name')
        ;

        return $db->setQuery($query)->loadObjectList();

    }

}
