当前位置: 首页>>代码示例>>PHP>>正文


PHP DataQuery::applyRelation方法代码示例

本文整理汇总了PHP中DataQuery::applyRelation方法的典型用法代码示例。如果您正苦于以下问题:PHP DataQuery::applyRelation方法的具体用法?PHP DataQuery::applyRelation怎么用?PHP DataQuery::applyRelation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataQuery的用法示例。


在下文中一共展示了DataQuery::applyRelation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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;
 }
开发者ID:silvercart,项目名称:silvercart,代码行数:39,代码来源:SilvercartExactMatchBooleanMultiFilter.php

示例2: 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));
 }
开发者ID:prostart,项目名称:cobblestonepath,代码行数:26,代码来源:ExactMatchMultiFilter.php

示例3: 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())
		));
	}
开发者ID:redema,项目名称:sapphire,代码行数:11,代码来源:GreaterThanFilter.php

示例4: getRelationName

	/**
	 * Translates a Object relation name to a Database name and apply the relation join to 
	 * the query
	 *
	 * @param string $field
	 * @return string
	 */
	public function getRelationName($field) {
		if(strpos($field,'.') === false) {
			return '"'.$field.'"';
		}
		$relations = explode('.', $field);
		$fieldName = array_pop($relations);
		$relationModelName = $this->dataQuery->applyRelation($field);
		return '"'.$relationModelName.'"."'.$fieldName.'"';
	}
开发者ID:redema,项目名称:sapphire,代码行数:16,代码来源:DataList.php

示例5: 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));
 }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:10,代码来源:PartialMatchFilter.php

示例6: 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);
 }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:18,代码来源:ComparisonFilter.php

示例7: 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);
 }
开发者ID:prostart,项目名称:cobblestonepath,代码行数:14,代码来源:LessThanFilter.php

示例8: testRelationReturn

 public function testRelationReturn()
 {
     $dq = new DataQuery('DataQueryTest_C');
     $this->assertEquals('DataQueryTest_A', $dq->applyRelation('TestA'), 'DataQuery::applyRelation should return the name of the related object.');
     $this->assertEquals('DataQueryTest_A', $dq->applyRelation('TestAs'), 'DataQuery::applyRelation should return the name of the related object.');
     $this->assertEquals('DataQueryTest_A', $dq->applyRelation('ManyTestAs'), 'DataQuery::applyRelation should return the name of the related object.');
     $this->assertEquals('DataQueryTest_B', $dq->applyRelation('TestB'), 'DataQuery::applyRelation should return the name of the related object.');
     $this->assertEquals('DataQueryTest_B', $dq->applyRelation('TestBs'), 'DataQuery::applyRelation should return the name of the related object.');
     $this->assertEquals('DataQueryTest_B', $dq->applyRelation('ManyTestBs'), 'DataQuery::applyRelation should return the name of the related object.');
     $newDQ = new DataQuery('DataQueryTest_E');
     $this->assertEquals('DataQueryTest_A', $newDQ->applyRelation('TestA'), 'DataQuery::applyRelation should return the name of the related object.');
 }
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:12,代码来源:DataQueryTest.php

示例9: getRelationName

 /**
  * Translates a Object relation name to a Database name and apply the relation join to 
  * the query.  Throws an InvalidArgumentException if the $field doesn't correspond to a relation
  *
  * @param string $field
  * @return string
  */
 public function getRelationName($field)
 {
     if (!preg_match('/^[A-Z0-9._]+$/i', $field)) {
         throw new InvalidArgumentException("Bad field expression {$field}");
     }
     if (strpos($field, '.') === false) {
         return '"' . $field . '"';
     }
     $relations = explode('.', $field);
     $fieldName = array_pop($relations);
     $relationModelName = $this->dataQuery->applyRelation($field);
     return '"' . $relationModelName . '"."' . $fieldName . '"';
 }
开发者ID:nomidi,项目名称:sapphire,代码行数:20,代码来源:DataList.php

