<?php

class introduction
{
    public static function ajax_submit_introduction()
    {
        $introduction = $_POST['introduction'];
        $user_id = $_POST['user_id'];
        wp_send_json(introduction::submit_introduction($introduction, $user_id));
    }

    public static function submit_introduction($introduction, $user_id)
    {
        global $wpdb;
        $result = $wpdb->update(
            Config::TOSPUR_CONSULTANT,
            array(
                'introduction' => $introduction
            ),
            array('id' => $user_id)
        );
        return $result;
    }

    public static function search_introduction()
    {
        global $wpdb;
        $user_id = introduction::get_user_id();
        $sql = "select introduction from " . Config::TOSPUR_CONSULTANT . " where id = " . $user_id;
        $result = $wpdb->get_var($sql);
        return $result;
    }

    public static function introduction_html()
    {
        $context = array();
        $context['url'] = home_url();
        $context['introduction'] = introduction::search_introduction();
        $user_id = introduction::get_user_id();
        $context['user_id'] = $user_id;
        Timber::render('introduction.html', $context);
    }

    public static function get_user_id()
    {
        $current_user = wp_get_current_user();
        return $current_user->ID;
    }
}

?>