-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinventory_fetcher.php
More file actions
421 lines (351 loc) · 13.5 KB
/
inventory_fetcher.php
File metadata and controls
421 lines (351 loc) · 13.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Inventory Plugin
*
* Fetch specific types of inventory
*
* @package MDV_CMS
* @author MDV.com Dev Team
* @copyright Copyright (c) 2010 - 2011, MDV.com
*
* Usage: {pyro:inventory_fetcher:used limit="10"}
*
*/
class Plugin_inventory_fetcher extends Plugin
{
/**
* Private Variables
*/
private $mod_cms_vars;
private $mdv_db;
/**
* Plugin Constructor
*/
public function Plugin_inventory_fetcher()
{
// Connect to MDV DB
$this->mdv_db = $this->load->database( $this->config->item( 'mdvdb_creds' ), TRUE );
// Fetch certain CMS vars
$this->mod_cms_vars = extractVars( varsToExtract() );
// Extend CMS vars
$this->mod_cms_vars['skip_stock_vehicles'] = parseStr( '{pyro:variables:skip_stock_vehicles}' );
$this->mod_cms_vars['filtered_inventory_allowed'] = parseStr( '{pyro:variables:filtered_inventory_allowed}' );
$this->mod_cms_vars['merge_used_vehicles'] = parseStr( '{pyro:variables:merge_used_vehicles}' );
if( $this->mod_cms_vars['merge_used_vehicles'] != '' )
$this->mod_cms_vars['merge_used_vehicles'] = json_decode( $this->mod_cms_vars['merge_used_vehicles'] );
}
/**
* Used Inventory Fetcher
*
* @return used car inventory
*/
public function used()
{
// Fetch Attributes
$limit = $this->attribute( 'limit', 10 );
$only_html = $this->attribute( 'only_html', false );
$show_data = $this->attribute( 'show_data', false );
$skip_btn = $this->attribute( 'skip_btn', false );
// Determine if merging with other used inventory
$ids = $this->mod_cms_vars['mdv_ids'];
if( $this->mod_cms_vars['merge_used_vehicles']->merge )
{
$ids = explode( ",", $ids );
$ids = array_merge( $ids, $this->mod_cms_vars['merge_used_vehicles']->ids );
$ids = implode( ",", $ids );
}
// Prepare query
$sql = "SELECT * FROM `vehicles_available_to_viewer_final` WHERE `CLIENT_ID` IN (".$ids.") AND `CONDITION` IN ('used', 'certified')";
// Remove stock vehicles (if enabled)
if( $this->mod_cms_vars['skip_stock_vehicles'] == 'yes' )
$sql .= " AND `IOL_IMAGE` = '0'";
// Finish query
$sql .= " ORDER BY RAND() LIMIT ".$limit;
// Return Used vehicles
$results = $this->mdv_db->query( $sql );
$used_vehicles = $results->result_array();
/* NO LONGER USED, DELETE ON NEXT PUSH
// Return Used vehicles (all vehicles)
$used_vehicles = $this->mdv_db
->select( '*' )
->where( '`CLIENT_ID` IN ('.$this->mod_cms_vars['mdv_ids'].')' )
->where( '`CONDITION`', 'used' )
->order_by( '`VEH_ID`', 'random' )
->limit( $limit )
->get( 'vehicles_available_to_viewer_final' )
->result_array();*/
// Loop and Add extra field
$extended_used_vehicles = array();
foreach( $used_vehicles as $v )
{
// create vehicle link
$v['VEH_URL'] = $this->mod_cms_vars['base_url']."inventario/".createVehiclePermaLink( $this->mod_cms_vars,
array( 'ci' => $v['CLIENT_ID'],
'mk' => $v['MAKE'],
'md' => $v['MODEL'],
'tr' => $v['TRIM'],
'yr' => $v['YEAR'],
'vn' => substr( $v['VIN'], ( strlen( $v['VIN'] ) - 3 ) )
) );
// create image thumb path
$v['IMAGE_W_PATH'] = $this->config->item( 'images_base_url' ).( ( $v['IOL_IMAGE'] == 1 ) ? $this->config->item('iol_vehicle_pictures_thumb_path' ) : $this->config->item( 'vehicle_pictures_thumb_path' ) ).'thumb_'.$v['IMAGE'];
// create seo alt label
$v['SEO_VEH_LABEL'] = $v['MAKE']." ".$v['MODEL']." ".( ( $v['TRIM'] != "" ) ? $v['TRIM']." " : "" ).$v['YEAR']." — ".$this->mod_cms_vars['dealer_name'];
// create simple label
$v['SIMPLE_VEH_LABEL'] = $v['MAKE']." ".$v['MODEL'];
// save extension
array_push( $extended_used_vehicles, $v );
}
// Determine what to return
if( $only_html )
{
$html_to_return = "";
foreach( $extended_used_vehicles as $v )
{
// Href & Img
$a_href = '<a href="'.$v['VEH_URL'].'" title="'.$v['SEO_VEH_LABEL'].'">';
$img = '<img alt="'.$v['SEO_VEH_LABEL'].'" src="'.$v['IMAGE_W_PATH'].'" title="'.$v['SEO_VEH_LABEL'].'" />';
// Determine if data (year mke and model) is showing
if( $show_data )
{
$html_to_return .=
'<div class="box_result clearfix">
<div class="thumbs">
'.$a_href.$img.'</a>
</div>
<ul>
<li class="title">'.$a_href.$v['MAKE'].' '.$v['MODEL'].'</a></li>
<li class="year">'.$v['YEAR'].'</li>
</ul>
</div>';
}
else
{
$html_to_return .=
'<div class="thumb">
'.$a_href.$img.'</a>
</div>';
}
}
// add see all button
if( !$skip_btn )
{
$html_to_return .=
'<div class="btn_2"><a href="inventario?conditions=used" title="Vehículos Usados en '.parseStr( '{pyro:variables:dealer_inc_name}' ).'"></a></div>';
}
// return html
return $html_to_return;
}
return $extended_used_vehicles;
}
/**
* Similar Inventory Fetcher
*
* @return similar car inventory
*/
public function similar()
{
// Fetch Attributes
$limit = $this->attribute( 'limit', 10 );
$veh_id = $this->attribute( 'veh_id' );
$v_make = $this->attribute( 'make' );
$v_model = $this->attribute( 'model' );
$v_type = $this->attribute( 'type' );
// Determine if merging with other used inventory
$ids = $this->mod_cms_vars['mdv_ids'];
if( $this->mod_cms_vars['merge_used_vehicles']->merge )
{
$ids = explode( ",", $ids );
$ids = array_merge( $ids, $this->mod_cms_vars['merge_used_vehicles']->ids );
$ids = implode( ",", $ids );
}
// Prepare query
$sql = "SELECT * FROM `vehicles_available_to_viewer_final` WHERE `CLIENT_ID` IN (".$ids.") AND `VEH_ID` != ".$veh_id." AND `MAKE` LIKE '".$v_make."' AND `MODEL` LIKE '".$v_model."'";
// Remove stock vehicles (if enabled)
if( $this->mod_cms_vars['skip_stock_vehicles'] == 'yes' )
$sql .= " AND `IOL_IMAGE` = '0'";
// Restrict inventory (if enabled)
if( $this->mod_cms_vars['filtered_inventory_allowed'] != '' )
$sql .= " AND `CONDITION` IN (".$this->mod_cms_vars['filtered_inventory_allowed'].")";
// Finish query
$sql .= " ORDER BY RAND() LIMIT ".$limit;
// Return Used vehicles
$results = $this->mdv_db->query( $sql );
$similar_vehicles = $results->result_array();
/* NOT USED NO MORE, DELETE ON NEXT PUSH
$similar_vehicles = $this->mdv_db
->select( '*' )
->where( '`CLIENT_ID` IN ('.$this->mod_cms_vars['mdv_ids'].')' )
->where( '`VEH_ID` !=', $veh_id )
->like( '`MAKE`', $v_make )
->like( '`MODEL`', $v_model )
->order_by( '`VEH_ID`', 'random' )
->limit( $limit )
->get( 'vehicles_available_to_viewer_final' )
->result_array();*/
// Check to see if limit has been met
$curr_count = count( $similar_vehicles );
if( $curr_count < $limit )
{
// Prepare query
$sql = "SELECT * FROM `vehicles_available_to_viewer_final` WHERE `CLIENT_ID` IN (".$ids.") AND `VEH_ID` != ".$veh_id." AND `TYPE` LIKE '".$v_type."'";
// Remove stock vehicles (if enabled)
if( $this->mod_cms_vars['skip_stock_vehicles'] == 'yes' )
$sql .= " AND `IOL_IMAGE` = '0'";
// Restrict inventory (if enabled)
if( $this->mod_cms_vars['filtered_inventory_allowed'] != '' )
$sql .= " AND `CONDITION` IN (".$this->mod_cms_vars['filtered_inventory_allowed'].")";
// Finish query
$sql .= " ORDER BY RAND() LIMIT ".( $limit - $curr_count );
// Return Used vehicles
$results = $this->mdv_db->query( $sql );
$similar_vehicles = array_merge( $similar_vehicles, $results->result_array() );
/* NOT USED NO MORE, DELETE ON NEXT PUSH
$similar_vehicles = array_merge( $similar_vehicles,
$this->mdv_db
->select( '*' )
->where( '`CLIENT_ID` IN ('.$this->mod_cms_vars['mdv_ids'].')' )
->where( '`VEH_ID` !=', $veh_id )
->like( '`TYPE`', $v_type )
->order_by( '`VEH_ID`', 'random' )
->limit( ( $limit - $curr_count ) )
->get( 'vehicles_available_to_viewer_final' )
->result_array() );*/
}
// Loop and Add extra field
$extended_similar_vehicles = array();
foreach( $similar_vehicles as $v )
{
// create vehicle link
$v['VEH_URL'] = $this->mod_cms_vars['base_url']."inventario/".createVehiclePermaLink( $this->mod_cms_vars,
array( 'ci' => $v['CLIENT_ID'],
'mk' => $v['MAKE'],
'md' => $v['MODEL'],
'tr' => $v['TRIM'],
'yr' => $v['YEAR'],
'vn' => substr( $v['VIN'], ( strlen( $v['VIN'] ) - 3 ) )
) );
// create image thumb path
$v['IMAGE_W_PATH'] = $this->config->item( 'images_base_url' ).( ( $v['IOL_IMAGE'] == 1 ) ? $this->config->item('iol_vehicle_pictures_thumb_path' ) : $this->config->item( 'vehicle_pictures_thumb_path' ) ).'thumb_'.$v['IMAGE'];
$v['IMAGE_W_PATH_MED'] = $this->config->item( 'images_base_url' ).( ( $v['IOL_IMAGE'] == 1 ) ? $this->config->item('iol_vehicle_pictures_med_path' ) : $this->config->item( 'vehicle_pictures_med_path' ) ).'med_'.$v['IMAGE'];
// create seo alt label
$v['SEO_VEH_LABEL'] = $v['MAKE']." ".$v['MODEL']." ".( ( $v['TRIM'] != "" ) ? $v['TRIM']." " : "" ).$v['YEAR']." — ".$this->mod_cms_vars['dealer_name'];
// create simple label
$v['SIMPLE_VEH_LABEL'] = $v['MAKE']." ".$v['MODEL'];
// save extension
array_push( $extended_similar_vehicles, $v );
}
return $extended_similar_vehicles;
}
/**
* Determine if there are use cars, or not
*
* @return true or false
*/
public function used_inventory_present()
{
// Fetch Attributes
$force_true = $this->attribute( 'force_true', false );
$force_false = $this->attribute( 'force_false', false );
// Determine if merging with other used inventory
$ids = $this->mod_cms_vars['mdv_ids'];
if( $this->mod_cms_vars['merge_used_vehicles']->merge )
{
$ids = explode( ",", $ids );
$ids = array_merge( $ids, $this->mod_cms_vars['merge_used_vehicles']->ids );
$ids = implode( ",", $ids );
}
// Prepare query
$sql = "SELECT * FROM `vehicles_available_to_viewer_final` WHERE `CLIENT_ID` IN (".$ids.") AND `CONDITION` IN ('used', 'certified')";
// Remove stock vehicles (if enabled)
if( $this->mod_cms_vars['skip_stock_vehicles'] == 'yes' )
$sql .= " AND `IOL_IMAGE` = '0'";
// Finish query
$sql .= " ORDER BY RAND()";
// fetch results
$results = $this->mdv_db->query( $sql );
// determine what to return
if( $force_false == 'true' || $force_false == true )
return false;
else if ( $force_true == 'true' || $force_true == true )
return true;
else if( $results->num_rows() <= 0 )
return false;
else
return true;
}
/**
* Single Vehicle Inventory Fetcher
*
* @return single vehicle
*/
public function single()
{
// Fetch Attributes
$make = $this->attribute( 'make', false );
$model = $this->attribute( 'model', false );
$year = $this->attribute( 'year', false );
$limit = 1;
// Security check
if ( $make == false ) {
// we need at least a model
return false;
}
// Determine if merging with other used inventory
$ids = $this->mod_cms_vars['mdv_ids'];
if( $this->mod_cms_vars['merge_used_vehicles']->merge )
{
$ids = explode( ",", $ids );
$ids = array_merge( $ids, $this->mod_cms_vars['merge_used_vehicles']->ids );
$ids = implode( ",", $ids );
}
// Prepare query
$sql = "SELECT * FROM `vehicles_available_to_viewer_final` WHERE `CLIENT_ID` IN (".$ids.") AND `MAKE` LIKE '%".$make."%'";
// Specific model
if( $model != false )
$sql .= " AND `MODEL` LIKE '%".$model."%'";
// Specific year
if( $year != false )
$sql .= " AND `YEAR` = '".$year."'";
// Remove stock vehicles (if enabled)
if( $this->mod_cms_vars['skip_stock_vehicles'] == 'yes' )
$sql .= " AND `IOL_IMAGE` = '0'";
// Finish query
$sql .= " ORDER BY RAND() LIMIT ".$limit;
// Return Used vehicles
$results = $this->mdv_db->query( $sql );
$single_vehicle = $results->result_array();
// Check to see if limit has been met
$curr_count = count( $single_vehicle );
if( $curr_count < $limit )
{
// Prepare query
$sql = "SELECT * FROM `vehicles_available_to_viewer_final` WHERE `CLIENT_ID` IN (".$ids.") AND `MAKE` LIKE '%".$make."%'";
// Finish query
$sql .= " ORDER BY RAND() LIMIT ".$limit;
// Return Used vehicles
$results = $this->mdv_db->query( $sql );
$single_vehicle = $results->result_array();
}
// Loop and Add extra field
$v = $single_vehicle[0];
// create vehicle link
$v['VEH_URL'] = $this->mod_cms_vars['base_url']."inventario/".createVehiclePermaLink( $this->mod_cms_vars,
array( 'ci' => $v['CLIENT_ID'],
'mk' => $v['MAKE'],
'md' => $v['MODEL'],
'tr' => $v['TRIM'],
'yr' => $v['YEAR'],
'vn' => substr( $v['VIN'], ( strlen( $v['VIN'] ) - 3 ) )
) );
// create image thumb path
$v['IMAGE_W_PATH'] = $this->config->item( 'images_base_url' ).( ( $v['IOL_IMAGE'] == 1 ) ? $this->config->item('iol_vehicle_pictures_thumb_path' ) : $this->config->item( 'vehicle_pictures_thumb_path' ) ).'thumb_'.$v['IMAGE'];
$v['IMAGE_W_PATH_MED'] = $this->config->item( 'images_base_url' ).( ( $v['IOL_IMAGE'] == 1 ) ? $this->config->item('iol_vehicle_pictures_med_path' ) : $this->config->item( 'vehicle_pictures_med_path' ) ).'med_'.$v['IMAGE'];
// create seo alt label
$v['SEO_VEH_LABEL'] = $v['MAKE']." ".$v['MODEL']." ".( ( $v['TRIM'] != "" ) ? $v['TRIM']." " : "" ).$v['YEAR']." — ".$this->mod_cms_vars['dealer_name'];
// create simple label
$v['SIMPLE_VEH_LABEL'] = $v['MAKE']." ".$v['MODEL'];
return $v;
}
}
/* End of file session.php */