Subversion Repositories SmartDukaan

Rev

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