Bouncy Melons 0.2
declarative style orm
FilterPermissive.php
Go to the documentation of this file.
1 <?php
2 namespace bm;
3 
5 
10  public function createWhere($fields) {
11  $input = $this->getWhere();
12  $re = [];
13  foreach ($fields as $field) {
14  if($field instanceof IdField) {
15  if(!empty($input[$field->getName()."_id"])) {
16  $re[] = "`".$field->getName()."_id` = '".$input[$field->getName()."_id"]."'";
17  continue;
18  }
19  }
20  if($field instanceof BoolField) {
21  if(isset($input[$field->getName()])) {
22  $re[] = "`".$field->getName()."`='".$input[$field->getName()]."'";
23  }
24  continue;
25  }
26  if (empty($input[$field->getName()])) {
27  continue;
28  }
29  if(is_array($input[$field->getName()])) {
30  if(!empty($input[$field->getName()]['from'])
31  && !empty($input[$field->getName()]['to'])) {
32  $re[] = "`".$field->getName()."` BETWEEN
33  '".$field->beforeSet($input[$field->getName()]['from'])."'
34  AND '".$field->beforeSet($input[$field->getName()]['to'])."'";
35  continue;
36  }
37  if(!empty($input[$field->getName()]['from'])) {
38  $re[] = "`".$field->getName()."` = '".$input[$field->getName()]['from']."'";
39  continue;
40  }
41  $re[] = "`".$field->getName()."` IN ('".implode("','",$input[$field->getName()])."')";
42  continue;
43  }
44  $re[] = "`".$field->getName()."` LIKE '%".$input[$field->getName()]."%'";
45  }
46 // var_dump(implode(' AND ', $re));
47  return implode(' AND ', $re);
48  }
49 }