示例10: excludeMany

 protected function excludeMany(DataQuery $query)
 {
     $this->model = $query->applyRelation($this->relation);
     $values = $this->getValue();
     $comparisonClause = DB::get_conn()->comparisonClause($this->getDbName(), null, false, true, $this->getCaseSensitive(), true);
     $parameters = array();
     foreach ($values as $value) {
         $parameters[] = $this->getMatchPattern($value);
     }
     // Since query connective is ambiguous, use AND explicitly here
     $count = count($values);
     $predicate = implode(' AND ', array_fill(0, $count, $comparisonClause));
     return $query->where(array($predicate => $parameters));
 }
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:14,代码来源:PartialMatchFilter.php

示例11: 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));
 }
开发者ID:prostart,项目名称:cobblestonepath,代码行数:14,代码来源:PartialMatchFilter.php

示例12: 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));
 }
开发者ID:helpfulrobot,项目名称:markguinn-silverstripe-shop-search,代码行数:18,代码来源:BetweenFilter.php

示例13: apply

	public function apply(DataQuery $query) {
		$this->model = $query->applyRelation($this->relation);
		$where = array();
		if(is_array($this->getValue())) {
			foreach($this->getValue() as $value) {
				$where[]= sprintf("%s LIKE '%%%s%%'", $this->getDbName(), Convert::raw2sql($value));
			}

		} else {
			$where[] = sprintf("%s LIKE '%%%s%%'", $this->getDbName(), Convert::raw2sql($this->getValue()));
		}

		return $query->where(implode(' OR ', $where));
	}
开发者ID:redema,项目名称:sapphire,代码行数:14,代码来源:PartialMatchFilter.php

示例14: getRelationName

 /**
  * Translates a {@link Object} relation name to a Database name and apply
  * the relation join to the query.  Throws an InvalidArgumentException if
  * the $field doesn't correspond to a relation.
  *
  * @throws InvalidArgumentException
  * @param string $field
  *
  * @return string
  */
 public function getRelationName($field)
 {
     if (!preg_match('/^[A-Z0-9._]+$/i', $field)) {
         throw new InvalidArgumentException("Bad field expression {$field}");
     }
     if (!$this->inAlterDataQueryCall) {
         Deprecation::notice('4.0', 'getRelationName is mutating, and must be called inside an alterDataQuery block');
     }
     if (strpos($field, '.') === false) {
         return '"' . $field . '"';
     }
     $relations = explode('.', $field);
     $fieldName = array_pop($relations);
     $relationModelName = $this->dataQuery->applyRelation($field);
     return '"' . $relationModelName . '"."' . $fieldName . '"';
 }
开发者ID:aaronleslie,项目名称:aaronunix,代码行数:26,代码来源:DataList.php

示例15: applyMany

 /**
  * Applies an exact match (equals) on a field value against multiple
  * possible values.
  *
  * @return DataQuery
  */
 protected function applyMany(DataQuery $query)
 {
     $this->model = $query->applyRelation($this->relation);
     $modifiers = $this->getModifiers();
     $values = array();
     foreach ($this->getValue() as $value) {
         $values[] = Convert::raw2sql($value);
     }
     $CategoryModel = $this->model;
     $this->setModel("DataObjectAsPage");
     $match = array();
     foreach ($values as &$v) {
         $match[] = sprintf("%s IN (\n\t\t\t\t   SELECT " . $query->dataClass() . "ID\n\t\t\t\t   FROM `" . $query->dataClass() . "_" . $this->relation[0] . "`\n\t\t\t\t   WHERE " . $CategoryModel . "ID = '%s'\n\t\t\t\t   GROUP BY " . $query->dataClass() . "ID\n\t\t\t\t)", $this->getDbName(), $v);
     }
     $where = implode(' AND ', $match);
     return $query->where($where);
 }
开发者ID:helpfulrobot,项目名称:arambalakjian-dataobjectaspagefilter,代码行数:23,代码来源:DataObjectAsPageMatchAllFilter.php


注:本文中的DataQuery::applyRelation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。