Generate condition string for WHERE or Having statement

@param mixed $conditions
@param array $params
@param array $types
@return string
969875
protected function processCondition($conditions, $params, $types)
    {
        // Regard numeric and null as primary key value
        if (is_numeric($conditions) || empty($conditions)) {
            $conditions = array($this->primaryKey => $conditions);
        }

        if (is_array($conditions)) {
            $where = array();
            $params = array();
            foreach ($conditions as $field => $condition) {
                if (is_array($condition)) {
                    $where[] = $field . ' IN (' . implode(', ', array_pad(array(), count($condition), '?')) . ')';
                    $params = array_merge($params, $condition);
                } else {
                    $where[] = $field . " = ?";
                    $params[] = $condition;
                }
            }
            $conditions = implode(' AND ', $where);
        }

        if ($params !== false) {
            if (is_array($params)) {
                $this->params = array_merge($this->params, $params);
                $this->paramTypes = array_merge($this->paramTypes, $types);
            } else {
                $this->params[] = $params;
                if ($types) {
                    $this->paramTypes[] = $types;
                }
            }
        }

        return $conditions;
    }
1204786
public function findOneBy(array $conditions)
    {
        $s = $this->selector()->one();
        foreach ($conditions as $column => $value) {
            $s->where($column, '=', $value);
        }

        return $s->execute();
    }
1279522
public static function getByMultiple($conditions, $args = array())
    {
        if (!Arr::iterable($conditions)) {
            return self::getWhere($args, $load_terms);
        }

        // Extract number if passed in $args
        // because we don't want to prematurely restrict the result set.
        $number = (array_key_exists('number', $args))
            ? $args['number']
            : null;
        unset($args['number']);

        // First, get all the post_ids
        $term_ids = array();
        foreach ($conditions as $k => $condition) {
            // Conditions can have numeric or named keys:
            // ['key1', 'val1', '=']
            // ['key'=>'foo', 'val'=>'bar', '=']
            $condition_values = array_values($condition);
            $key = (array_key_exists('key', $condition)) ? $condition['key'] : $condition_values[0];
            $value = (array_key_exists('value', $condition)) ? $condition['value'] : $condition_values[1];

            // Make sure we have a compare
            $compare = '=';
            if (array_key_exists('compare', $condition)) {
                $compare = $condition['compare'];
            } elseif (array_key_exists(2, $condition_values)) {
                $compare = $condition_values[2];
            }

            // Get the posts from getBy
            // Trying to replicate getBy's logic could be significant
            // b/c it handles both core and meta fields
            $terms = self::getBy($key, $value, $compare, $args);
            if (!Arr::iterable($terms)) {
                continue;
            }

            // Using array_intersect here gives us the AND relationship
            // array_merge would give us OR
            $new_term_ids = Collection::pluck($terms, 'term_id');
            $new_term_ids = array_map('intval', $new_term_ids);
            $term_ids = (Arr::iterable($term_ids))
                ? array_intersect($term_ids, $new_term_ids)
                : $new_term_ids;
            $term_ids = array_unique($term_ids);

            // After the first conditional, we can start modifying the args
            // to restrict results to previously matched posts.
            //
            // Effectively, this also means that when calling this method
            // you should put conditions you expect to be more restrictive
            // earlier in the conditionals array.
            $args['include'] = $term_ids;
        }

        // Reapply numberposts now that we have our desired post_ids
        if (!is_null($number)) {
            $args['number'] = $number;
        }

        // TODO This should probably use getWhere
        //      but it seems like getWhere may not work with the ordering
        unset($args['include']);
        return (Arr::iterable($term_ids))
            ? self::getBy('term_id', $term_ids, 'in', $args)
            : array();
    }
284369
public static function buildCondition($opt, &$condition, &$params, $likes = [], $between = []) {
        if ($opt == null || count($opt) == 0) {
            $condition = [];
            $params = [];
            return;
        }
        $condition = [
            'and'
        ];
        foreach ($opt as $key => $value) {
            if (in_array($key, $likes)) {
                $condition [] = [
                    'like',
                    $key,
                    $value
                ];
                continue;
            } else if (in_array($key, $between)) {
                $condition [] = [
                    'between',
                    $key,
                    $value [0],
                    $value[1]];
                continue;
            } else {
                $condition[] = $key . '=:' . $key;
            }
            $params[':' . $key] = $value;
        }
        return [$condition, $params];
    }
489004
public function addCondition(\Sulu\Bundle\ResourceBundle\Entity\Condition $conditions)
    {
        $this->conditions[] = $conditions;

        return $this;
    }
502870
public function where($conditions = null, $types = [], $overwrite = false)
    {
        if ($conditions === null) {
            return $this->clause('where');
        }

        $this->_parts['where'] = (!$overwrite) ? Hash::merge($this->clause('where'), $conditions) : $conditions;

        return $this;
    }
806668
public function having($conditions, $parameters = [])
	{
		$this->having = [];

		if (!empty($conditions)) {
			$this->addHaving($conditions, $parameters);
		}

		return $this;
	}
