<?php
class Tospur_House{

    public static function canApproval(){
        return current_user_can("houseApproval");
    }

    public static function getCurrentRole(){
        $current_user = wp_get_current_user();
        if ( !($current_user instanceof WP_User) )
            return;
        $roles = $current_user->roles;
        return $roles[0];
    }
    
    public static function list_status_upate($userType,$postStatus,$arrayParams){
        //首先判断是经理修改还是职业顾问做不同的操作，接着判断置业顾问是否修改了状态
        if($userType == 0){
            //经理
            //通过
            if($postStatus != -2){
                $arrayParams["status"] =$postStatus;
                $arrayParams["approval"] = -2;
            }else{
                //退回
                $arrayParams["approval"] = $postStatus;
            }
        }else{
            //置业顾问
            //修改了状态
            $currentStatus = SearchDao::getDetailInfo($_POST["userType"]);
            if($currentStatus["result"]->status != $postStatus){
                $arrayParams["approval"] = $postStatus;
            }else {
                //没有修改状态
                //没有申请审批
                if($currentStatus["result"]->approval == -2){
                    $arrayParams["approval"] = $currentStatus["result"]->status;
                }else{
                    //申请了审批，没有修改状态，approval保持原来的
                    $arrayParams["approval"] = $currentStatus["result"]->approval;
                }
            }
        }
        return $arrayParams;
    }
}