Filter the results matching any of the criteria
@param  array $criteria  each row is a column, value and optional negate flag (same as filter method)
@return $this
329431
public function any(array $criteria) : self
    {
        $sql = [];
        $par = [];
        foreach ($criteria as $row) {
            if (isset($row[1])) {
                $temp = $this->filterSQL($row[0], $row[1] ?? null, $row[2] ?? false);
                $sql[] = $temp[0];
                $par = array_merge($par, $temp[1]);
            }
        }
        return $this->where('(' . implode(' OR ', $sql) . ')', $par);
    }
1354755
public function select(array $criteria = array(),
            $return = Table::RETURN_MODEL) {
        if (!$this->checkExists()) {
            return ($this->delayExecute) ? $this : new ArrayCollection();
        }

        $this->current = self::OP_SELECT;

        $this->query = 'SELECT ' . $this->prepareColumns();
        $this->query .= ' FROM `' . $this->name . '`' . $this->processJoins();

        $this->where($criteria);

        $this->setExpectedResult($return, true);
        if ($this->delayExecute) {
            return $this;
        }
        return $this->execute();
    }
1028063
protected function validate_criteria($criteria) {
        $criteria = strtoupper($criteria);

        if(in_array($criteria, $this->available_criteria) === false) {
            throw new InvalidWhereQueryCriteriaException();
        }

        return $criteria;
    }
23859
public function findOneBy(array $criteria) : ?array
    {
        foreach ($this->objects as $object) {
            $matches = true;

            foreach ($criteria as $key => $value) {
                if ($object[$key] === $value) {
                    continue;
                }

                $matches = false;
            }

            if ($matches) {
                return $object;
            }
        }

        return null;
    }
1291945
private function filterHasEncryptedField(array $criteria)
    {
        $result = false;

        if (!empty($criteria)) {
            $encryptedFields = array_keys($this->getEncryptedFields());
            $criteriaFields = array_keys($criteria);
            $commonFields = array_intersect($encryptedFields, $criteriaFields);

            $result = !empty($commonFields);
        }

        return $result;
    }
386239
public function filter(array $filters)
	{
		foreach ($filters as $filter) {
			if ($filter->isValueSet()) {
				if ($filter->hasConditionCallback()) {
					$data = (array) call_user_func_array(
						$filter->getConditionCallback(),
						[$this->data, $filter->getValue()]
					);
					$this->setData($data);
				} else {
					$data = array_filter($this->data, function ($row) use ($filter) {
						return $this->applyFilter($row, $filter);
					});
					$this->setData($data);
				}
			}
		}

		return $this;
	}
1130312
public function seeUserInDatabase(array $criteria)
    {
        $tableName = $this->grabPrefixedTableNameFor('users');
        $allCriteria = $criteria;
        if (!empty($criteria['user_pass'])) {
            $userPass = $criteria['user_pass'];
            unset($criteria['user_pass']);
            $hashedPass = $this->grabFromDatabase($tableName, 'user_pass', $criteria);
            $passwordOk = WpPassword::instance()->check($userPass, $hashedPass);
            $this->assertTrue(
                $passwordOk,
                'No matching records found for criteria ' . json_encode($allCriteria) . ' in table ' . $tableName
            );
        }
        $this->seeInDatabase($tableName, $criteria);
    }
992700
final public static function where(array $criteria, array $orderBy = ['createdAt' => 'DESC'], int $limit = null, int $offset = null, bool $withTrash = false)
    {
        $criteria = self::criteriaWithSoftDelete($criteria, $withTrash);
        return static::getRepository()
            ->findBy($criteria, $orderBy, $limit, $offset);
    }
535672
protected function filter(Config $config, array $criteria = [])
    {
        $count = count($criteria);
        $default = new \stdClass();
        $countResult = 0;
        foreach ($criteria as $key => $value) {
            $configValue = $config->get($key, $default);
            if ($configValue === $value) {
                $countResult++;
            }
        }

        return ($countResult === $count);
    }
796965
public function select($criteria)
    {
        $selected = [];
        
        if (is_array($criteria)) {
            foreach ($this as $member) {
                foreach ($criteria as $propName => $value) {
                    if ($member->getProperty($propName) != $value) {
                        continue;
                    }
                    $selected[] = $member;
                }
            }
        } elseif ($criteria instanceof Closure) {
            foreach ($this as $member) {
                if ($criteria($member)) {
                    $selected[] = $member;
                };
            }
        }
        
        return new static($selected);
    }
424075
public function search(array $criteria = array())
    {

        /** @var Statement $statement */
        $maxResults   = isset($criteria['maxResults']) ? intval($criteria['maxResults']) : self::MAX_RESULTS;
        $where        = isset($criteria['where']) ? $criteria['where'] : null;
        $queryBuilder = $this->getSelectQueryBuilder();
        //        $returnType   = isset($criteria['returnType']) ? $criteria['returnType'] : null;

        // add filter (https://trac.wheregroup.com/cp/issues/3733)
        if (!empty($this->sqlFilter)) {
            $queryBuilder->andWhere($this->sqlFilter);
        }

        // add second filter (https://trac.wheregroup.com/cp/issues/4643)
        if ($where) {
            $queryBuilder->andWhere($where);
        }

        $queryBuilder->setMaxResults($maxResults);
        // $queryBuilder->setParameters($params);
        $statement  = $queryBuilder->execute();
        $rows       = $statement->fetchAll();
        $hasResults = count($rows) > 0;

        // Cast array to DataItem array list
        if ($hasResults) {
            $this->prepareResults($rows);
        }

        return $rows;
    }
1116665
public function findOneOrNullBy(array $criteria)
    {

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

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

        return $object;
    }
790666
public function findRandomOneBy(array $criteria)
    {
        $queryBuilder = $this->getQueryBuilder();

        $this->applyCriteria($queryBuilder, $criteria);

        return $queryBuilder
            ->addSelect('RAND() as HIDDEN rand')
            ->orderBy('rand')
            ->setMaxResults(1)
            ->getQuery()
            ->getOneOrNullResult()
        ;
    }
770782
protected function applyCriteria($criteria)
    {
        $query = $this->getQuery();
        $metadata = $this->getEntityMetadata();
        
        if (null !== $criteria) {
            switch (true) {
                case is_scalar($criteria):
                    $identifier = $metadata->getRawSQLName($metadata->getIdentifier());
                    $query->addConditions($identifier, $criteria);
                    break;
                
                case $criteria instanceof QueryBuilder\Select:
                    $criteria->setFromTable($metadata->getTableName());
                    $this->setQuery($criteria);
                    break;
                
                case (is_array($criteria) and count($criteria) > 0):
                    $query->addConditions(...$criteria);
                    break;
                
                default:
                    throw new NotSupportedException('It is impossible to determine the correct assignment criteria');
                    break;
            }
        }
        
        return $this;
    }
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();
    }
429768
public function remove($criteria) {

        $sql = 'DELETE FROM '.$this->name.' WHERE document_criteria("'.$this->database->registerCriteriaFunction($criteria).'", document)';

        return $this->database->connection->exec($sql);
    }
230733
public function sortBy($criteria)
    {
        $criteria = $this->factoryCallableCriteria($criteria);
        $sorted   = $this->create();
        $groups   = $this->groupBy($criteria);

        $criterias = $this->map(function ($element, $key) use ($criteria) {
            return $criteria($element, $key);
        })->toArray();

        sort($criterias);
        $criterias = array_unique($criterias);

        foreach ($criterias as $key) {
            foreach ($groups[$key] as $element) {
                $sorted[] = $element;
            }
        }

        return $sorted;
    }