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 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
					$cache = getFileCache($header);
51
					if(isset($cache) && !empty($cache)){
52
						$head['header'][$header] = $cache;
53
					}else{
54
						$this->curlURL($header,'get');	
55
					}
56
				}
57
			}
58
			if(isset($module['footer']) and !empty($module['footer']))
59
			{
60
				foreach($module['footer'] as $footer)
61
				{
62
					$cache = getFileCache($footer);
63
					if(isset($cache) && !empty($cache)){
64
						$foot['footer'][$footer] = $cache;
65
					}else{
66
						$this->curlURL($footer,'get');	
67
					}
68
				}
69
			}
70
			if(isset($module['response']) and !empty($module['response']))
71
			{
72
				foreach($module['response'] as $response)
73
				{
74
 
75
					if(isset($post) and !empty($post))
76
					{
77
						if($this->current_client=='magento' )
78
						$this->curlURL($response,'get',$post);
79
					else
80
						$this->curlURL($response,'get',$post);
81
 
82
					}
83
					else
84
					{
85
						$this->curlURL($response,'get',$get,$itemcode);
86
					}
87
				}
88
			}
89
		}
90
		//add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
91
		//$this->curlURL('products','get',$get);
92
		$responses = $this->mcurl->execute();
93
		if(isset($responses) and !empty($responses))
94
		$responses = $this->parser->parse_response($responses,$module);
95
 
96
		if(isset($head) && !empty($head)){
97
			foreach($head['header'] as $key=>$value){
98
				$responses['header'][$key] = $value;
99
			}
100
		}
101
		if(isset($foot) && !empty($foot)){
102
			foreach($foot['footer'] as $key=>$value){
103
				$responses['footer'][$key] = $value;
104
			}
105
		}
106
		return $responses;
107
	}
108
function curlURL($configurl=null,$methodtype='get',$parameter=array(),$itemcode=null)
109
{
110
		$params ='';
111
		$display='';
112
		$url = $this->config->item('curl_base_url');
113
		$productsurl =$this->config->item($configurl);
114
		if(isset($productsurl['url']) and !empty($productsurl['url']))
115
			{
116
				$url .=$productsurl['url'];
117
				if($productsurl['display'])
118
				{$display=$productsurl['display'];}
119
			if(empty($parameter)){$parameter=$productsurl['params'];}
120
 
121
 
122
		if(isset($parameter) and !empty($parameter) and $methodtype=='get')
123
		{
124
			print_r($parameter);
125
			$params = $this->parser->prepareParams($parameter,$display,$configurl);
126
 
127
		}
128
		if(isset($parameter) and !empty($parameter) and $methodtype=='post')
129
		{
130
			$params = $this->parser->prepareParams($parameter,$display,$configurl);
131
			$methodtype ='post';
132
		}
133
		if(!isset($parameter) || empty($parameter))
134
			{$params =$this->parser->prepareParams('',$display,$configurl);}
135
		if(isset($itemcode) && $itemcode != null){
136
			$url .= '/'.$itemcode;
137
		}
138
 
139
		return $this->mcurl->add_call($configurl,$methodtype,$url,$params);
140
	}
141
	else
142
		{return '';}
143
 
144
}
145
 
146
}