Array to mapper criteria
@param  array   $values
@param  boolean $qmMode force question mark placeholder
@return string
534
public static function buildCriteria(array $values, $qmMode = false)
    {
        reset($values);
        $qmMode = $qmMode ?: is_numeric(key($values));

        if ($qmMode) {
            $result = array_values($values);
            array_unshift($result, str_repeat('?,', count($values)-1).'?');

            return $result;
        }

        $result = [''];
        foreach ($values as $key => $value) {
            $key = ":$key";
            $result[0] .= ($result[0]?',':'').$key;
            $result[$key] = $value;
        }

        return $result;
    }
1279797
public static function modelIdsQueryAtOnce($modelClass, $values)
    {
        $q = (new Query())
            ->select('model_id')
            ->from($modelClass::tableInheritanceTable());

        foreach ($values as $key => $vals) {
            $q->andWhere(['or', $key, $vals]);
        };

            $q->groupBy('model_id');
        return $q;
    }
779770
public function filterValues(array $values = null)
    {
        if (null === $values) {
            $values = $this->getFields();
        }
        foreach ($values as $key => $value) {
            $values[$key] = $this->filterValue($value);
        }
        return $values;
    }
1021487
public function transform(QueryBuilder $qb, $dqlAlias)
    {
        $values = $this->values;
        foreach ($values as $k => $v) {
            $values[$k] = ValueConverter::convertToDatabaseValue($v, $qb);
        }

        $paramName = sprintf('comparison_%d', $qb->getParameters()->count());
        $qb->setParameter($paramName, $values, $this->valueType);

        return sprintf(':%s', $paramName);
    }
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;
    }
771823
public function query($q, $params = array()){
		try{
			if(!empty($this->pdo)){
				$this->st = $this->pdo->prepare($q);
				if(!empty($params)){
					$keys = array_keys($params);
					$qmark = false;//qmark = question mark
					if(is_int($keys[0])){//mode '?'
						$qmark = true;
					}

					foreach($params as $p => $val){
						if($qmark){
							//$p is a numeric - 0, 1, 2, ...
							$p += 1;//bindValue starts to 1
						}
						if(is_array($val) && count($val) == 2){//if called with PDO::PARAM_STR or PDO::PARAM_INT, PDO::PARAM_BOOL
							$this->st->bindValue($p, $val[0], $val[1]);
						}
						else{
							if(! is_bool($val)) { //fix fatal error with some php versions
								$this->st->bindValue($p, $val);
							}
							else {
								$this->st->bindValue($p, $val, PDO::PARAM_INT);//cast
							}
						}
					}
				}

				$this->st->execute();
				return $this->st;
			}
			else{
				throw new DBException('PDO attribute is undefined');
			}
		}
		catch(\Exception $e){
			throw new DBException($e->getMessage(), $e->getCode());
		}
	}
1126396
private function queryAddSortByParameter(array $value): string
    {
        if (!\in_array($value[0], $this->fieldsSortable, true)) {
            throw new \InvalidArgumentException(\sprintf(
                'Parameter %s is not available for sorting in repository %s',
                $value[0],
                $this->name
            ));
        }

        return $value[0].':'.$value[1];
    }
1238693
public function addTablePrefix($values, $tableFieldMix = true)
    {
        if (is_null($this->tablePrefix)) {
            return $values;
        }

        // $value will be an array and we will add prefix to all table names

        // If supplied value is not an array then make it one
        $single = false;
        if (!is_array($values)) {
            $values = array($values);
            // We had single value, so should return a single value
            $single = true;
        }

        $return = array();

        foreach ($values as $key => $value) {
            // It's a raw query, just add it to our return array and continue next
            if ($value instanceof Raw || $value instanceof \Closure) {
                $return[$key] = $value;
                continue;
            }

            // If key is not integer, it is likely a alias mapping,
            // so we need to change prefix target
            $target = &$value;
            if (!is_int($key)) {
                $target = &$key;
            }

            if (!$tableFieldMix || ($tableFieldMix && strpos($target, '.') !== false)) {
                $target = $this->tablePrefix . $target;
            }

            $return[$key] = $value;
        }

        // If we had single value then we should return a single value (end value of the array)
        return $single ? end($return) : $return;
    }
160551
public static function to_map($arr, $keyField = null, $valueField = null)
    {
        $map = [];
        if ($valueField) {
            foreach ($arr as $row) {
                if ($keyField) {
                    $map[$row[$keyField]] = $row[$valueField];
                } else {
                    $map[] = $row[$valueField];
                }
            }
        } else {
            foreach ($arr as $row) {
                if ($keyField) {
                    $map[$row[$keyField]] = $row;
                } else {
                    $map[] = $row;
                }
            }
        }
        return $map;
    }
