Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

<?php
if (!defined('BASEPATH'))
        exit('No direct script access allowed');


/*
 * Model for home
 */ 
 
Class Prestashop_model extends CI_Model {

        var $url = '';
        var $parser_model;
        var $parser;

        function __construct() {
                
                // Call the Model constructor
                parent::__construct();
                //load appropriate parser
                
                
        }

        
function prepareParams($data=array(),$display=null,$configurl=null)
{
        if(isset($configurl) and $configurl=='product_list')
        {
                //category naming convetion
                if(isset($data['category'])) {$data['id_category_default']=$data['category']; unset($data['category']);}
        }
        if(isset($configurl) and $configurl=='login')
        {
                //category naming convetion
                unset($data['signin']);
                if(isset($data['passwd'])) {$data['passwd']= md5($this->config->item('hashkey').$data['passwd']);}
        }
        if(isset($configurl) and $configurl=='signup')
        {
                //category naming convetion
                unset($data['signup']);
                if(isset($data['passwd'])) {$data['passwd']= md5($this->config->item('hashkey').$data['passwd']);}
        }

        $newdata =array();
        if(isset($data) and !empty($data) and $configurl!='signup')
        {

                foreach($data as $key=>$d)
                {
                        if($key!=='sort')
                        {
                                $newdata['filter['.$key.']']='['.$d.']';
                        }

                }
        }
        if($configurl=='signup'){}
        
        if(isset($display) and !empty($display))
                {$newdata['display']=$display;}
        else
                {$newdata['display']='full';}
        
        $newdata['ws_key'] = $this->config->item('apikey');
        //return 'filter[price]=[300,5000]';
        //print_r($newdata);
        return $newdata;
}
function parse_response($responses=null,$module=array())
{
        
        $response=array();
        $data = $this->__xml_to_json($responses,$module);
        if(isset($data['header']) and !empty($data['header']))
        {
                $response['header']= $this->__parser_seperator($data['header']);

        }
        if(isset($data['footer']) and !empty($data['footer']))
        {
                $response['footer']= $this->__parser_seperator($data['footer']);

        }
        if(isset($data['response']) and !empty($data['response']))
        {
                $response['response']= $this->__parser_seperator($data['response']);

        }
        //print_r($response);
        return $response;
        
        
}
/*function parse_home_response($responses=null,$module=array())
{
        
        $response=array();
        $data = $this->__xml_to_json($responses,$module);
        if(isset($data['header']) and !empty($data['header']))
        {
                $response['header']= $this->__parser_seperator($data['header']);

        }
        if(isset($data['footer']) and !empty($data['footer']))
        {
                $response['footer']= $this->__parser_seperator($data['footer']);

        }
        if(isset($data['response']) and !empty($data['response']))
        {
                $response['response']= $this->__parser_seperator($data['response']);

        }
        //print_r($response);
        return $response;
        
        
}



function parse_productlist_response($responses=null,$module=array())
{
        $response=array();
        $data = $this->__xml_to_json($responses,$module);
        if(isset($data['header']) and !empty($data['header']))
        {
                $response['header']= $this->__parser_seperator($data['header']);

        }
        if(isset($data['footer']) and !empty($data['footer']))
        {
                $response['footer']= $this->__parser_seperator($data['footer']);

        }
        if(isset($data['response']) and !empty($data['response']))
        {
                $response['response']= $this->__parser_seperator($data['response']);

        }
        //print_r($response);
        return $response;

        
}

function parse_productinfo_response($responses=null,$module=array())
{
        $response=array();
        $data = $this->__xml_to_json($responses,$module);
        if(isset($data['header']) and !empty($data['header']))
        {
                $response['header']= $this->__parser_seperator($data['header']);

        }
        if(isset($data['footer']) and !empty($data['footer']))
        {
                $response['footer']= $this->__parser_seperator($data['footer']);

        }
        if(isset($data['response']) and !empty($data['response']))
        {
                $response['response']= $this->__parser_seperator($data['response']);

        }
        //print_r($response);
        return $response;
        
}
function parse_oauth_response($responses=null,$module=array())
{
        $response=array();
        $data = $this->__xml_to_json($responses,$module);
        
        if(isset($data['header']) and !empty($data['header']))
        {
                $response['header']= $this->__parser_seperator($data['header']);

        }
        if(isset($data['footer']) and !empty($data['footer']))
        {
                $response['footer']= $this->__parser_seperator($data['footer']);

        }
        if(isset($data['response']) and !empty($data['response']))
        {
                $response['response']= $this->__parser_seperator($data['response']);

        }
        //print_r($response);
        return $response;
        
}
*/
function __xml_to_json($responses=null,$module=array())
{
        $responseseperate =array();


        if(isset($module) and !empty($module))
                {
                        if(isset($module['header']) and !empty($module['header']))
                        {
                                foreach($module['header'] as $header)
                                {
                                        $i = $this->config->item($header);
                                        if(isset($i['url']))
                                        {$responseseperate['header'][$header][]=xml_to_json($responses[$header]['response'],array($header,''),array('id','language'));}
                                        $responseseperate['header'][$header]['render']=@$i['render'];
                                }
                        }
                        if(isset($module['footer']) and !empty($module['footer']))
                        {
                                foreach($module['footer'] as $footer)
                                {
                                        $i = $this->config->item($footer);
                                        if(isset($i['url']))
                                        {$responseseperate['footer'][$footer][]=xml_to_json($responses[$footer]['response'],array($footer,''),array('id','language'));}
                                        $responseseperate['footer'][$footer]['render']=@$i['render'];
                                }
                        }
                        if(isset($module['response']) and !empty($module['response']))
                        {
                                foreach($module['response'] as $response)
                                {
                                        $i = $this->config->item($response);
                                        if(isset($i['url']))
                                        {
                                                if(isset($responses[$response]['response']))
                                        $responseseperate['response'][$response][]=xml_to_json($responses[$response]['response'],array($response,''),array('id','language'));}
                                        $responseseperate['response'][$response]['render']=@$i['render'];
                                }
                        }

                        
                }
//xml_to_json(response from api,find route element),ignoreelement and replace with parent id)
                //print_r($responseseperate);
$response = $responseseperate;
//call parser and extract data as per requirement
return $response;

}

function __parser_seperator($data=array())
{
        $newarray =array();
        if(isset($data) and !empty($data))
        {
                foreach($data as $key=>$value)
                {
                        $newarray[$key] = $this->$key($value);
                }
        }
        return $newarray;
        
}


/*function top menu parser 
* menu category paramter
*id,parentid,menuname,position,render*/


function top_menu($data=array())
{

        $response =array();
        if(isset($data[0]) and !empty($data[0]))
        {
                foreach($data[0] as $d)
                {
                        if($d->id > 2)
                        {$childarray=array();
                        $childarray['id']=$d->id;
                        $childarray['parentid']=$d->id_parent;
                        $childarray['menuname']=$d->name;
                        $childarray['position']=$d->position;
                        if(array_key_exists($d->id_parent, $response))
                        {
                                $response[$d->id_parent]['child'][]=$childarray;
                        }
                        else
                        {
                        $response[$d->id][]=$childarray;
                        }
                        }


                }
                //print_r($response);

        }
        if(isset($data['render']) and !empty($data['render']))
                {$response['render']=$data['render'];}

        return $response;
}
/*function top menu parser 
* menu category paramter
*render*/

function search_bar($data=array())
{
        $response =array();
        
        if(isset($data['render']) and !empty($data['render']))
                {$response['render']=$data['render'];}

        return $response;
        
}
function breadcrumb($data=array())
{
        $response =array();
        
        if(isset($data['render']) and !empty($data['render']))
                {$response['render']=$data['render'];}

        return $response;
        
}

function authentication_bar($data=array())
{
        $response =array();
        
        if(isset($data['render']) and !empty($data['render']))
                {$response['render']=$data['render'];}

        return $response;
        
}
function social_bar($data=array())
{
        $response =array();
        
        if(isset($data['render']) and !empty($data['render']))
                {$response['render']=$data['render'];}

        return $response;
        
}
function subscribe_bar($data=array())
{
        $response =array();
        
        if(isset($data['render']) and !empty($data['render']))
                {$response['render']=$data['render'];}

        return $response;
        
}
function footer_link($data=array())
{
        $response =array();
        
        if(isset($data['render']) and !empty($data['render']))
                {$response['render']=$data['render'];}

        return $response;
        
}

//paramters for home banner - id,bannername,bannerimage,url
function home_banner($data=array())
{
        $response =array();
        if(isset($data[0]) and !empty($data[0]))
        {
                
                foreach($data[0] as $d)
                {
                        $childarray=array();
                        $childarray['id']=$d->id;
                        $childarray['bannername']=$d->name;
                        $childarray['bannerimage']=$d->id_default_image;
                        $childarray['url']=$d->id_category_default;
                        $response[]=$childarray;


                }

        }
        if(isset($data['render']) and !empty($data['render']))
                {$response['render']=$data['render'];}

        return $response;
}

function home_menu($data=array())
{

        $response =array();
        if(isset($data[0]) and !empty($data[0]))
        {
                foreach($data[0] as $d)
                {
                        if($d->id > 2)
                        {$childarray=array();
                        $childarray['id']=$d->id;
                        $childarray['parentid']=$d->id_parent;
                        $childarray['menuname']=$d->name;
                        $childarray['position']=$d->position;
                        if(array_key_exists($d->id_parent, $response))
                        {
                                $response[$d->id_parent]['child'][]=$childarray;
                        }
                        else
                        {
                        $response[$d->id][]=$childarray;
                        }
                        }


                }
                //print_r($response);

        }
        if(isset($data['render']) and !empty($data['render']))
                {$response['render']=$data['render'];}

        return $response;
}

//product list

function product_list($data=array())
{
        
        $response =array();
        if(isset($data[0]) and count($data[0]) > 1)
        {

                
                foreach($data[0] as $d)
                {
                        $childarray=array();
                        $childarray['id']=$d->id;
                        $childarray['productname']=$d->name;
                        $childarray['productprice']=$d->price;
                        $childarray['productimage']=$this->config->item('curl_base_url').'images/products/'.$d->id.'/'.$d->id_default_image;
                        $childarray['url']=base_url().'productinfo?id='.$d->id;
                        $response[]=$childarray;


                }

        }
        else
                {$response['error']='No Product Found!';}
        if(isset($data['render']) and !empty($data['render']))
                {$response['render']=$data['render'];}

        return $response;

}
function product_details($data=array())
{
        $response =array();
        if(isset($data[0]) and !empty($data[0]))
        {
                foreach($data[0] as $d)
                {
                        $childarray=array();
                        $childarray['id']=$d->id;
                        $childarray['category']=$d->id_category_default;
                        $childarray['productname']=$d->name;
                        $childarray['productprice']=$d->price;
                        $childarray['productimage']=$d->id_default_image;
                        $childarray['shortdescription']=$d->description_short;
                        $childarray['fulldescription']=$d->description;
                        $childarray['url']=$d->link_rewrite;
                        $response[]=$childarray;


                }

        }
        if(isset($data['render']) and !empty($data['render']))
                {$response['render']=$data['render'];}

        return $response;

}

function login($data=array())
{
        $response =array();
        if(isset($data[0]) and count($data[0]) == 0)
        {
                $response['redirect']='login';
                $response['msg']='Invalid Login Credential!';

        }
        if(isset($data[0][0]) and !empty($data[0][0]))
        {
                $inputdata =$data[0][0];
                if(isset($inputdata) and count($inputdata) ==0)
                {
                        $response['redirect']='login';
                        $response['msg']='Invalid Login Credential!';

                }
                else
                {
                        $response['authorized']=array('id'=>$inputdata->id,'fname'=>$inputdata->firstname,'lname'=>$inputdata->lastname,'email'=>$inputdata->email,'status'=>$inputdata->active);
                        $response['redirect']='home';
                        $response['msg']='Logged-in Successfully!';

                }
                

                
        
        }
        
        
        
        
        
        if(isset($data['render']) and !empty($data['render']))
                {$response['render']=$data['render'];}
        //print_r($response);
        return $response;
        
}
function signup($data=array())
{
        $response =array();
        if(isset($data[0]) and count($data[0]) == 0)
        {
                $response['redirect']='signup';
                $response['msg']='Invalid Signup Credential!';

        }
        if(isset($data[0][0]) and !empty($data[0][0]))
        {
                $inputdata =$data[0][0];
                

                $response['authorized']=array('id'=>$inputdata->id,'fname'=>$inputdata->firstname,'lname'=>$inputdata->lastname,'email'=>$inputdata->email);
                $response['redirect']='home';
                $response['msg']='Successfully Registered!';
        
        }
        
        
        
        
        if(isset($data['render']) and !empty($data['render']))
                {$response['render']=$data['render'];}
        //print_r($response);
        return $response;
        
}
function forgetpassword($data=array())
{
        $response =array();
        
        if(isset($data['render']) and !empty($data['render']))
                {$response['render']=$data['render'];}

        return $response;
        
}

function carts($data=array())
{
        $response =array();
        
        if(isset($data['render']) and !empty($data['render']))
                {$response['render']=$data['render'];}

        return $response;
        
}

function addcart($data=array())
{
        $response =array();
        
        //if added successfully
        //pass parameter as msg in response

        return $response;
        
}

function updatecart($data=array())
{
        $response =array();
        
        //if added successfully
        //pass parameter as msg in response

        return $response;
        
}

function deletecart($data=array())
{
        $response =array();
        
        //if added successfully
        //pass parameter as msg in response

        return $response;
        
}

function login_process($data=array())
{
        $response =array();
        
        if(isset($data['render']) and !empty($data['render']))
                {$response['render']=$data['render'];}

        return $response;
        
}
function shipping_process($data=array())
{
        $response =array();
        
        if(isset($data['render']) and !empty($data['render']))
                {$response['render']=$data['render'];}

        return $response;
        
}
function orderconfirmation_process($data=array())
{
        $response =array();
        
        if(isset($data['render']) and !empty($data['render']))
                {$response['render']=$data['render'];}

        return $response;
        
}
function billing_process($data=array())
{
        $response =array();
        
        if(isset($data['render']) and !empty($data['render']))
                {$response['render']=$data['render'];}

        return $response;
        
}
function payment_process($data=array())
{
        $response =array();
        
        if(isset($data['render']) and !empty($data['render']))
                {$response['render']=$data['render'];}

        return $response;
        
}




}