Subversion Repositories SmartDukaan

Rev

Rev 10582 | Blame | Compare with Previous | Last modification | View Log | RSS feed

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


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

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

        function __construct() {
                
                // Call the Model constructor
                parent::__construct();
                //load appropriate parser
                $current_client =$this -> config -> item('current_client');
                $model = $current_client.'_model';
                $this->load->model($model);
                $this->parser = $this-> $model;
                
                
        }

        function index($get=array(),$post=array(),$module=array())
        {
                log_message('error', "in index ".print_r($get));                
                //add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
                $this->curlURL('products','get',$get);
                $responses = $this->mcurl->execute();
                $responses = $this->parser->parse_response($responses);
                return $responses;
        }

        function getProducts($get=array(),$post=array(),$module=array(), $itemcode ,$query)
        {
                $output =array();
                if(isset($module) and !empty($module))
                {
                        if(isset($module['header']) and !empty($module['header']))
                        {
                                foreach($module['header'] as $header)
                                {

                                        $this->curlURL($header,'get');
                                }
                        }
                        if(isset($module['footer']) and !empty($module['footer']))
                        {
                                foreach($module['footer'] as $footer)
                                {
                                        $this->curlURL($footer,'get');
                                }
                        }
                        if(isset($module['response']) and !empty($module['response']))
                        {
                                foreach($module['response'] as $response)
                                {
                                        
                                        if(isset($post) and !empty($post))
                                        {
                                                if($this->current_client=='magento' )
                                                $this->curlURL($response,'get',$post);
                                        else
                                                $this->curlURL($response,'get',$post);

                                        }
                                        else
                                        {
                                                log_message('error',"Befor CurlUrl ".print_r($get,1));  
                                                log_message('error',"Befor CurlUrl ".print_r($itemcode,1));     
                                                log_message('error',"Befor CurlUrl ".print_r($response,1));     
                                                log_message('error',"Befor CurlUrl ".print_r($get,1));  
                                                $this->curlURL($response,'get',$get,$itemcode,$query);
                                        }
                                }
                        }

                        
                }
                
                //add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
                //$this->curlURL('products','get',$get);
                $responses = $this->mcurl->execute();
                if(isset($responses) and !empty($responses))
                $responses = $this->parser->parse_response($responses,$module);
        
                
                return $responses;
        }
        function curlURL($configurl=null,$methodtype='get',$parameter=array(),$itemcode=null,$query=null) {
                $params ='';
                $display='';
                $url = $this->config->item('curl_base_url');
                $productsurl =$this->config->item($configurl);
                if(isset($productsurl['url']) and !empty($productsurl['url'])) {
                        $url .=$productsurl['url'];
                        if($productsurl['display']) {
                                $display=$productsurl['display'];
                        }
                        if(empty($parameter)){
                                $parameter=$productsurl['params'];
                        }
                        if(isset($parameter) and !empty($parameter) and $methodtype=='get'){
                                $params = $this->parser->prepareParams($parameter,$display);
                                log_message('error',"Params befor add_call".print_r($params,1));
                        }
                        if(isset($parameter) and !empty($parameter) and $methodtype=='post'){
                                $params = $this->parser->prepareParams($parameter,$display);
                                $methodtype ='post';
                        }
                        if(!isset($parameter) || empty($parameter)){
                                $params =$this->parser->prepareParams('',$display);
                        }
                        if(isset($itemcode) && $itemcode != null){
                                $url .= '/'.$itemcode;
                        }
                        if(isset($query) && $query != null){
                                $params = $query;
                        }
                        log_message('error',"Params befor add_call".print_r($parameter,1));
                        log_message('error',"Params befor add_call".print_r($params,1));
                        return $this->mcurl->add_call($configurl,$methodtype,$url,$params);
                }
                else {
                        return '';
                }
        }


        function nextProducts($get=array(),$post=array(),$module=array())
        {
                
                $output =array();
                if(isset($module) and !empty($module))
                {
                        if(isset($module['header']) and !empty($module['header']))
                        {
                                foreach($module['header'] as $header)
                                {

                                        $this->curlURL($header,'get');
                                }
                        }
                        if(isset($module['footer']) and !empty($module['footer']))
                        {
                                foreach($module['footer'] as $footer)
                                {
                                        $this->curlURL($footer,'get');
                                }
                        }
                        if(isset($module['response']) and !empty($module['response']))
                        {
                                foreach($module['response'] as $response)
                                {
                                        if(isset($get) and !empty($get))
                                        $this->curlURL($response,'get',$get);
                                
                                }
                        }

                        
                }
                
                //add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
                //$this->curlURL('products','get',$get);
                $responses = $this->mcurl->execute();
                //print_r($responses);
                if(isset($responses) and !empty($responses))
                $responses = $this->parser->parse_response($responses,$module);
        
                
                return $responses;
        }

}