155779
public static function formatConditions($methondname, $conditions)
    {
        if (count($conditions) > 1) {
            throw new InvalidArgumentException(
                sprintf("Method '%s' supports a single array input", $methondname)
            );
        }

        if (1 == count($conditions)) {
            if ($conditions[0] instanceof Node) {
                return $conditions;
            }
        }

        $conditions = (empty($conditions)) ? [[]] : $conditions;

        return call_user_func_array('array_merge', $conditions);
    }
7174
private function parseQualityAndParameters(array $fields): array
    {
        $quality     = 1;
        $qParamFound = false;
        $parameters  = null;

        $count = \count($fields);
        for ($idx = 1; $idx < $count; ++$idx) {
            $fieldValue = $fields[$idx];
            if (empty($fieldValue) === true) {
                continue;
            }

            if (\strpos($fieldValue, '=') === false) {
                throw new InvalidArgumentException('mediaType');
            }

            list($key, $value) = \explode('=', $fieldValue, 2);

            $key   = \trim($key);
            $value = \trim($value, ' "');

            // 'q' param separates media parameters from extension parameters

            if ($key === 'q' && $qParamFound === false) {
                $quality     = (float)$value;
                $qParamFound = true;
                continue;
            }

            if ($qParamFound === false) {
                $parameters[$key] = $value;
            }
        }

        return [$parameters, $quality];
    }
773699
protected function getMappingsAndValues($operands)
    {
        $mappings = [];
        $values   = [];

        foreach ($operands as $operand) {
            if ($operand instanceof Value) {
                $values[] = $operand;
            } elseif ($operand instanceof PathInterface) {
                $mapping = $operand->getMapping();

                if ($mapping !== null) {
                    $mappings[] = $mapping;
                }
            }
        }

        return [$mappings, $values];
    }
1352606
public static function getRequestMap($data, $maskValues = false)
    {
        $result = array();
        if (is_array($data)) {
            foreach ($data as $key => $value) {
                $result[$key] = $maskValues
                    ? self::HIDDEN_VALUE
                    : TypeConverter::stringify($value);
            }
        }
        return empty($result) ? null : $result;
    }
521339
public function getFilter(QueryBuilder $qb, $dqlAlias)
    {
        if (null !== $this->dqlAlias) {
            $dqlAlias = $this->dqlAlias;
        }

        $field = ArgumentToOperandConverter::toField($this->field);
        $value = ArgumentToOperandConverter::toValue($this->value);

        return (string) $qb->expr()->in(
            $field->transform($qb, $dqlAlias),
            $value->transform($qb, $dqlAlias)
        );
    }
1123606
private function whereXML (array $q) {
		$queryString = '';
		$counter = 0;

		foreach ($q as $col => $value) {
			$counter++;
			$queryString .= '<Eq><FieldRef Name="' . $col . '" /><Value Type="Text">' . htmlspecialchars($value) . '</Value></Eq>';

			// Add additional "and"s if there are multiple query levels needed.
			if ($counter >= 2) {
				$queryString = '<And>' . $queryString . '</And>';
			}
		}

		return '<Where>' . $queryString . '</Where>';
	}
1134972
public function arrayToMultiselect(array $values)
    {
        // First clean the array
        foreach ($values as $k => $v) {
            if (empty($v)) {
                unset($values[$k]);
            }
        }

        // Encode
        $values = (empty($values) ? '^^' : encodeMultienumValue($values));

        // Then return the array
        return $values;
    }
113249
protected function where_clause_list($field, array $values) {
        if (empty($values)) {
            return array("1 = 2", array()); // Fake condition, won't return rows ever. MDL-17645
        }

        // Note: Do not use get_in_or_equal() because it can not deal with bools and nulls.

        $params = array();
        $select = "";
        $values = (array)$values;
        foreach ($values as $value) {
            if (is_bool($value)) {
                $value = (int)$value;
            }
            if (is_null($value)) {
                $select = "$field IS NULL";
            } else {
                $params[] = $value;
            }
        }
        if ($params) {
            if ($select !== "") {
                $select = "$select OR ";
            }
            $count = count($params);
            if ($count == 1) {
                $select = $select."$field = ?";
            } else {
                $qs = str_repeat(',?', $count);
                $qs = ltrim($qs, ',');
                $select = $select."$field IN ($qs)";
            }
        }
        return array($select, $params);
    }