-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMerlinUtils.php
More file actions
73 lines (59 loc) · 1.78 KB
/
MerlinUtils.php
File metadata and controls
73 lines (59 loc) · 1.78 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
<?php
/**
* Class MerlinUtils
*
* Defines data models for use between Magento, Merlin, CEMI, Pace, etc.
* @author rkomatz
**/
class MerlinUtils
{
/*------------------------------------------------
Constructor Method
-------------------------------------------------*/
/**
* MerlinUtils is a set of utility functions for the Merlin class and subclasses.
*/
public function __construct()
{
}
/*------------------------------------------------
Protected Methods
-------------------------------------------------*/
/**
* Generates a select statement based on 'columnName' => 'tableName' and gives you sanitized values `tableName`.`columnName`.
* @param $columnArray
* @return string
*/
protected function selectCols($columnArray)
{
$cols = array();
foreach ($columnArray as $k => $v)
{
$cols[] = "`".$v."`.`".$k."`";
}
return implode(', ', $cols);
}
/**
* Generates a MySQL WHERE statement based on $filterArray('columnName' => 'value'). Statement
* defaults to "OR" query, but "AND" may be passed as $whereType argument.
* @param $filterArray
* @param null $whereType
* @return string
*/
protected function where($filterArray, $whereType = null)
{
if (is_null($filterArray)) return;
if ($whereType === null)
$whereType = "OR";
elseif (strtoupper($whereType) !== "AND" && strtoupper($whereType) !== "OR")
return;
$whereType = ' '.strtoupper($whereType).' ';
foreach ($filterArray as $k => $v)
{
$cols[] = "`".str_replace('.', '`.`', $k)."`='".$v."'";
}
$where = " WHERE ".implode($whereType, $cols);
return $where;
}
}
?>