<?php
namespace WpBookingProAdminWooPanel\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 PackagesModel extends ModelList
{
    /**
     * @var string
     */
    public $context = "packages";
    /**
     * @var string
     */
    public $table_name = "package";

    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;
    }

}
