Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12694 anikendra 1
<?php
2
if (!defined('BASEPATH'))
3
	exit('No direct script access allowed');
4
 
5
 
6
/*
7
 * Model for home
8
 */ 
9
 
10
Class Product_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 ,$query)
40
	{
41
		$output =array();
42
		if(isset($module) and !empty($module))
43
		{
44
			if(isset($module['header']) and !empty($module['header']))
45
			{
46
				foreach($module['header'] as $header)
47
				{
48
 
49
					$this->curlURL($header,'get');
50
				}
51
			}
52
			if(isset($module['footer']) and !empty($module['footer']))
53
			{
54
				foreach($module['footer'] as $footer)
55
				{
56
					$this->curlURL($footer,'get');
57
				}
58
			}
59
			if(isset($module['response']) and !empty($module['response']))
60
			{
61
				foreach($module['response'] as $response)
62
				{
63
 
64
					if(isset($post) and !empty($post))
65
					{
66
						if($this->current_client=='magento' )
67
						$this->curlURL($response,'get',$post);
68
					else
69
						$this->curlURL($response,'get',$post);
70
 
71
					}
72
					else
73
					{
74
 
75
						$this->curlURL($response,'get',$get,$itemcode,$query);
76
					}
77
				}
78
			}
79
 
80
 
81
		}
82
 
83
		//add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
84
		//$this->curlURL('products','get',$get);
85
		$responses = $this->mcurl->execute();
86
		if(isset($responses) and !empty($responses))
87
		$responses = $this->parser->parse_response($responses,$module);
88
 
89
 
90
		return $responses;
91
	}
92
function curlURL($configurl=null,$methodtype='get',$parameter=array(),$itemcode=null,$query=null)
93
{
94
 
95
		$params ='';
96
		$display='';
97
		$url = $this->config->item('curl_base_url');
98
		$productsurl =$this->config->item($configurl);
99
		if(isset($productsurl['url']) and !empty($productsurl['url']))
100
			{
101
				$url .=$productsurl['url'];
102
				if($productsurl['display'])
103
				{$display=$productsurl['display'];}
104
			if(empty($parameter)){$parameter=$productsurl['params'];}
105
 
106
 
107
		if(isset($parameter) and !empty($parameter) and $methodtype=='get')
108
		{
109
			$params = $this->parser->prepareParams($parameter,$display,$configurl);
110
 
111
		}
112
		if(isset($parameter) and !empty($parameter) and $methodtype=='post')
113
		{
114
			$params = $this->parser->prepareParams($parameter,$display,$configurl);
115
			$methodtype ='post';
116
		}
117
		if(!isset($parameter) || empty($parameter))
118
			{$params =$this->parser->prepareParams('',$display,$configurl);}
119
		if(isset($itemcode) && $itemcode != null){
120
			$url .= '/'.$itemcode;
121
		}
122
		if(isset($query) && $query != null){
123
 
124
			$params = $query;
125
		}
126
		return $this->mcurl->add_call($configurl,$methodtype,$url,$params);
127
	}
128
	else
129
		{return '';}
130
 
131
}
132
 
133
 
134
	function nextProducts($get=array(),$post=array(),$module=array())
135
	{
136
 
137
		$output =array();
138
		if(isset($module) and !empty($module))
139
		{
140
			if(isset($module['header']) and !empty($module['header']))
141
			{
142
				foreach($module['header'] as $header)
143
				{
144
 
145
					$this->curlURL($header,'get');
146
				}
147
			}
148
			if(isset($module['footer']) and !empty($module['footer']))
149
			{
150
				foreach($module['footer'] as $footer)
151
				{
152
					$this->curlURL($footer,'get');
153
				}
154
			}
155
			if(isset($module['response']) and !empty($module['response']))
156
			{
157
				foreach($module['response'] as $response)
158
				{
159
					if(isset($get) and !empty($get))
160
					$this->curlURL($response,'get',$get);
161
 
162
				}
163
			}
164
 
165
 
166
		}
167
 
168
		//add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
169
		//$this->curlURL('products','get',$get);
170
		$responses = $this->mcurl->execute();
171
		//print_r($responses);
172
		if(isset($responses) and !empty($responses))
173
		$responses = $this->parser->parse_response($responses,$module);
174
 
175
 
176
		return $responses;
177
	}
178
 
179
}