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