PluginProbe
Smart Forms – when you need more than just a contact form / trunk
Smart Forms – when you need more than just a contact form vtrunk
trunk 0.5 0.5.5 0.6 0.7 0.8 0.8.5 0.9.1
smart-forms / php_classes / api / query / WhereClause.php

WhereClause.php in Smart Forms – when you need more than just a contact form trunk, at php_classes/api/query/WhereClause.php

121 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Created by PhpStorm.
4 * User: Edgar
5 * Date: 12/1/2017
6 * Time: 12:38 PM
7 */
8 require_once SMART_FORMS_DIR.'php_classes/api/query/comparators/ComparatorBase.php';
9 class WhereClause
10 {
11 private $field;
12 private $comparison;
13 private $value;
14 private $join;
15 private $Comparator;
16
17 public $openParentheses=false;
18 public $closeParentheses=false;
19
20 public function __construct($field, $comparison, $value,$join)
21 {
22 $this->join=$join;
23 $this->field=$field;
24 $this->value=$value;
25 $this->comparison=$comparison;
26
27 $this->Comparator=ComparatorFactory::GetComparator($field['ClassName']);
28 $this->Comparator->Initialize($field,$comparison,$value);
29 }
30
31
32 private function GetOperationString()
33 {
34 if($this->comparison=='like')
35 {
36 switch($this->GetSerializationType())
37 {
38 case "text":
39 return "value like concat('%%',%s,'%%')";
40 case "list":
41 return "value in (%l)";
42 case "check":
43 return "(%c)";
44 default:
45 throw new Exception("Invalid like operation");
46 }
47 }
48
49 switch($this->comparison)
50 {
51 case 'like':
52 case 'not like':
53 return "value ".$this->comparison." concat('%%',%s,'%%')";
54 break;
55
56 case "in":
57 case "not in":
58 return "value ".$this->comparison." (%l)";
59 default:
60 if($this->GetSerializationType()=='date')
61 return "datevalue".$this->comparison."%s";
62 return "value".$this->comparison."%s";
63
64
65 }
66 }
67
68 public function GetText()
69 {
70
71
72 global $wpdb;
73 $statement='';
74 if($this->field['Id']=="_FormId")
75 {
76 $statement= $wpdb->prepare(" parent.entry_id=%s ",$this->value);
77 }else
78
79 if($this->field['Id']=="_SFTimeStamp"||$this->field['Id']=="_Date")
80 {
81 $statement= $wpdb->prepare(" parent.date".$this->comparison."%s ",$this->value);
82 }else
83
84 if($this->field['Id']=="_UserId")
85 {
86 $statement= $wpdb->prepare(" parent.user_id".$this->comparison."%s ",$this->value);
87 }else{
88 $statement=$wpdb->prepare(" exists(select 1 from ".SMART_FORMS_ENTRY_DETAIL." detail where parent.entry_id=detail.entry_id and field_id=%s and ".$this->Comparator->GetConditionString()." ) ",$this->field['Id']);
89 }
90
91
92 if($this->join=='or')
93 {
94 $join = ' or';
95 }
96 else
97 {
98 $join = ' and';
99 }
100
101
102 return $join.$statement;
103
104 }
105
106 private function GetSerializationType()
107 {
108 switch($this->field['ClassName']){
109 case 'rednaodatepicker':
110 return 'date';
111 case "rednaomultiplecheckboxes":
112 return "list";
113 default:
114 return 'text';
115
116
117 }
118 }
119
120
121 }