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

use WpBookingPro\Factory;
use WpBookingPro\Mvc\Model\Model;
use WpBookingPro\Mvc\Model\ModelForm;
use WpBookingPro\Form\Form;
use WpBookingPro\Mvc\Model\ModelList;
use WpBookingPro\Registry\Registry;
class StatesModel extends ModelList
{
    /**
     * @var string
     */
    public $context = "states";
    /**
     * @var string
     */
    public $table_name = "state";
    public function getList()
    {
        if(is_user_logged_in()) {
            $modelUser = Model::getInstance('user');
            $user = $modelUser->getUserInfo();
            $query = $this->_db->getQuery(true);
            $query->clear()
                ->select('a.*')
                ->from($this->getTableName() . ' AS a')
                ->leftJoin($this->getTableName('country') . ' AS country ON country.id =a.country_id')
                ->select('country.countryname  AS country_name')
                ->where('a.user_id='.(int)$user->data->user_plugin->id)
            ;
            return $this->_db->setQuery($query)->loadObjectList();
        }
        return '';

    }


}
