<?php
namespace TourOperatorProAdmin\app\helpers;

use TourOperatorPro\Factory;
use TourOperatorPro\Mvc\Model\Model as ModelAlias;
use TourOperatorPro\Mvc\Table\Table;
use TourOperatorPro\Registry\Registry;
use TourOperatorPro\Utilities\Utility;

class ConfigHelper extends AdminHelper
{
    public static function get_page_tour_detail(){
        $modelConfig = ModelAlias::getInstance('config');
        $item = $modelConfig->getItem(1);
        return $item->params->get('page_tour_detail',0);

    }
    public static function set_page_tour($page_id,$type){
        $modelConfig = ModelAlias::getInstance('config');
        $table = $modelConfig->getTable();
        $table->load(1);
        $params = $table->params;
        $reg = new Registry();
        $reg->loadString($params);
        $reg->set($type,$page_id);
        $table->params = $reg->toString();
        $table->store();
    }
    public static function get_page_tour_checkout(){
        $modelConfig = ModelAlias::getInstance('config');
        $item = $modelConfig->getItem(1);
        return $item->params->get('page_tour_checkout',0);

    }
    public static function get_page_list_tour(){
        $modelConfig = ModelAlias::getInstance('config');
        $item = $modelConfig->getItem(1);
        return $item->params->get('page_list_tour',0);

    }
    public static function get_page_list_tour_search_result(){
        $modelConfig = ModelAlias::getInstance('config');
        $item = $modelConfig->getItem(1);
        return $item->params->get('page_list_tour_search_result',0);

    }

    public static function create_create_page($view,$type)
    {
        $a_view=str_replace("-"," ",$view);
        $key_page=$a_view;
        $tour_detail = array(
            'post_name' => "$key_page",
            'post_title' => $key_page,
            'post_content' => '[touroperatorpro view="'.$view.'"]',
            'post_status' => "publish",
            'post_author' => get_current_user_id(),
            'post_type' => "page",
        );
        $post_id=wp_insert_post($tour_detail, '');
        self::set_page_tour($post_id,$type);
    }

}