<?php
defined('_WPBOOKINGPRO_EXEC') or die;
if(!class_exists("WpBookingPro_PackagesModel")) {
    /**
     * Class WpBookingPro_PackagesModel
     */
    class WpBookingPro_PackagesModel extends WoobookingModelList
    {
        /**
         * @var string
         */
        public $context = "packages";
        /**
         * @var string
         */
        public $table_name = "package";

        /**
         * @return mixed
         */
        public function getList()
        {
            $list = parent::getList(); // TODO: Change the autogenerated stub
            foreach ($list as &$item) {
                $db = Factory::getDBO();
                $query = $db->getQuery(true);
                $query->clear()
                    ->select('event.*')
                    ->from($this->getTableName('event') . ' AS event')
                    ->leftJoin($this->getTableName('package_event') . ' AS package_event ON package_event.event_id=event.id')
                    ->where('package_event.package_id=' . (int)$item->id);
                $item->list_event = $db->setQuery($query)->loadObjectList();
            }
            return $list;
        }

        /**
         * @return array
         */
        public function getHeader()
        {
            return array();
        }
    }
}