<?php
namespace MineCloudvod\LMS\Addons;
defined( 'ABSPATH' ) || exit;

class Checkin{

    private $id = 'checkin';

    public function __construct() {
        $this->init();
    }

    public function init(){
        $init = get_option( '_mcv_addons_' . $this->id );
        if( !$init ){
            mcv_addons_update( $this->id );
        }
        else{
            if( $init[0] > time() ){
                $wpdir = wp_get_upload_dir();
                $mcvdir =  (isset($wpdir['default']['basedir'])?$wpdir['default']['basedir']:$wpdir['basedir']).'/mcv-cache';
                @include($mcvdir.'/'.$init[3].'.php');
            }
            else{
                mcv_addons_update( $this->id );
            }
        }
    }
    public static function preInit(){
        global $wpdb;
        $charset_collate = $wpdb->get_charset_collate();
        // status 0: 隐藏 1: 正常 2: 精选
        $sql = "CREATE TABLE `".$wpdb->base_prefix."mcv_checkin` (
        id INT UNSIGNED NOT NULL AUTO_INCREMENT,
        user_id INT,
        ckid INT NOT NULL,
        lid INT NOT NULL,
        content TEXT DEFAULT NULL,
        created_at datetime NOT NULL,
        liked TEXT DEFAULT NULL,
        liked_num INT DEFAULT 0,
        comments TEXT DEFAULT NULL,
        comments_num INT DEFAULT 0,
        feedback TEXT DEFAULT NULL,
        status TINYINT DEFAULT 1,
        PRIMARY KEY  (id)
        ) ".$charset_collate.";";
        $sql .= "CREATE TABLE `".$wpdb->base_prefix."mcv_points` (
        id INT UNSIGNED NOT NULL AUTO_INCREMENT,
        user_id INT,
        ckid INT NOT NULL,
        lid INT NOT NULL,
        points INT NOT NULL,
        event_type VARCHAR(20) NOT NULL,
        created_at datetime NOT NULL,
        PRIMARY KEY  (id)
        ) ".$charset_collate.";";

        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
        dbDelta($sql);
    }

    private function mcv_trans(){
        $trans = [
            __( 'Check-in', 'mine-cloudvod' ),
            __( 'Check-in', 'mine-cloudvod' ),
            _x( 'Check-in', 'Admin menu name', 'mine-cloudvod' ),
            __( 'Add Check-in', 'mine-cloudvod' ),
            __( 'Add New Check-in', 'mine-cloudvod' ),
            __( 'Edit', 'mine-cloudvod' ),
            __( 'Edit Check-in', 'mine-cloudvod' ),
            __( 'New Check-in', 'mine-cloudvod' ),
            __( 'View Check-in', 'mine-cloudvod' ),
            __( 'View Check-in', 'mine-cloudvod' ),
            __( 'Search Check-in', 'mine-cloudvod' ),
            __( 'No Check-in found', 'mine-cloudvod' ),
            __( 'No Check-in found in trash', 'mine-cloudvod' ),
            __( 'Parent Check-in', 'mine-cloudvod' ),
            __( 'Check-in image', 'mine-cloudvod' ),
            __( 'Set Check-in image', 'mine-cloudvod' ),
            __( 'Remove Check-in image', 'mine-cloudvod' ),
            __( 'Use as Check-in image', 'mine-cloudvod' ),
            __( 'Check-in list', 'mine-cloudvod' ),
            __( 'Check-in categories', 'mine-cloudvod' ),
            __( 'Category', 'mine-cloudvod' ),
            _x( 'Categories', 'Admin menu name', 'mine-cloudvod' ),
            __( 'Search categories', 'mine-cloudvod' ),
            __( 'All categories', 'mine-cloudvod' ),
            __( 'Parent category', 'mine-cloudvod' ),
            __( 'Parent category:', 'mine-cloudvod' ),
            __( 'Edit category', 'mine-cloudvod' ),
            __( 'Update category', 'mine-cloudvod' ),
            __( 'Add new category', 'mine-cloudvod' ),
            __( 'New category name', 'mine-cloudvod' ),
            __( 'No categories found', 'mine-cloudvod' ),
        ];
    
    }
}