Subversion Repositories SmartDukaan

Rev

Rev 11049 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
10582 lgm 1
<?php
2
if (!defined('BASEPATH'))
3
	exit('No direct script access allowed');
4
 
5
 
6
/*
7
 * Model for home
8
 */ 
9
 
10
Class Productinfo_model extends CI_Model {
11
 
12
	var $url = '';
13
	var $parser_model;
14
	var $parser;
15
 
16
	function __construct() {
17
 
18
		// Call the Model constructor
19
		parent::__construct();
20
		//load appropriate parser
21
		$current_client =$this -> config -> item('current_client');
22
		$model = $current_client.'_model';
23
		$this->load->model($model);
24
		$this->parser = $this-> $model;
25
 
26
 
27
	}
28
 
29
	function index($get=array(),$post=array(),$module=array())
30
	{
31
 
32
		//add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
33
		$this->curlURL('products','get',$get);
34
		$responses = $this->mcurl->execute();
35
		$responses = $this->parser->parse_response($responses);
36
		return $responses;
37
	}
38
 
39
	function getProducts($get=array(),$post=array(),$module=array(),$itemcode)
40
	{
41
 
42
		$output =array();
43
		if(isset($module) and !empty($module))
44
		{
45
			if(isset($module['header']) and !empty($module['header']))
46
			{
47
				foreach($module['header'] as $header)
48
				{
49
 
50
					$this->curlURL($header,'get');
51
				}
52
			}
53
			if(isset($module['footer']) and !empty($module['footer']))
54
			{
55
				foreach($module['footer'] as $footer)
56
				{
57
					$this->curlURL($footer,'get');
58
				}
59
			}
60
			if(isset($module['response']) and !empty($module['response']))
61
			{
62
				foreach($module['response'] as $response)
63
				{
64
 
65
					if(isset($post) and !empty($post))
66
					{
67
						if($this->current_client=='magento' )
68
						$this->curlURL($response,'get',$post);
69
					else
70
						$this->curlURL($response,'get',$post);
71
 
72
					}
73
					else
74
					{
75
						//echo "inside if";
76
						$this->curlURL($response,'get',$get,$itemcode);
77
					}
78
				}
79
			}
80
		}
81
		//add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
82
		//$this->curlURL('products','get',$get);
83
		$responses = $this->mcurl->execute();
84
		if(isset($responses) and !empty($responses))
85
		$responses = $this->parser->parse_response($responses,$module);
86
 
87
 
88
		return $responses;
89
	}
90
function curlURL($configurl=null,$methodtype='get',$parameter=array(),$itemcode=null)
91
{
92
		$params ='';
93
		$display='';
94
		$url = $this->config->item('curl_base_url');
95
		$productsurl =$this->config->item($configurl);
96
		if(isset($productsurl['url']) and !empty($productsurl['url']))
97
			{
98
				$url .=$productsurl['url'];
99
				if($productsurl['display'])
100
				{$display=$productsurl['display'];}
101
			if(empty($parameter)){$parameter=$productsurl['params'];}
102
 
103
 
104
		if(isset($parameter) and !empty($parameter) and $methodtype=='get')
105
		{
106
			print_r($parameter);
107
			$params = $this->parser->prepareParams($parameter,$display,$configurl);
108
 
109
		}
110
		if(isset($parameter) and !empty($parameter) and $methodtype=='post')
111
		{
112
			$params = $this->parser->prepareParams($parameter,$display,$configurl);
113
			$methodtype ='post';
114
		}
115
		if(!isset($parameter) || empty($parameter))
116
			{$params =$this->parser->prepareParams('',$display,$configurl);}
117
		if(isset($itemcode) && $itemcode != null){
118
			$url .= '/'.$itemcode;
119
		}
120
 
121
		return $this->mcurl->add_call($configurl,$methodtype,$url,$params);
122
	}
123
	else
124
		{return '';}
125
 
126
}
127
 
128
}