Filters the values using by one or more encrypted fields

@param array $values
@param array $orderBy

@return array
178000
private function filterWithEncryptedCriteria($values, array $encryptedCriteria)
    {
        $result = array_filter($values, function($value) use ($encryptedCriteria) {
            foreach ($encryptedCriteria as $fieldName => $fieldValue) {
                if (!$this->fieldValueMatches($value, $fieldName, $fieldValue)) {
                    return false;
                }
            }
            return true;
        });

        return $result;
    }
992804
public function filterInsertValues($data, $fields)
	{
		$insertValues = array();
		$field_keys = array_flip($fields);
		foreach ($data as $key => $values) {
			$filteredValues = array_intersect_key($values, $field_keys);
			$emptyFields = array_fill_keys($fields, null);
			$filledValues = array_values(array_merge($emptyFields, $filteredValues));
			$insertValues = array_merge($insertValues, $filledValues);
		}
		return $insertValues;
	}
1265779
public function selectAll(
        array $filters = [],
        array $orderBy = [],
        array $groupBy = []
    ) {
        $selection = $this->getEntityManager()->createQueryBuilder();

        $selection->select([$this->entityAlias])
            ->from($this->entityClass, $this->entityAlias);

        return $this->filterFurther($filters, $orderBy, $groupBy, $selection, 0, 0);
    }
1013186
public function byNestedFieldAndFilter(
        string $field,
        string $order,
        Filter $filter,
        string $mode = self::MODE_AVG
    ): SortBy {
        $fieldPath = Item::getPathByField($filter->getField());
        $filterAsArray = $filter->toArray();
        $filterAsArray['field'] = $fieldPath;
        $filter = Filter::createFromArray($filterAsArray);
        $this->sortsBy[] = [
            'type' => self::TYPE_NESTED,
            'filter' => $filter,
            'mode' => $mode,
            'field' => "indexed_metadata.$field",
            'order' => $order,
        ];

        return $this;
    }
100615
public function parse(array $criteria, array $orderBy = array(), $limit = null, $offset = null)
    {
        $statement = new Expr\Statement();

        if(!empty($criteria)) {
            $statement->setClause('condition', $this->parseCriteria($criteria));
        }

        if(!empty($orderBy)) 
            $statement->setClause('order', $this->parseOrderBy($orderBy));
        if($limit)
            $statement->setClause('limit', $this->parseLimit($limit));
        if($offset)
            $statement->setClause('offset', $this->parseOffset($offset));

        return new Query($statement, $this->persister);
    }
202766
public function values(array $values) : QueryBuilder
    {
        $args    = func_get_args();
        $columns = [];
        $_values = [];

        foreach($values as $key => $value) {
            preg_match("/\(JSON\)\s*([\w]+)/i", $key, $jsonTag);

            if(
                is_array($value) ||
                is_object($value)
            ) {
                if(isset($jsonTag[0])) {
                    $key       = preg_replace('/\(JSON\)\s*([\w]+)/i', '$1', $key);
                    $_values[] = $this->getQuoted(json_encode($value));
                } else {
                    $_values[] = $this->getQuoted(serialize($value));
                }
            } else if(is_bool($value)) {
                $_values[] = ($value ? 1 : 0);
            } else if(is_null($value)) {
                $_values[] = "NULL";
            } else {
                $_values[] = $this->getQuoted($value);
            }

            $columns[] = "`". $this->sanitize($key) ."`";
        }

        $this->_query[] = "(". implode(", ", $columns) .")";
        $this->_query[] = "VALUES";
        $this->_query[] = "(". implode(", ", $_values) .")";

        return $this;
    }
884999
public function listUsers($columns = ['*'], string $orderBy = 'id', string $sortBy = 'asc') : Collection
    {
        return $this->all($columns, $orderBy, $sortBy);
    }
1368204
public function sortCollection(Collection $collection, $orderBy, $orderDir = 'asc', $orderManual = null, $sort_flags = null)
    {
        $items = $collection->toArray();
        if (!$items) {
            return [];
        }

        $lookup = md5(json_encode($items) . json_encode($orderManual) . $orderBy . $orderDir);
        if (!isset($this->sort[$lookup][$orderBy])) {
            $this->buildSort($lookup, $items, $orderBy, $orderManual, $sort_flags);
        }

        $sort = $this->sort[$lookup][$orderBy];

        if ($orderDir !== 'asc') {
            $sort = array_reverse($sort);
        }

        return $sort;

    }
1217160
private function cleanOrderBy($table, $orderBy)
    {
        if (!empty($orderBy)) {
            $orderByArray = explode(',', $orderBy);
            foreach ($orderByArray as $k => $order) {
                $orderByArray[$k] = $table . '.' . $order;
            }
            $orderBy = implode(',', $orderByArray);
        }

        return $orderBy;
    }
