/** * Sets search conditions for finding resultsets * @method search * @param string $id * @return string */ public function search($id = NULL) { $condition = $condition2 = ''; $relationalOperator = ''; $searchId = ''; if ($this->obj->searchFields['unparsed'] != NULL || $id != NULL) { $searchFields = $this->obj->searchFields['unparsed']; $last = getLastKeyValue($this->obj->searchFields['unparsed']); $lastKey = $last['key']; $lastValue = $last['value']; foreach ($searchFields as $queries => $query) { $operator = $queries; foreach ($query as $keys => $key) { foreach ($key as $field => $value) { $relationalOperator = ''; if (count($searchFields) > 1 && ($lastKey != $field || $lastValue != $value)) { $relationalOperator = ' ' . strtoupper($this->obj->searchFields['operator']); } if ('in' != $operator && 'nin' != $operator && 'empty' != $value && 'false' != $value && 'true' != $value) { $value = ' "' . $value . '" '; } if ("empty" == $value) { $value = '""'; } else { if ("false" == $value) { $value = 0; } else { if ("true" == $value) { $value = 1; } else { if ("null" == $value) { $value = NULL; } } } } $condition .= $field . ' ' . $this->operators[$operator] . $value . $relationalOperator . ' '; } } } } if (NULL != $id) { $searchId = 'id = ' . $id; $condition2 = $searchId; } $condition2 = $this->obj->searchFields['unparsed'] != NULL ? $relationalOperator : '' . $searchId; $params = $condition2; if (!empty($condition)) { $params = $condition . $condition2; } return $params; }
/** * Sets search conditions for finding resultsets * @var array */ public function search($id = NULL) { $condition = $condition2 = array(); $relationalOperator = ''; $searchId = ''; if ($this->obj->searchFields['unparsed'] != NULL || $id != NULL) { $searchFields = $this->obj->searchFields['unparsed']; $last = getLastKeyValue($this->obj->searchFields['unparsed']); if (!empty($last)) { $lastKey = $last['key']; $lastValue = $last['value']; foreach ($searchFields as $queries => $query) { $operator = $queries; foreach ($query as $keys => $key) { foreach ($key as $field => $value) { $relationalOperator = ''; if ('eq' == $operator) { $condition[$field] = $value; } else { if ('like' == $operator) { $condition[$field] = new \MongoRegex("/{$value}/"); } else { if ('nin' == $operator || 'in' == $operator) { $value = !is_array($value) ? explode(",", trim($value, "()")) : $value; $condition[$field][$this->operators[$operator]] = $value; } else { $condition[$field][$this->operators[$operator]] = $value; } } } } } } } } if (NULL != $id) { $searchId['id'] = $id; $condition2 = $searchId; } $params = array_merge($condition, $condition2); return $params; }