<?php
namespace WpBookingProAdmin\app\controllers;
use WpBookingPro\Factory;
use WpBookingPro\Mvc\Controller\Controller;
use WpBookingPro\Mvc\Controller\ControllerForm as ControllerFormAlias;
use WpBookingPro\Mvc\Model\Model;

defined('_WPBOOKINGPRO_EXEC') or die;
class UserController extends ControllerFormAlias
{
    public $view="user";
    public function delete($id = 0)
    {
        return parent::delete($id); // TODO: Change the autogenerated stub
    }

    public function check_old_user_pass() {
        if(!function_exists('wp_get_current_user')) {
            include(ABSPATH . "wp-includes/pluggable.php");
        }
        $input = Factory::getInput();
        $data = $input->getData();
        $modelUser = Model::getInstance('user');
        $check = $modelUser->checkOldUserPass($data);
        return $check;
    }

    public function ajax_change_role_user_wordpress() {
        if(!function_exists('wp_get_current_user')) {
            include(ABSPATH . "wp-includes/pluggable.php");
        }
        $input = Factory::getInput();
        $role_user_new = $input->getString('role_user_new','');
        $user_wp_id = $input->getInt('user_wp_id',0);
        $user_meta=get_userdata($user_wp_id);

        $user_role_old=$user_meta->roles[0]; //array of roles the user is part of.
        // NOTE: Of course change 3 to the appropriate user ID
        $u = new \WP_User( $user_wp_id );

        // Remove role
        $u->remove_role( $user_role_old);

        // Add role
        $u->add_role( $role_user_new);
    }
}
