Adds active promotion check

@param array  $aWhere  SQL condition array
@param string $sqlFull SQL query string

@return $sQ
551103
protected function _prepareWhereQuery($aWhere, $sqlFull)
    {
        $sQ = parent::_prepareWhereQuery($aWhere, $sqlFull);
        $sDisplayType = (int) \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('displaytype');
        $sTable = getViewName("oxactions");

        // searching for empty oxfolder fields
        if ($sDisplayType) {
            $sNow = date('Y-m-d H:i:s', \OxidEsales\Eshop\Core\Registry::getUtilsDate()->getTime());

            switch ($sDisplayType) {
                case 1: // active
                    $sQ .= " and {$sTable}.oxactivefrom < '{$sNow}' and {$sTable}.oxactiveto > '{$sNow}' ";
                    break;
                case 2: // upcoming
                    $sQ .= " and {$sTable}.oxactivefrom > '{$sNow}' ";
                    break;
                case 3: // expired
                    $sQ .= " and {$sTable}.oxactiveto < '{$sNow}' and {$sTable}.oxactiveto != '0000-00-00 00:00:00' ";
                    break;
            }
        }

        return $sQ;
    }
707129
protected function updateFullTextEnabled()
    {
        // Check if installed
        $isInstalled = $this->query("SELECT fulltextserviceproperty('isfulltextinstalled')")->value();
        if (!$isInstalled) {
            return false;
        }

        // Check if current database is enabled
        $database = $this->getSelectedDatabase();
        $enabledForDb = $this->preparedQuery(
            "SELECT is_fulltext_enabled FROM sys.databases WHERE name = ?",
            array($database)
        )->value();
        return $enabledForDb;
    }
1197241
public function orWhereRaw($column, $operator = null, ?string $raw = null)
	{
		return $this->whereRaw($column, $operator, $raw, 'OR');
	}
1229439
public function checkExistsWithMultipleWhere($whereValue = '', $whereField = 'id', $select = '*')
    {
        if (is_array($whereValue) && count($whereValue) > 0) {
            foreach ($whereValue as $key => $value) {
                if (is_array($value['value'])) {
                    $this->db->where($value['field'], $value['value'], self::OPERATOR_IS_IN);
                } else {
                    $this->db->where($value['field'], $value['value'], $value['operator']);
                }
            }
        } else {
            $this->db->where($whereField, $whereValue, self::OPERATOR_EQUAL_TO);
        }
        $this->db->get($this->table, NULL, $select);

        return (int) $this->db->count;
    }
330737
public function orWhere($column, $expression = null, $value = null)
    {
        return $this->doWhere(self::OR_WHERE, $column, $expression, $value);
    }
516107
public function get_events_select_count($selectwhere, array $params) {
        global $DB;

        // Replace the query with hardcoded mappings required for core.
        list($selectwhere, $params) = self::replace_sql_legacy($selectwhere, $params);

        try {
            return $DB->count_records_select('log', $selectwhere, $params);
        } catch (\moodle_exception $ex) {
            debugging("error converting legacy event data " . $ex->getMessage() . $ex->debuginfo, DEBUG_DEVELOPER);
            return 0;
        }
    }
