Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested select combo issue #76

Open
mangopik opened this issue Jul 5, 2015 · 1 comment
Open

Nested select combo issue #76

mangopik opened this issue Jul 5, 2015 · 1 comment
Labels
Milestone

Comments

@mangopik
Copy link
Owner

mangopik commented Jul 5, 2015

after select parent , child select did not filtered with parent id selected

@mangopik mangopik added the bug label Jul 5, 2015
@mangopik
Copy link
Owner Author

mangopik commented Jul 5, 2015

Fix it by following step

Step 1

Edit file protected/app/library/SiteHelpers.php and replace function createPreCombo() as following code

    public static function createPreCombo( $field , $table , $key ,  $val ,$app ,$class ,$lookey = null)
    {   
        $parent = null;
        $parent_field = null;
        if($lookey != null)  
        {   
            $parent = " parent: '#".$lookey."',";
            $parent_field =  "&parent={$lookey}:";
        }   
        $pre_jCombo = "
        \$(\"#{$field}\").jCombo(\"{{ URL::to('{$class}/comboselect?filter={$table}:{$key}:{$val}') }}$parent_field\",
        { ".$parent." selected_value : '{{ \$row[\"{$field}\"] }}' });
        ";  
        return $pre_jCombo;
    }   

Step 2

Edit file protected/app/controllers/BaseController.php and replace function getComboSelect()

    function getComboselect()
    {

        if(Request::ajax() == true && Auth::check() == true)
        {
            $param = explode(':',Input::get('filter'));
            $parent = (!is_null(Input::get('parent')) ? Input::get('parent') : null);
            $limit = (!is_null(Input::get('limit')) ? Input::get('limit') : null);
            $rows = $this->model->getComboselect($param,$limit,$parent);
            $items = array();

            $fields = explode("|",$param[2]);

            foreach($rows as $row) 
            {
                $value = "";
                foreach($fields as $item=>$val)
                {
                    if($val != "") $value .= $row->$val." ";
                }
                $items[] = array($row->$param['1'] , $value);   

            }

            return json_encode($items);     
        } else {
            return json_encode(array('OMG'=>" Ops .. Cant access the page !"));
        }   
    }

Step 3
Edit file protected/app/models/BaseModel.php and replace function getComboSelect()

    static function getComboselect( $params , $limit =null, $parent = null)
    {   
        $limit = explode(':',$limit);
        $parent = explode(':',$parent);

        if(count($limit) >=3)
        {
            $table = $params[0]; 
            $condition = $limit[0]." `".$limit[1]."` ".$limit[2]." ".$limit[3]." "; 
            if(count($parent)>=2 )
            {

                 $row =  DB::select( "SELECT * FROM ".$table." ".$condition ." AND ".$parent[0]." = '".$parent[1]."'");
            } else  {
               $row =  DB::select( "SELECT * FROM ".$table." ".$condition);
            }        
        }else{

            $table = $params[0]; 
            if(count($parent)>=2 )
            {
                $row =  DB::table($table)->where($parent[0],$parent[1])->get();
            } else  {
                $row =  DB::table($table)->get();
            }              
        }

        return $row;
    }  

@mangopik mangopik added this to the Version 3.2 milestone Jul 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant