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

        /**
         * @return mixed
         * @throws Exception
         */
        public function getListServiceCategory()
        {
            $db = Factory::getDBO();
            $query = $db->getQuery(true);
            $modelCategories = $this->getModel('categories');
            $list_service_category = $modelCategories->getList();
            foreach ($list_service_category as &$category) {
                $query->clear()
                    ->select('service.*')
                    ->from(WoobookingTable::getWBTable('service') . ' AS service')
                    ->where('category_id=' . $category->id)
                    ->order('ordering');
                $category->list_service = $db->setQuery($query)->loadObjectList();
                $query->clear()
                    ->select('extra.*')
                    ->from(WoobookingTable::getWBTable('extra') . ' AS extra')
                    ->where('object_id=' . $category->id)
                    ->where('type=' . $query->quote('service'));
                $category->extra = $db->setQuery($query)->loadObjectList();
            }
            return $list_service_category;
        }
        public function getList()
        {
            $db = Factory::getDBO();
            $query = $db->getQuery(true)
                ->select("*")
                ->from(self::getTableName());
            return $db->setQuery($query)->loadObjectList();
        }
    }
}