1174693
private function buildWhere()
    {
        $sql = ' ';
        //join
        if ($this->_sql['join']) {
            foreach ($this->_sql['join'] as $key => $join) {
                foreach ($join as list($table, $con1, $op, $con2)) {
                    $table = $this->prefix . $table;
                    $table = $this->formatTable($table);
                    $sql .= $key . ' ' . $table . ' on ' . $con1 . ' ' . $op . ' ' . $con2 . ' ';
                }
            }
        }
        //where
        if ($this->_sql['where'] || $this->_sql['whereraw'] || $this->_sql['findinset'] || $this->_sql['wheretuple']) {
            $sql .= 'where ';
            $haswhere = false;
            foreach ($this->_sql['where'] as $k => list($column, $op, $val, $type)) {
                $haswhere = true;
                if ($k !== 0) {
                    $sql .= $type . ' ';
                }
                switch ($op) {
                    case 'in':
                    case 'not in':
                        if (!is_array($val) && strpos(',', $val) !== false) {
                            $val = explode(',', $val);
                        }
                        if (is_array($val)) {
                            $val = array_map(function ($v) {
                                if (is_numeric($v) && $v < 65535) {
                                    return $v;
                                } else {
                                    return "'" . $v . "'";
                                }
                            }, $val);
                            $val = implode(',', $val);
                        }
                        $sql .= $column . ' ' . $op . ' (' . $val . ') ';
                        break;
                    case 'exists':
                    case 'not exists':
                        $sql .= ' ' . $op . "(" . $column . ') ';
                        break;
                    case 'not between':
                    case 'between':
                        if (!is_numeric($val[0])) {
                            $val[0] = "'" . $val[0] . "'";
                            $val[1] = "'" . $val[1] . "'";
                        }
                        $sql .= ' ' . $column . ' ' . $op . ' ' . $val[0] . ' and ' . $val[1];
                        break;
                    case 'is not':
                    case 'is':
                        $sql .= $column . ' ' . $op . ' null ';
                        break;
                    default:
                        if (!is_numeric($val) || $val > 65535) {
                            $val = "'" . $val . "'";
                        }
                        $sql .= $column . ' ' . $op . ' ' . $val . ' ';
                }
            }
            //find_in_set值
            foreach ($this->_sql['findinset'] as $k => list($column, $val, $type)) {
                if ($haswhere) {
                    $sql .= $type . ' ';
                    $haswhere = true;
                }
                $sql .= " find_in_set('$val',$column) ";
            }
            //where raw
            foreach ($this->_sql['whereraw'] as $raw) {
                $sql .= ' ' . $raw . ' ';
                $haswhere = true;
            }
            //where tuple
            foreach ($this->_sql['wheretuple'] as list($raw, $type)) {
                if ($haswhere) {
                    $sql .= $type . ' (' . $raw . ') ';
                } else {
                    $sql .= ' (' . $raw . ') ';
                    $haswhere = true;
                }
            }
        }
        return $sql;
    }
591968
public function orWhereRaw(string $sql, string ...$params)
    {
        $this->wConditions()->orRaw($sql, ...$params);

        return $this;
    }
131276
public function count($beanType,$addSQL = '',$params = array()) {
		$sql = "SELECT count(*) FROM {$this->safeTable($beanType)} ";
		if ($addSQL!='') $addSQL = ' WHERE '.$addSQL; 
		return (int) $this->adapter->getCell($sql.$addSQL,$params);
	}
125683
public function approvedWithPending(): ActiveQuery
    {
        return $this->andWhere([$this->statusAttribute => [Status::APPROVED, Status::PENDING]]);
    }
82142
public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null)
    {
        $where = $query->getWhere();
        if (!$where && !$this->wantsTemporary($query)) {
            $from = array_values($query->getFrom());
            $query->addWhere("{$from[0]}.\"MultiFormIsTemporary\" = '0'");
            return;
        }
        $filterKey = key($where[0]);
        if (strpos($filterKey, ".`ID` = ") === false
            && strpos($filterKey, ".ID = ") === false
            && strpos($filterKey, "ID = ") !== 0
            && !$this->wantsTemporary($query)
        ) {
            $from = array_values($query->getFrom());
            $query->addWhere("{$from[0]}.\"MultiFormIsTemporary\" = '0'");
        }
    }
