Subversion Repositories SmartDukaan

Rev

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 Search_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(),$query)
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
 
76
						$this->curlURL($response,'get',$get,$query);
77
					}
78
				}
79
			}
80
 
81
 
82
		}
83
 
84
		//add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
85
		//$this->curlURL('products','get',$get);
86
		$responses = $this->mcurl->execute();
87
		//print_r($responses);
88
		//die();
89
		if(isset($responses) and !empty($responses))
90
		$responses = $this->parser->parse_response($responses,$module);
91
 
92
 
93
		return $responses;
94
	}
95
function curlURL($configurl=null,$methodtype='get',$parameter=array(),$query=null)
96
{
97
 
98
		$params ='';
99
		$display='';
100
		$url = $this->config->item('curl_base_url');
101
		$productsurl =$this->config->item($configurl);
102
		if(isset($productsurl['url']) and !empty($productsurl['url']))
103
			{
104
				$url .=$productsurl['url'];
105
				if($productsurl['display'])
106
				{$display=$productsurl['display'];}
107
			if(empty($parameter)){$parameter=$productsurl['params'];}
108
 
109
 
110
		if(isset($parameter) and !empty($parameter) and $methodtype=='get')
111
		{
112
			$params = $this->parser->prepareParams($parameter,$display,$configurl);
113
 
114
		}
115
		if(isset($parameter) and !empty($parameter) and $methodtype=='post')
116
		{
117
			$params = $this->parser->prepareParams($parameter,$display,$configurl);
118
			$methodtype ='post';
119
		}
120
		if(!isset($parameter) || empty($parameter))
121
			{$params =$this->parser->prepareParams('',$display,$configurl);}
122
		if(isset($query) && $query != null){
123
 
124
			$params = $query;
125
		}
126
 
127
		return $this->mcurl->add_call($configurl,$methodtype,$url,$params);
128
	}
129
	else
130
		{return '';}
131
 
132
}
133
 
134
 
135
	function nextProducts($get=array(),$post=array(),$module=array())
136
	{
137
 
138
		$output =array();
139
		if(isset($module) and !empty($module))
140
		{
141
			if(isset($module['header']) and !empty($module['header']))
142
			{
143
				foreach($module['header'] as $header)
144
				{
145
 
146
					$this->curlURL($header,'get');
147
				}
148
			}
149
			if(isset($module['footer']) and !empty($module['footer']))
150
			{
151
				foreach($module['footer'] as $footer)
152
				{
153
					$this->curlURL($footer,'get');
154
				}
155
			}
156
			if(isset($module['response']) and !empty($module['response']))
157
			{
158
				foreach($module['response'] as $response)
159
				{
160
					if(isset($get) and !empty($get))
161
					$this->curlURL($response,'get',$get);
162
 
163
				}
164
			}
165
 
166
 
167
		}
168
 
169
		//add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
170
		//$this->curlURL('products','get',$get);
171
		$responses = $this->mcurl->execute();
172
		//print_r($responses);
173
		if(isset($responses) and !empty($responses))
174
		$responses = $this->parser->parse_response($responses,$module);
175
 
176
 
177
		return $responses;
178
	}
179
 
180
}