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

use WpBookingEvent\Factory;
use WpBookingEvent\Mvc\Model\ModelForm;
use WpBookingEvent\Form\Form;
use WpBookingEvent\Mvc\Model\ModelList;
use WpBookingEvent\Registry\Registry;
class CategoriesModel extends ModelList
{
    /**
     * @var string
     */
    public $context = "categories";
    /**
     * @var string
     */
    public $table_name = "category";
    public function getList()
    {
        $list = parent::getList(); // TODO: Change the autogenerated stub
        $query = $this->db->getQuery(true);
        foreach ($list as &$item) {
            $query->clear()
                ->select('service.*')
                ->from($this->getTableName('service') . ' AS service')
                ->where('service.category_id=' . (int)$item->id)
                ->where('service.published=1')
            ;
            $item->list_service = $this->_db->setQuery($query)->loadObjectList();
        }
        return $list;
    }
}
