本文整理汇总了PHP中DataQuery::where方法的典型用法代码示例。如果您正苦于以下问题:PHP DataQuery::where方法的具体用法?PHP DataQuery::where怎么用?PHP DataQuery::where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataQuery
的用法示例。
在下文中一共展示了DataQuery::where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: apply
public function apply(DataQuery $query)
{
$this->model = $query->applyRelation($this->relation);
// hack
// PREVIOUS $values = explode(',',$this->getValue());
$values = array();
if (is_string($this->getValue())) {
$values = explode(',', $this->getValue());
} else {
foreach ($this->getValue() as $v) {
$values[] = $v;
}
}
if (!$values) {
return false;
}
for ($i = 0; $i < count($values); $i++) {
if (!is_numeric($values[$i])) {
// @todo Fix string replacement to only replace leading and tailing quotes
$values[$i] = str_replace("'", '', $values[$i]);
$values[$i] = Convert::raw2sql($values[$i]);
}
}
$SQL_valueStr = "'" . implode("','", $values) . "'";
return $query->where(sprintf("%s IN (%s)", $this->getDbName(), $SQL_valueStr));
}
示例2: addFilter
/**
* Modify this DataList, adding a filter
*/
public function addFilter($filterArray)
{
$SQL_Statements = array();
foreach ($filterArray as $field => $value) {
if (is_array($value)) {
$customQuery = 'IN (\'' . implode('\',\'', Convert::raw2sql($value)) . '\')';
} else {
$customQuery = '= \'' . Convert::raw2sql($value) . '\'';
}
if (stristr($field, ':')) {
$fieldArgs = explode(':', $field);
$field = array_shift($fieldArgs);
foreach ($fieldArgs as $fieldArg) {
$comparisor = $this->applyFilterContext($field, $fieldArg, $value);
}
} else {
if ($field == 'ID') {
$field = sprintf('"%s"."ID"', ClassInfo::baseDataClass($this->dataClass));
} else {
$field = '"' . Convert::raw2sql($field) . '"';
}
$SQL_Statements[] = $field . ' ' . $customQuery;
}
}
if (count($SQL_Statements)) {
foreach ($SQL_Statements as $SQL_Statement) {
$this->dataQuery->where($SQL_Statement);
}
}
return $this;
}
示例3: filter
/**
* Filter the list to include items with these charactaristics
*
* @see SS_List::filter()
*
* @example $list->filter('Name', 'bob'); // only bob in the list
* @example $list->filter('Name', array('aziz', 'bob'); // aziz and bob in list
* @example $list->filter(array('Name'=>'bob, 'Age'=>21)); // bob with the age 21
* @example $list->filter(array('Name'=>'bob, 'Age'=>array(21, 43))); // bob with the Age 21 or 43
* @example $list->filter(array('Name'=>array('aziz','bob'), 'Age'=>array(21, 43))); // aziz with the age 21 or 43 and bob with the Age 21 or 43
*
* @todo extract the sql from $customQuery into a SQLGenerator class
*
* @param string|array Escaped SQL statement. If passed as array, all keys and values are assumed to be escaped.
* @return DataList
*/
public function filter()
{
$numberFuncArgs = count(func_get_args());
$whereArguments = array();
if ($numberFuncArgs == 1 && is_array(func_get_arg(0))) {
$whereArguments = func_get_arg(0);
} elseif ($numberFuncArgs == 2) {
$whereArguments[func_get_arg(0)] = func_get_arg(1);
} else {
throw new InvalidArgumentException('Incorrect number of arguments passed to filter()');
}
$SQL_Statements = array();
foreach ($whereArguments as $field => $value) {
if (is_array($value)) {
$customQuery = 'IN (\'' . implode('\',\'', Convert::raw2sql($value)) . '\')';
} else {
$customQuery = '= \'' . Convert::raw2sql($value) . '\'';
}
if (stristr($field, ':')) {
$fieldArgs = explode(':', $field);
$field = array_shift($fieldArgs);
foreach ($fieldArgs as $fieldArg) {
$comparisor = $this->applyFilterContext($field, $fieldArg, $value);
}
} else {
$SQL_Statements[] = '"' . Convert::raw2sql($field) . '" ' . $customQuery;
}
}
if (count($SQL_Statements)) {
foreach ($SQL_Statements as $SQL_Statement) {
$this->dataQuery->where($SQL_Statement);
}
}
return $this;
}
示例4: apply
/**
* Applies the filter.
* Builds the where clause with the given IDs and boolean values in
* $this->value
*
* @param DataQuery $query Query to build where clause for
*
* @return DataQuery
*
* @author Sebastian Diel <sdiel@pixeltricks.de>
* @since 25.06.2014
*/
public function apply(DataQuery $query)
{
$result = false;
$value = $this->getValue();
if (is_array($value) && count($value) > 0) {
$this->model = $query->applyRelation($this->relation);
$values = array(0 => array(), 1 => array());
foreach ($value as $ID => $boolean) {
$operator = '!=';
if ($boolean) {
$operator = '=';
}
$values[$boolean][] = sprintf("%s %s '%s'", $this->getDbName(), $operator, Convert::raw2sql($ID));
}
$negativeWhereClause = implode(' AND ', $values[0]);
$positiveWhereClause = implode(' OR ', $values[1]);
if (count($values[0]) > 0 && count($values[1]) > 0) {
$where = sprintf('(%s) AND (%s)', $negativeWhereClause, $positiveWhereClause);
} elseif (count($values[0]) > 0) {
$where = $negativeWhereClause;
} else {
$where = $positiveWhereClause;
}
$result = $query->where($where);
}
return $result;
}
示例5: apply
public function apply(DataQuery $query) {
$query->where(sprintf(
"MATCH (%s) AGAINST ('%s')",
$this->getDbName(),
Convert::raw2sql($this->getValue())
));
return $query;
}
示例6: apply
/**
* @return $query
*/
public function apply(DataQuery $query) {
$this->model = $query->applyRelation($this->relation);
return $query->where(sprintf(
"%s > '%s'",
$this->getDbName(),
Convert::raw2sql($this->getDbFormattedValue())
));
}
示例7: apply
public function apply(DataQuery $query)
{
if (!isset($this->min) || !isset($this->max)) {
$this->findMinMax();
}
if ($this->min && $this->max) {
$query->where(sprintf("%s >= '%s' AND %s <= '%s'", $this->getDbName(), Convert::raw2sql($this->min), $this->getDbName(), Convert::raw2sql($this->max)));
} else {
if ($this->min) {
$query->where(sprintf("%s >= '%s'", $this->getDbName(), Convert::raw2sql($this->min)));
} else {
if ($this->max) {
$query->where(sprintf("%s <= '%s'", $this->getDbName(), Convert::raw2sql($this->max)));
}
}
}
}
开发者ID:helpfulrobot,项目名称:dnadesign-silverstripe-datedropdownselectorfield,代码行数:17,代码来源:DateRangeFilter.php
示例8: apply
function apply(DataQuery $query) {
$query->where(sprintf(
"%s >= %s AND %s <= %s",
$this->getDbName(),
Convert::raw2sql($this->min),
$this->getDbName(),
Convert::raw2sql($this->max)
));
}
示例9: excludeMany
protected function excludeMany(DataQuery $query)
{
$this->model = $query->applyRelation($this->relation);
$where = array();
$modifiers = $this->getModifiers();
foreach ($this->getValue() as $value) {
$where[] = DB::getConn()->comparisonClause($this->getDbName(), '%' . Convert::raw2sql($value) . '%', false, true, $this->getCaseSensitive());
}
return $query->where(implode(' AND ', $where));
}
示例10: excludeOne
/**
* Applies a exclusion(inverse) filter to the query
* Handles SQL escaping for both numeric and string values
*
* @param DataQuery $query
* @return $this|DataQuery
*/
protected function excludeOne(DataQuery $query)
{
$this->model = $query->applyRelation($this->relation);
$value = $this->getDbFormattedValue();
if (is_numeric($value)) {
$filter = sprintf("%s %s %s", $this->getDbName(), $this->getInverseOperator(), Convert::raw2sql($value));
} else {
$filter = sprintf("%s %s '%s'", $this->getDbName(), $this->getInverseOperator(), Convert::raw2sql($value));
}
return $query->where($filter);
}
示例11: apply
/**
* @return $query
*/
public function apply(DataQuery $query)
{
$this->model = $query->applyRelation($this->relation);
$value = $this->getDbFormattedValue();
if (is_numeric($value)) {
$filter = sprintf("%s < %s", $this->getDbName(), Convert::raw2sql($value));
} else {
$filter = sprintf("%s < '%s'", $this->getDbName(), Convert::raw2sql($value));
}
return $query->where($filter);
}
示例12: testNestedGroups
public function testNestedGroups()
{
$dq = new DataQuery('DataQueryTest_A');
$dq->where('DataQueryTest_A.ID = 2');
$subDq = $dq->disjunctiveGroup();
$subDq->where('DataQueryTest_A.Name = \'John\'');
$subSubDq = $subDq->conjunctiveGroup();
$subSubDq->where('DataQueryTest_A.Age = 18');
$subSubDq->where('DataQueryTest_A.Age = 50');
$subDq->where('DataQueryTest_A.Name = \'Bob\'');
$this->assertContains("WHERE (DataQueryTest_A.ID = 2) AND ((DataQueryTest_A.Name = 'John') OR ((DataQueryTest_A.Age = 18) " . "AND (DataQueryTest_A.Age = 50)) OR (DataQueryTest_A.Name = 'Bob'))", $dq->sql());
}
示例13: applyOne
/**
*
*@return SQLQuery
**/
public function applyOne(DataQuery $query)
{
//$this->model = $query->applyRelation($this->relation);
$value = $this->getValue();
$date = new Date();
$date->setValue($value);
$distanceFromToday = time() - strtotime($value);
$maxDays = round($distanceFromToday / ($this->divider * 2 * 86400)) + 1;
$formattedDate = $date->format("Y-m-d");
// changed for PostgreSQL compatability
// NOTE - we may wish to add DATEDIFF function to PostgreSQL schema, it's just that this would be the FIRST function added for SilverStripe
// default is MySQL DATEDIFF() function - broken for others, each database conn type supported must be checked for!
$db = DB::getConn();
if ($db instanceof PostgreSQLDatabase) {
// don't know whether functions should be used, hence the following code using an interval cast to an integer
$query->where("(\"EcommercePayment\".\"Created\"::date - '{$formattedDate}'::date)::integer > -" . $maxDays . " AND (\"EcommercePayment\".\"Created\"::date - '{$formattedDate}'::date)::integer < " . $maxDays);
} else {
// default is MySQL DATEDIFF() function - broken for others, each database conn type supported must be checked for!
$query->where("(DATEDIFF(\"EcommercePayment\".\"Created\", '{$formattedDate}') > -" . $maxDays . " AND DATEDIFF(\"EcommercePayment\".\"Created\", '{$formattedDate}') < " . $maxDays . ")");
}
return $query;
}
示例14: apply
public function apply(DataQuery $query)
{
$this->model = $query->applyRelation($this->relation);
$where = array();
$comparison = DB::getConn() instanceof PostgreSQLDatabase ? 'ILIKE' : 'LIKE';
if (is_array($this->getValue())) {
foreach ($this->getValue() as $value) {
$where[] = sprintf("%s %s '%%%s%%'", $this->getDbName(), $comparison, Convert::raw2sql($value));
}
} else {
$where[] = sprintf("%s %s '%%%s%%'", $this->getDbName(), $comparison, Convert::raw2sql($this->getValue()));
}
return $query->where(implode(' OR ', $where));
}
示例15: excludeMany
/**
* @param DataQuery $query
* @return DataQuery
*/
protected function excludeMany(DataQuery $query)
{
$this->model = $query->applyRelation($this->relation);
$filters = array();
$ops = array('<', '>');
foreach ($this->getValue() as $i => $value) {
if (is_numeric($value)) {
$filters[] = sprintf("%s %s %s", $this->getDbName(), $ops[$i], Convert::raw2sql($value));
} else {
$filters[] = sprintf("%s %s '%s'", $this->getDbName(), $ops[$i], Convert::raw2sql($value));
}
}
return $query->where(implode(' OR ', $filters));
}