<?php
namespace WpBookingProAdmin\app\models;
defined('_WPBOOKINGPRO_EXEC') or die;

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



    public function getList()
    {
        $input = Factory::getInput();
        $user_id  = $input->getInt('user_id',0);
        $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')
        ;
        if($user_id > 0) {
            $query->where('location.user_id='.(int)$user_id);
        }

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

    }

}
