<?php
namespace WpBookingHotelAdmin\app\models;
defined('_WPBOOKINGHOTEL_EXEC') or die;

use WpBookingHotel\Factory;
use WpBookingHotel\Mvc\Model\ModelForm;
use WpBookingHotel\Form\Form;
use WpBookingHotel\Mvc\Model\ModelList;
use WpBookingHotel\Registry\Registry;
class RoomtypesModel extends ModelList
{
    /**
     * @var string
     */
    public $context = "roomtypes";
    /**
     * @var string
     */
    public $table_name = "roomtype";
    public function getList()
    {
        $list_roomtype= parent::getList(); // TODO: Change the autogenerated stub
        $query =$this->db->getQuery(true);
        foreach ($list_roomtype as $roomtype){
            $query->clear()
                ->select('DISTINCT amenity.name')
                ->from($this->getTableName('amenity').' AS amenity')
                ->leftJoin($this->getTableName('roomtype_amenity').' AS roomtype_amenity ON roomtype_amenity.amenity_id = amenity.id')
                ->where('roomtype_amenity.roomtype_id ='.(int)$roomtype->id)
            ;
            $roomtype->list_amenity=$this->db->setQuery($query)->loadColumn();
        }

        return $list_roomtype;
    }
}