372021
public static function filter(array $conditions)
    {

        $model = static::class;
        $obj = new $model();

        foreach ($conditions as $key => $condition) {

            if (is_array($condition)) {
                if (count($condition) == 1) {
                    $obj = $obj->where($key, $condition[0]);
                } elseif (count($condition) == 2) {
                    if (strtolower(trim($condition[0])) === 'between') {
                        $obj = $obj->whereBetween($key, $condition[1]);
                    } else {
                        $obj = $obj->where($key, $condition[0], $condition[1]);
                    }
                } elseif (count($condition) == 3) {
                    if (strtolower(trim($condition[0])) === 'between') {
                        $obj = $obj->whereBetween($key, $condition[1], $condition[2]);
                    } else {
                        $obj = $obj->where($key, $condition[0], $condition[1], $condition[2]);
                    }
                } else {
                    throw new \Exception("Invalid " . strtoupper($key) . " condition", 1);
                }
            } else {
                if (is_numeric($condition) || is_bool($condition)) {
                    $obj = $obj->where($key, $condition);
                } elseif (is_string($condition)) {
                    $obj = $obj->where($key, 'LIKE', $condition);
                } elseif (is_null($condition)) {
                    $obj = $obj->whereNull($key);
                } else {
                    throw new \Exception("Invalid " . strtoupper($key) . " condition", 2);
                }
            }
        }

        return $obj;
    }
1367694
private static function _extractWhereConditions($conditions) 
    {
        if (!$conditions) {
            return "";
        }

        $cls    = get_called_class();
        $escape = Driver::$escape_char;

        if (is_array($conditions)) {
            // check if is a regular array or an associative one
            if (array_values($conditions) !== $conditions) {
                $conditions = self::_extractWhereAssociativeConditions($conditions, $cls, $escape);
            } else {
                $conditions = self::_extractWhereRegularConditions($conditions, $cls, $escape);
            }
        }
        return $conditions;
    }
656361
public function findColumn($condition, $params, $fields) {
		if (!empty($fields)) $this->driver->field($fields);
		return $this->driver->where($condition, $params)
            ->fetchColumn();
	}
737077
public function andWhere($condition, $params = [])
    {
        if (is_array($condition)) {
            foreach ($condition as $key => $value) {
                if ($this->canSetProperty($key)) {
                    $this->{$key} = $value;
                    unset($condition[$key]);
                }
            }
        }

        return parent::andWhere($condition);
    }
1233318
public function having($conditions, $params = array())
    {
        $this->mergeParams($params);
        $this->query['having'] = $this->buildConditions($conditions);

        return $this;
    }
1051488
public static function findAll($condition = '1=1', $params = array())
    {
        /* @var $condition \mpf\datasources\sql\ModelCondition */
        if (!is_a($condition, '\\mpf\\datasources\\sql\\ModelCondition')) {
            $condition = ModelCondition::getFrom($condition, get_called_class());
        } else {
            $condition->model = $condition->model ? $condition->model : get_called_class();
        }
        $condition->setParams($params);
        $searchedRelations = [];
        if (is_array($condition->with)) {
            foreach ($condition->with as $k) {
                $searchedRelations[$k] = $k;
            }
        }
        $models = static::getDb()->queryClass($condition, get_called_class(), $condition->getParams(), [
            [
                '_columns' => static::getDb()->getTableColumns(static::getTableName()),
                '_pk' => static::getDb()->getTablePk(static::getTableName()),
                '_isNewRecord' => false,
                '_action' => 'update',
                '_tableName' => static::getTableName(),
                '_db' => static::getDb(),
                '_searchedRelations' => $searchedRelations
            ]
        ]);
        if (!$models) {
            return [];
        }
        $condition->getExtraRelations($models);
        return $models;
    }
42444
protected function compileConditions(array $conditions, $conjunction = null)
    {
        if (count($conditions) === 1) {
            return $conditions[0];
        }

        if ($conjunction === null) {
            $conjunction = $this->conjunction();
        }

        return '('.implode(' '.$conjunction.' ', $conditions).')';
    }
1155870
protected function prepareArray(array $conditions)
    {
        switch (count($conditions)) {
            case 1:
                $result = $conditions[0];
                break;
            case 2:
                if (is_array($conditions[1])) {
                    $result = $conditions[0].' IN ('.implode(',', $conditions[1]).')';
                } elseif (is_null($conditions[1])) {
                    $result = $conditions[0].' IS NULL';
                } elseif ($conditions[1] instanceof \pwf\components\querybuilder\interfaces\SelectBuilder) {
                    $result = $conditions[0].' IN ('.$conditions[1]->generate().')';
                    $this->setParams(array_merge($this->getParams(),
                            $conditions[1]->getParams()));
                } else {
                    $result = $conditions[0].'=?';//.$conditions[0];
                    $this->addParam($conditions[0], $conditions[1]);
                }
                break;
            case 3:
                $left   = is_array($conditions[1]) ? $this->prepareConditions($conditions[1])
                        : $conditions[1];
                $right  = is_array($conditions[2]) ? $this->prepareConditions($conditions[2])
                        : $conditions[2];
                $result = '(('.$left.') '.$conditions[0].' ('.$right.'))';
                break;
            default:
                throw new \Exception('Wrong condition configuration');
        }

        return $result;
    }
1260107
public function findBy(array $conditions)
    {
        $s = $this->selector();
        foreach ($conditions as $column => $value) {
            $s->where($column, '=', $value);
        }

        return $s->execute();
    }
1076301
protected function whereConditions(array $wheres): string
	{
		$conditions = [];

		$conditionCounter = 0;

		foreach($wheres as $where)
		{
			$conditions[] = ($conditionCounter > 0 ? $where['separator'] . ' ' : null) . $this->{$where['type']}($where);

			$conditionCounter++;
		}

		return implode(' ', $conditions);
	}