MCPcopy Create free account
hub / github.com/EqualifyEverything/equalify / filters

Method filters

models/db.php:80–195  ·  view source on GitHub ↗

* Filters helper. * @param array filters * [ array ('name' => $name, 'value' => $value, * 'operator' => '=', 'condition' => 'AND', 'type' = '' ) ] */

($filters)

Source from the content-addressed store, hash-verified

78 * 'operator' => '=', 'condition' => 'AND', 'type' = '' ) ]
79 */
80 private static function filters($filters){
81
82 // Our goal is to output SQL and params.
83 $output = array(
84 'sql' => '',
85 'params' => array()
86 );
87
88 // Let's start a count so we can tell when our
89 // loop ends.
90 $filter_count = count($filters);
91
92 // We only need to prepare SQL if filters exist.
93 if($filter_count > 0){
94
95 // We start a loop to set up our filters.
96 $output['sql'] = ' WHERE ';
97 $filter_iteration = 0;
98 foreach ($filters as $filter){
99
100 // Filters without type have the standard
101 // markup
102 if(empty($filter['type'])){
103
104 // The default condition 'AND'.
105 if(empty($filter['condition'])){
106 $condition = 'AND';
107
108 // You can use other conditions like 'OR'.
109 }else{
110 $condition = $filter['condition'];
111 }
112
113 // The default operator is '='.
114 if(empty($filter['operator'])){
115 $operator = '=';
116
117 // You can use other operators like 'IS'.
118 }else{
119 $operator = $filter['operator'];
120 }
121
122 // You can nest filters in filter values.
123 if(is_array($filter['value'])){
124
125 // Start the sub filter SQL.
126 $sub_filter_iteration = 0;
127 $sub_filter_count = count($filter['value']);
128 $output['sql'].= '(';
129
130 // We only support one sub filter.
131 foreach($filter['value'] as $sub_filter){
132
133 // Like we did before, let's build the
134 // sql and add to params.
135 if(empty($sub_filter['condition'])){
136 $sub_condition = 'AND';
137 }else{

Callers 4

get_db_rowsMethod · 0.95
update_db_rowsMethod · 0.95
delete_db_entriesMethod · 0.95
count_db_rowsMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected