<?php

class OrderHelper{

    public static function convertInToStatus($data){
        $ctx = &get_instance();
        $list = $ctx->mOrder->getList();
        if(is_array($data)){
            foreach ($list as $k1 => $val){
                foreach ($data as $k2 => $input){
                    if($val['id']==$input){
                        $data[$k2] = $val['label'] ;
                    }
                }
            }
        }else{
            foreach ($list as $k1 => $val){
                if($val['id']==$val){
                    return $val['label'] ;
                }
            }
        }
        return $data;
    }

    public static function variantsBuilderString($variants){

        $string = "";

        if(!is_array($variants))
            $variants = json_decode($variants);

        if(!empty($variants))
            $string = "<br />";


        foreach ($variants as $grp_label => $options){

            $options = json_encode($options);
            $options = json_decode($options,JSON_OBJECT_AS_ARRAY);

            if(!empty($options))
                $string .= '&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;'.$grp_label.':<br/>';

            echo "</pre>";
               foreach ($options as $key => $value){
                   $string .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i>".$key."</i><br />";
                }
        }

        return $string;
    }

}


function parseUrlParam($key){

    if(RequestInput::get($key)=="")
        return array();

    if(!preg_match("#,#",RequestInput::get($key)))
        return array(RequestInput::get($key));

    $sc = explode(",",RequestInput::get($key));
    $sc = array_map('trim',$sc);
    return $sc;
}