963717
protected function addSearchClauses(
        SearchableSubquery $subquery,
        ColumnCollection $columns,
        array $words,
        $threshold
    ) {
        $whereBindings = $this->searchSelect($subquery, $columns, $words, $threshold);

        // For morphOne/morphMany support we need to port the bindings from JoinClauses.
        $joinBindings = collect($subquery->getQuery()->joins)->flatMap(function ($join) {
            return $join->getBindings();
        })->all();

        $this->addBinding($joinBindings, 'select');

        // Developer may want to skip the score threshold filtering by passing zero
        // value as threshold in order to simply order full result by relevance.
        // Otherwise we are going to add where clauses for speed improvement.
        if ($threshold > 0) {
            $this->searchWhere($subquery, $columns, $words, $whereBindings);
        }

        $this->query->where('relevance', '>=', new Expression(number_format($threshold, 2)));

        $this->query->orders = array_merge(
            [['column' => 'relevance', 'direction' => 'desc']],
            (array) $this->query->orders
        );
    }
1166176
private function combineSelectQuery($sqlParts)
    {
        // Add select columns and tables.
        $output = "SELECT " . $sqlParts['select'] . " FROM " . $sqlParts['from'];

        // Add where when defined.
        if ($sqlParts['where'] !== null) {
            // Add where
            $output .= " WHERE " . $sqlParts['where'];
        }

        // TODO: Add other parts.


        return $output;
    }
323
public function select($table = '', $column = [], $arrayWhere = [], $other = '')
    {
        // handle column array data
        if (!is_array($column)) {
            $column = [];
        }
        // get field if pass otherwise use *
        $sField = count($column) > 0 ? implode(', ', $column) : '*';
        // check if table name not empty
        if (!empty($table)) {
            // if more then 0 array found in where array
            if (count($arrayWhere) > 0 && is_array($arrayWhere)) {
                // set class where array
                $this->data = $arrayWhere;
                // parse where array and get in temp var with key name and val
                if (strstr(key($arrayWhere), ' ')) {
                    $tmp = $this->customWhere($this->data);
                    // get where syntax with namespace
                    $where = $tmp['where'];
                } else {
                    $tmp = [];
                    foreach ($arrayWhere as $k => $v) {
                        $tmp[] = "$k = :s_$k";
                    }
                    // join temp array with AND condition
                    $where = implode(' AND ', $tmp);
                }
                // unset temp var
                unset($tmp);
                // set class sql property
                $this->sql = "SELECT $sField FROM `$table` WHERE $where $other;";
            } else {
                $this->sql = "SELECT $sField FROM `$table` $other;";  // if no where condition pass by user
            }

            // pdo prepare statement with sql query
            $this->STH = $this->prepare($this->sql);
            // if where condition has valid array number

            if (count($arrayWhere) > 0 && is_array($arrayWhere)) {
                $this->_bindPdoNameSpace($arrayWhere); // bind pdo param
            }

            // use try catch block to get pdo error
            try {
                // check if pdo execute
                if ($this->STH->execute()) {
                    // set class property with affected rows
                    $this->affectedRows = $this->STH->rowCount();
                    // set class property with sql result
                    $this->results = $this->STH->fetchAll();
                    // close pdo
                    $this->STH->closeCursor();
                    // return self object
                    return $this;
                } else {
                    self::error($this->STH->errorInfo());  // catch pdo error
                }
            } catch (\PDOException $e) {
                // get pdo error and pass on error method
                self::error($e->getMessage() . ': ' . __LINE__);
            } // end try catch block to get pdo error
        } else { // if table name empty
            self::error('Table name not found..');
        }
    }
234917
protected function _createSqlActiveSnippet($forceCoreTable)
    {
        // check if article is still active
        $sQ = $this->getActiveCheckQuery($forceCoreTable);

        // stock and variants check
        $sQ .= $this->getStockCheckQuery($forceCoreTable);

        return $sQ;
    }
1300095
public function executeSelect($tableName, $columns = '*', $where = null, $afterWhere = '')
    {
        return $this->pdo->executeSelect($tableName, $columns, $where, $afterWhere);
    }
505439
public function add($data, $sqlQuery = false)
    {
        if(!is_array($data) || count($data) == 0) {
            echo 'no data to save'; //no argument
            exit;
        }
        $sql = $this->buildQuery('insert', $data);
        if($sqlQuery === true) {
            return $this->getQuery();
        }
        $result = $this->executeQuery($sql);
        return $result;
    }