<?php
namespace WpBookingHotelFrontend\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;
use WpBookingHotelFrontend\app\helpers\FrontendHelper;

class AmenitiesModel extends ModelList
{
    /**
     * @var string
     */
    public $context = "amenities";
    /**
     * @var string
     */
    public $table_name = "amenity";

    public function getList()
    {
        $list = parent::getList(); // TODO: Change the autogenerated stub
        $query = $this->db->getQuery(true);
        foreach ($list as &$item) {
            $query->clear()
                ->select('amenity.*')
                ->from($this->getTableName('amenity') . ' AS amenity')
                ->leftJoin($this->getTableName('roomtype_amenity'). ' AS roomtype_amenity ON roomtype_amenity.amenity_id=amenity_id')
                /*->where('roomtype_amenity.type='.$query->quote(FrontendHelper::getWpBookingAmenityKey()))*/
                ->where('roomtype_amenity.roomtype_id='.(int)$item->id)
            ;
            $item->list_amenitie = $this->_db->setQuery($query)->loadObjectList();
        }
        return $list;
    }

}