@param Criteria $criteria

@return string
430129
public function getGroupBy(Criteria $criteria)
    {
        $groupBy = $criteria->getGroupByColumns();

        if ($groupBy) {
            // check if all selected columns are groupBy'ed.
            $selected = $this->getPlainSelectedColumns($criteria);
            $asSelects = $criteria->getAsColumns();

            foreach ($selected as $colName) {
                if (!in_array($colName, $groupBy)) {

                    // is a alias there that is grouped?
                    if ($alias = array_search($colName, $asSelects)) {
                        if (in_array($alias, $groupBy)) {
                            continue; //yes, alias is selected.
                        }
                    }
                    $groupBy[] = $colName;
                }
            }

            if ($groupBy) {
                return ' GROUP BY ' . implode(',', $groupBy);
            }
        }

        return '';
    }
588936
public function getURI(array $criteria)
    {
        $uris = $this->getURIs($criteria);

        return $uris->count() > 0
            ? $uris->first()
            : false;
    }
296903
public function groupBy($criteria)
    {
        $criteria = $this->factoryCallableCriteria($criteria);
        $groups   = $this->create();

        $this->each(function ($element, $key) use ($groups, $criteria) {
            $groupName  = $criteria($element, $key);
            $elements   = $groups->offsetGet($groupName, array());
            $elements[] = $element;
            $groups[$groupName] = $elements;
        });

        return $groups;
    }
514576
public function prepareCriteria($criteria)
    {
        if (is_null($criteria)) {
            $criteria = array();
        }

        if (array_key_exists('$id', $criteria)) {
            $criteria['id'] = $criteria['$id'];
            unset($criteria['$id']);
        }

        return $criteria ? : array();
    }
602043
public function matching(Criteria $criteria)
    {
        $this->guardAgainstInvalidGivenType();
        $elements = $this->collection->matching($criteria)->toArray();

        return $this->create($elements);
    }
1116665
public function findOneOrNullBy(array $criteria)
    {

        $query = $this->createQueryBuilder($criteria);

        $object = $this->getOneOrNullResultFromQueryBuilder($query);

        return $object;
    }
559187
public function getDeleteFromClause($criteria, $tableName)
    {
        $sql = 'DELETE ';
        if ($queryComment = $criteria->getComment()) {
            $sql .= '/* ' . $queryComment . ' */ ';
        }
        if ($realTableName = $criteria->getTableForAlias($tableName)) {
            if ($this->useQuoteIdentifier()) {
                $realTableName = $this->quoteIdentifierTable($realTableName);
            }
            $sql .= $tableName . ' FROM ' . $realTableName . ' AS ' . $tableName;
        } else {
            if ($this->useQuoteIdentifier()) {
                $tableName = $this->quoteIdentifierTable($tableName);
            }
            $sql .= 'FROM ' . $tableName;
        }

        return $sql;
    }
284793
public function findOneBy($criteria)
    {
        if (in_array($criteria, [null, false], true)) {
            throw new BadArgumentException(sprintf('Method "%s" could not been invoked with empty criteria', __METHOD__));
        }
        
        return $this->findFirst($criteria);
    }
383155
protected function getCriteria(array $criteria = []): array
    {
        $criteria['source'] = $this->alias;
        $criteria['sourceTable'] = $this->sourceTable;
        $criteria['sourceField'] = $this->sourceField;

        return $criteria;
    }
227443
protected function getCriteriaString(array &$criteria): string
    {
        $statement    = '';
        $useConnector = false;

        foreach ($criteria as $i => $criterion) {
            // 是括号符
            if (array_key_exists('bracket', $criterion)) {
                if (strcmp($criterion['bracket'], QueryBuilder::BRACKET_OPEN) === 0) {
                    if ($useConnector) {
                        $statement .= ' ' . $criterion['connector'] . ' ';
                    }
                    $useConnector = false;
                } else {
                    $useConnector = true;
                }

                $statement .= $criterion['bracket'];
                continue;
            }

            if ($useConnector) {
                $statement .= ' ' . $criterion['connector'] . ' ';
            }

            // 没有括号
            $useConnector = true;
            $value        = $this->getCriteriaWithoutBracket($criterion['operator'], $criterion['value'], $criterion['column']);
            $column       = $criterion['column'];
            $column       = strpos($column, '.') === false ? " `{$column}` " : " $column ";
            $statement    .= $column . $criterion['operator'] . ' ' . $value;
        }

        return $statement;
    }