139280
protected function getOrderingsByField(string $field, array $values, string $order = QueryInterface::ORDER_DESCENDING): array {
    $orderings = [];

    if (!empty($values)) {
      foreach ($values as $value) {
        $orderings["$field={$value}"] = $order;
      }
    }

    return $orderings;
  }
1021599
public function select($table, $where, $orderBy = null)
    {
        return $this->fieldSelect($table, "*", $where, $orderBy);
    }
797939
public function findBy(
        array $criteria,
        ?array $orderBy = null,
        ?int $limit = null,
        ?int $offset = null
    ) : array {
        $objects = [];

        foreach ($this->objects as $object) {
            $matches = true;

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

                $matches = false;
            }

            if (! $matches) {
                continue;
            }

            $objects[] = $object;
        }

        return $objects;
    }
67863
final public function orderBy($orderby, $direction = '')
    {
        if (strtolower($direction) == 'random') {
            $orderby = ''; // Random results want or don't need a field name
            $direction = $this->_randomKeyword;
        } elseif (trim($direction) != '') {
            $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' ' . $direction : ' ASC';
        }


        if (strpos($orderby, ',') !== FALSE) {
            $temp = array();
            foreach (explode(',', $orderby) as $part) {
                $part = trim($part);
                if (!in_array($part, $this->arrayAliasedTables)) {
                    $part = $this->identifiers(trim($part));
                }
                $temp[] = $part;
            }

            $orderby = implode(', ', $temp);
        } else if ($direction != $this->_randomKeyword) {
            $orderby = $this->identifiers($orderby);
        }

        $orderbyStatement = $orderby . $direction;

        $this->arrayOrderBy[] = $orderbyStatement;
        if ($this->arrayCaching === TRUE) {
            $this->arrayCacheOrderBy[] = $orderbyStatement;
            $this->arrayCacheExists[] = 'orderby';
        }

        return $this;
    }
362922
protected function removeValuesFromEntry(array $entry, $values)
    {
        foreach ($values as $value) {
            if (isset($entry[$value])) {
                unset($entry[$value]);
            }
        }

        return $entry;
    }
604912
public function orderBy($orderBy)
    {
        if (is_string($orderBy)) {
            if (strpos($orderBy, '[') === false && strpos($orderBy, '(') === false) {
                $orderBy = (string)preg_replace('#\w+#', '[\\0]', $orderBy);
                $orderBy = str_ireplace(['[ASC]', '[DESC]'], ['ASC', 'DESC'], $orderBy);
            }
            $this->_order = $orderBy;
        } else {
            $r = '';
            /** @noinspection ForeachSourceInspection */
            foreach ($orderBy as $k => $v) {
                if (is_int($k)) {
                    $type = 'ASC';
                    $field = $v;
                } else {
                    $field = $k;
                    if (is_int($v)) {
                        $type = $v === SORT_ASC ? 'ASC' : 'DESC';
                    } else {
                        $type = strtoupper($v);
                    }
                }

                if (strpos($field, '[') === false && strpos($field, '(') === false) {
                    if (strpos($field, '.') !== false) {
                        $r .= '[' . str_replace('.', '].[', $field) . '] ' . $type . ', ';
                    } else {
                        $r .= '[' . $field . '] ' . $type . ', ';
                    }
                }
                $this->_order = substr($r, 0, -2);
            }
        }

        return $this;
    }
1079709
private function filterAndSortByEncryptedField(array $criteria, array $orderBy = null, $limit = null, $offset = null)
    {
        $encryptedSort = $this->orderByHasEncryptedField($orderBy);

        $encryptedFields = $this->getEncryptedFields();
        $notEncryptedCriteria = array_diff_key($criteria, $encryptedFields);
        $notEncryptedOrderBy = !$encryptedSort ? $orderBy : null;

        // Get the result of the filter by not encrypted fields
        $result = $this->wrapped->findBy($notEncryptedCriteria, $notEncryptedOrderBy);

        $encryptedCriteria = array_intersect_key($criteria, $encryptedFields);
        if (!empty($result) && !empty($encryptedCriteria)) {
            $result = $this->filterWithEncryptedCriteria($result, $encryptedCriteria);
        }

        if ($encryptedSort && !empty($orderBy)) {
            $result = $this->sortWithEncryptedOrderBy($result, $orderBy);
        }

        if ($limit) {
            $offset = $offset ? $offset : 0;

            $result = array_slice($result, $offset, $limit);
        }

        return $result;
    }
851372
public function findOneBy(array $criteria, array $orderBy = null)
    {
        $models = $this->findBy($criteria, $orderBy, 1, 0);

        if ([] === $models) {
            $this->logger->notice(
                'model: row within table {table} with criteria {criteria} not found',
                [
                    'table' => $this->getTable(),
                    'criteria' => $criteria,
                    'orderBy' => $orderBy,
                    'limit' => 1,
                    'offset' => 0,
                ]
            );

            return null;
        }

        return reset($models);
    }