<?php
namespace WpBookingEventAdmin\app\models;
defined('_WPBOOKINGEVENT_EXEC') or die;

use WpBookingEvent\Factory as FactoryAlias;
use WpBookingEvent\Mvc\Model\ModelForm;
use WpBookingEvent\Form\Form;
use WpBookingEvent\Mvc\Model\ModelList;
use WpBookingEvent\Registry\Registry;
use WpBookingEvent\Utilities\Utility as UtilityAlias;
class EventsModel extends ModelList
{
    /**
     * @var string
     */
    public $context = "events";
    /**
     * @var string
     */
    public $table_name = "event";
    public function getList()
    {

        $list = parent::getList();
        $db= FactoryAlias::getDBO();
        $query=$db->getQuery(true);
        foreach ($list as &$item) {
            $query->clear()
                ->select('order_detail.*')
                ->from(UtilityAlias::getTableName('order_detail').' AS order_detail ')
                ->where('order_detail.event_id=' . (int)$item->id);
            $list_order = $db->setQuery($query)->loadObjectList();
            $item->total_order = count($list_order);
        }
        return $list;
    }


}
