<?php
defined('_WPBOOKINGPRO_EXEC') or die;
if(!class_exists("WpBookingPro_BookingController")) {
    /**
     * Class WpBookingPro_BookingController
     */
    class WpBookingPro_BookingController extends woobooking_controller
    {
        /**
         * @return mixed
         * @throws Exception
         */
        public function ajax_get_item()
        {
            return self::view("event.form");
        }

        /**
         * @return mixed
         * @throws Exception
         */
        public function ajax_add_new_event()
        {
            //TODO check permission add new
            return self::view("event.form");
        }

        /**
         * @param string $data_post
         * @return array|bool|mixed|stdClass
         * @throws Exception
         */
        public function ajax_save($data_post = "")
        {
            $input = Factory::getInput();
            if (!$data_post) {
                $data_post = $input->getData()['data'];
            }
            if (count($data_post['rates']) > 1) {
                $data_post['rates'] = implode(';', $data_post['rates']);
            } else {
                $data_post['rates'] = reset($data_post['rates']);
            }
            $data_post = parent::save($data_post); // TODO: Change the autogenerated stub
            $response = new stdClass();
            $response->data = $data_post;
            $this->item = (object)$data_post;
            $this->view = 'event';
            ob_start();
            $this->loadTemplate('list_item');
            $response->html_item = ob_get_clean();
            return $response;
        }
    }
}
?>