<?php

CMA_UserRelatedQuestions::bootstrap();
class CMA_UserRelatedQuestions
{
    static function bootstrap()
    {
        add_action('add_meta_boxes', array(__CLASS__, 'add_meta_boxes'));
        add_action('save_post', array(__CLASS__, 'save_post'), 10, 1);
    }
    static function add_meta_boxes()
    {
        if (CMA_Settings::getOption(CMA_Settings::OPTION_USER_RELATED_QUESTIONS_ENABLE)) {
            add_meta_box('cma-user-related-questions', 'User Related Questions', array(__CLASS__, 'render_meta_box'), CMA_Thread::POST_TYPE, 'normal', 'high');
        }
    }
    static function render_meta_box($post)
    {
        wp_enqueue_style('cma-backend', CMA_RESOURCE_URL . 'backend.css');
        wp_enqueue_script('cma-admin-script', CMA_RESOURCE_URL . 'admin_script.js');
        if ($thread = CMA_Thread::getInstance($post)) {
            $questions = $thread->getUserRelatedQuestions(false);
        } else {
            $questions = array();
        }
        $nonce = wp_create_nonce(__CLASS__);
        include CMA_PATH . '/views/backend/hooks/user_related_questions_metabox.phtml';
    }
    static function save_post($postId)
    {
        if ($thread = CMA_Thread::getInstance($postId) and self::save_post_verify_nonce()) {