22899
private function GetWhereSQL($criteria)
	{
		$ands = $criteria->GetAnds();
		$ors = $criteria->GetOrs();
		
		// TODO: this all needs to move to the criteria object so it will recurse properly  ....
		$where = $this->RemoveWherePrefix($criteria->GetWhere());
		
		if (count($ands))
		{
			$wdelim = ($where) ? " and " : "";
			foreach($ands as $c)
			{
				$tmp = $c->GetWhere();
				$buff = $this->RemoveWherePrefix($tmp);
				if ($buff)
				{
					$where .= $wdelim . $buff;
					$wdelim = " and ";
				}
			}
		}
		
		if (count($ors))
		{
			$where = trim($where) ? "(" . $where . ")" : ""; // no primary criteria.  kinda strange
			$wdelim = $where ? " or " : "";
				
			foreach($ors as $c)
			{
				$tmp = $c->GetWhere();
				$buff = $this->RemoveWherePrefix($tmp);
				if ($buff)
				{
					$where .= $wdelim . "(" . $buff . ")";
					$wdelim = " or ";
				}
			}
		}
		
		// .. end of stuff that should be in criteria	

		// prepend the "where" onto the statement
		if ($where) $where = " where (" . trim($where) . ") ";
		
		return $where;
	}
424069
public static function needsSelectAliases(Criteria $criteria)
    {
        $columnNames = array();
        foreach ($criteria->getSelectColumns() as $fullyQualifiedColumnName) {
            if ($pos = strrpos($fullyQualifiedColumnName, '.')) {
                $columnName = substr($fullyQualifiedColumnName, $pos);
                if (isset($columnNames[$columnName])) {
                    // more than one column with the same name, so aliasing is required
                    return true;
                }
                $columnNames[$columnName] = true;
            }
        }

        return false;
    }
1181997
public function applyFilter(Criteria $criteria, $filter)
    {
        if (is_string($filter) && is_string($this->property)) {
            $criteria->andWhere(
                $criteria->expr()->contains($this->property, $filter)
            );
        }

        if (is_array($filter) && isset($filter[$this->searchKey])) {
            $criteria->andWhere(
                $criteria->expr()->contains($this->property, $filter[$this->searchKey])
            );
        }

        return $criteria;
    }
110361
public function registerCriteriaFunction($criteria) {

        $id = \uniqid('criteria');

        if (\is_callable($criteria)) {
           $this->document_criterias[$id] = $criteria;
           return $id;
        }

        if (is_array($criteria)) {

            $fn = null;

            eval('$fn = function($document) { return '.UtilArrayQuery::buildCondition($criteria).'; };');

            $this->document_criterias[$id] = $fn;

            return $id;
        }

        return null;
    }
1358726
public function findOne(array $criteria = [])
    {
        $result = $this->search($criteria);

        if (count($result) > 0) {
            return $result[0];
        }

        return null;
    }
122780
protected function getRelativePath($criteria): string
    {
        $criterion  = current($criteria);
        $components = explode('/', $criterion);

        if (count($components) < 2) {
            return '';
        }

        return implode('/', array_slice($components, 0, -1));
    }
697668
public function getDatabaseSeriesData(Criteria $criteria)
    {
        $dbData = [];

        $res = $this->database->query("SELECT {$criteria->getValueField()} AS value,
calendar.week AS week,
calendar.month AS month,
calendar.year AS year,
{$this->getSeries($criteria->getSeries())}
{$criteria->getTableName()}.id
FROM {$criteria->getTableName()}
INNER JOIN calendar ON date({$criteria->getTableName()}.{$criteria->getTimeField()}) = calendar.date
    AND calendar.date >= '{$criteria->getStartDate()}'
	AND calendar.date <= '{$criteria->getEndDate()}'
    {$criteria->getJoin()}
WHERE
    {$criteria->getTableName()}.{$criteria->getTimeField()} >= '{$criteria->getStartDate()}' 
AND {$criteria->getTableName()}.{$criteria->getTimeField()} <= '{$criteria->getEndDate()}'
	{$criteria->getWhere()}
GROUP BY calendar.year,calendar.month,calendar.week" . $this->getGroupBy($criteria->getGroupBy()) . '
		');

        foreach ($res as $row) {
            $value = 0;
            if ($row->id != null) {
                $value = $row['value'];
            }
            $date = new \DateTime();
            $date->setISODate($row->year, $row->week);
            if (isset($row->name)) {
                $dbData[$row->name][$date->format('Y-m-d')] = $value;
            } else {
                $dbData[' '][$date->format('Y-m-d')] = $value;
            }
        }
        return $dbData;
    }