77
77
function init($fields=null, $arguments=null, $order=null, $limit=null) {
78
78
$this->_arguments = (is_array($arguments) ? array_merge($this->_arguments, $arguments) : $this->_arguments);
79
$this->_fields = (is_array($fields) ? $fields : null);
80
$this->_limit = (is_array($limit) ? $limit : null);
81
$this->_order = (is_array($order)? $order : null);
79
$this->_fields = (is_array($fields) ? $fields : $this->_fields);
80
$this->_limit = (is_array($limit) ? $limit : $this->_limit);
81
$this->_order = (is_array($order)? $order : $this->_order);
124
124
* Process dependencies of other modules
126
126
public function processDependencies($dep_array) {
127
if(!empty($dep_array['fields'])) {
128
if($dep_array['fields'] != null) {
128
129
$fields = array_merge($this->_fields, $dep_array['fields']);
132
if($dep_array['arguments'] != null) {
129
133
$arguments = array_merge($this->_arguments, $dep_array['arguments']);
130
$order = array_merge($this->_order, $dep_array['order']);
131
$limit = array_merge($this->_limit, $dep_array['order']);
132
$this->init($fields, $arguments, $order, $limit);
136
if($dep_array['order'] != null) {
137
$order = $dep_array['order'];
140
if($dep_array['limit'] != null) {
141
$limit = $dep_array['limit'];
145
$this->init($fields, $arguments, $order, $limit);
137
151
* Build of field list of the query
139
153
protected function _queryField() {
140
154
if(is_array($this->_fields)) {
141
if(in_array('id', $this->_fields)) {
155
if(in_array('id', $this->_fields) AND in_array($this->array_name, $this->_fields)) {
156
// Make sure the id and array_name fields are requested
142
157
return implode(", ", $this->_fields);
144
// The id field, which is required, wasn't requested
146
return "id, " . implode(", ", $this->_fields);
159
if(!in_array('id', $this->_fields) AND !in_array($this->array_name, $this->_fields) AND $this->array_name != 'id') {
160
// Both the id and the array_name weren't there, which is required, wasn't requested
162
return "id, " . $this->array_name . ", " . implode(", ", $this->_fields);
163
} elseif(!in_array('id', $this->_fields) AND $this->array_name == 'id') {
165
return "id, " . implode(", ", $this->_fields);
167
return $this->array_name . ", " . implode(", ", $this->_fields);
173
195
foreach($this->_arguments as $key => $value) {
174
196
if(is_array($value)) {
175
$where .= (($i == 1) ? " ( " : " AND ( ");
197
$where .= (($i == 1) ? " ( " : " AND ( ");
177
199
foreach($value as $subkey => $subvalue) {
178
$operator = ((is_numeric($subkey)) ? '=' : $subkey);
179
$where .= (($i > 0 ) ? " OR ".$key." ".$operator." ".$subvalue : $key." ".$operator." ".$subvalue);
200
$operator = ((is_int($subkey)) ? '=' : $subkey);
201
$where .= (($j > 1 ) ? " OR " . $key . " " . $operator . " '" . $subvalue . "'" : $key . " " . $operator . " '" . $subvalue . "'");
184
$where .= (($i == 1) ? " ".$key." = ".$value : " AND ".$key." = ".$value);
206
$where .= (($i == 1) ? " " . $key . " = '" . $value . "'" : " AND ".$key." = '" . $value . "'");