Compiles any like's into the query

@param array &$aData The data array

@return void
518696
protected function getCountCommonCompileLikes(array &$aData)
    {
        $oDb = Factory::service('Database');

        $aLikes = [
            'like'        => 'AND',
            'or_like'     => 'OR',
            'not_like'    => 'AND',
            'or_not_like' => 'OR',
        ];

        $aLikeCompiled = [];

        foreach ($aLikes as $sLikeType => $sLikeGlue) {

            if (!empty($aData[$sLikeType])) {

                $aLikeCompiled[$sLikeType] = [];

                if (is_array($aData[$sLikeType])) {

                    /**
                     * The value is an array. For each element we need to compile as appropriate
                     * and add to $aLikeCompiled.
                     */

                    foreach ($aData[$sLikeType] as $mWhere) {

                        if (is_string($mWhere)) {

                            /**
                             * The value is a straight up string, assume this is a compiled
                             * where string,
                             */

                            $aLikeCompiled[$sLikeType][] = $mWhere;

                        } else {

                            /**
                             * The value is an array, try and determine the various parts
                             * of the query. We use strings which are unlikely to be found
                             * as falsey values (such as null) are perfectly likely.
                             */

                            //  Work out column
                            $mColumn = isset($mWhere['column']) ? $mWhere['column'] : '[NAILS-COL-NOT-FOUND]';

                            if ($mColumn === '[NAILS-COL-NOT-FOUND]') {
                                $mColumn = isset($mWhere[0]) && is_string($mWhere[0]) ? $mWhere[0] : null;
                            }

                            //  Work out value
                            $mVal = isset($mWhere['value']) ? $mWhere['value'] : '[NAILS-VAL-NOT-FOUND]';

                            if ($mVal === '[NAILS-VAL-NOT-FOUND]') {
                                $mVal = isset($mWhere[1]) ? $mWhere[1] : null;
                            }

                            //  Escaped?
                            $bEscape = isset($mWhere['escape']) ? (bool) $mWhere['escape'] : '[NAILS-ESCAPE-NOT-FOUND]';

                            if ($bEscape === '[NAILS-ESCAPE-NOT-FOUND]') {
                                $bEscape = isset($mWhere[2]) ? $mWhere[2] : true;
                            }

                            if ($bEscape) {
                                $mVal = $oDb->escape_like_str($mVal);
                            }

                            //  If the $mColumn is an array then we should concat them together
                            if (is_array($mColumn)) {
                                $mColumn = 'CONCAT_WS(" ", ' . implode(',', $mColumn) . ')';
                            }

                            //  Got something?
                            if ($mColumn) {
                                switch ($sLikeType) {

                                    case 'like' :
                                    case 'or_like' :
                                        $aLikeCompiled[$sLikeType][] = $mColumn . ' LIKE "%' . $mVal . '%"';
                                        break;

                                    case 'not_like' :
                                    case 'or_not_like' :
                                        $aLikeCompiled[$sLikeType][] = $mColumn . ' NOT LIKE "%' . $mVal . '%"';
                                        break;
                                }
                            }
                        }
                    }

                } elseif (is_string($aData[$sLikeType])) {

                    /**
                     * The value is a straight up string, assume this is a compiled
                     * where string,
                     */

                    $aLikeCompiled[$sLikeType][] = $aData[$sLikeType];
                }
            }
        }

        /**
         * Now we need to compile all the conditionals into one big super query.
         * $aWhereStr is an array of the compressed where strings... will make
         * sense shortly...
         */

        if (!empty($aLikeCompiled)) {

            $aWhereStr = [];

            foreach ($aLikeCompiled as $sLikeType => $sValue) {
                $aWhereStr[] = '(' . implode(' ' . $aLikes[$sLikeType] . ' ', $sValue) . ')';
            }

            //  And reduce $aWhereStr to an actual string, like the name suggests
            $aWhereStr = implode(' AND ', $aWhereStr);
            $oDb->where($aWhereStr);
        }
    }
467276
protected function compile()
    {
        if (!$this->bootstrap_buttonStyle) {
            $this->bootstrap_buttonStyle = 'btn-default';
        }

        $buttons = Factory::createFromFieldset($this->bootstrap_buttons);
        $buttons->eachChild(array($this, 'addButtonStyle'));

        $this->Template->buttons = $buttons;
    }
122882
public function compile(): void
	{
		// Get teplate contents

		$contents = $this->fileSystem->get($this->template);

		// Compile template

		foreach($this->compileOrder as $method)
		{
			$contents = $this->$method($contents);
		}

		// Store compiled template

		$this->fileSystem->put($this->cachePath . '/' . md5($this->template) . '.php', trim($contents));
	}
814325
public function compile()
    {
        $sql = array();

        if (isset($this->select)) {
            $sql[] = 'SELECT ' . implode(',', $this->select);
        }

        if (isset($this->update)) {
            $sql[] = 'UPDATE';
            $sql[] = $this->update['table'];
            $sql[] = 'SET';

            $blocks = array();
            foreach ($this->update['values'] as $key => $value) {
                $blocks[] = $key . ' = ' . $value;
            }

            $sql[] = implode(',', $blocks);
        }

        if (isset($this->delete)) {
            $sql[] = "DELETE ";
        }

        if (isset($this->insert)) {
            $sql[] = 'INSERT INTO';
            $sql[] = $this->insert['table'];

            $fields = array();
            $replaces = array();

            foreach ($this->insert['values'] as $key => $value) {
                $fields[] = '`' . $key . '`';
                $replaces[] = $value;
            }

            $sql[] = '(' . implode(',', $fields) . ')';
            $sql[] = (count($this->insert['values']) > 1) ? 'VALUES' : 'VALUE';
            $sql[] = '(' . implode(',', $replaces) . ')';
        }

        if (isset($this->replace)) {
            $sql[] = 'REPLACE INTO';
            $sql[] = $this->replace['table'];

            $fields = array();
            $replaces = array();

            foreach ($this->replace['values'] as $key => $value) {
                $fields[] = '`' . $key . '`';
                $replaces[] = $value;
            }

            $sql[] = '(' . implode(',', $fields) . ')';
            $sql[] = (count($this->replace['values']) > 1) ? 'VALUES' : 'VALUE';
            $sql[] = '(' . implode(',', $replaces) . ')';
        }

        if (isset($this->from)) {
            $sql[] = 'FROM ' . implode(',', $this->from);
        }

        foreach ($this->where as $index => $where) {

            if (!is_string($where['column'])) {
                throw new \OtherCode\Database\Exceptions\QueryException("The column field is not a string in where clause.");
            }

            if (!is_string($where['operator']) || !in_array($where['operator'], $this->operators)) {
                throw new \OtherCode\Database\Exceptions\QueryException("Invalid operator in where clause.");
            }

            if (gettype($where['value']) == 'string' && $where['quoted'] === true) {
                $where['value'] = '"' . $where['value'] . '"';
            }

            unset($where['quoted']);

            $sentence = ($index == 0) ? "WHERE " : "AND ";
            $sql[] = $sentence . implode(" ", $where);

        }

        if (isset($this->group)) {
            $sql[] = 'GROUP BY ' . $this->group;
        }

        foreach ($this->order as $index => $order) {

            if (!in_array($order[1], array('ASC', 'DESC'))) {
                throw new \OtherCode\Database\Exceptions\QueryException('Invalid order by value, must be ASC or DESC.');
            }

            $sql[] = 'ORDER BY ' . implode(" ", $order);
        }

        if (isset($this->limit)) {
            $sql[] = 'LIMIT ' . implode(" ", $this->limit);
        }

        return trim(implode(" ", $sql));
    }
27352
public function compile(Compiler $compiler): void
    {
        $compiler
            ->addDebugInfo($this)
            ->write(sprintf('$this->env->getExtension(\'%s\')', $this->extension))
            ->raw(PHP_EOL)
            ->indent()
        ;

        $this->compileTags($compiler);

        $compiler
            ->outdent()
            ->raw(';'.PHP_EOL)
        ;
    }
1028809
private function compileQuery()
    {
        if ($this->queryConfiguration->isGlobalSearch()) {
            $this->compileGlobalQuery();
        } elseif ($this->queryConfiguration->isColumnSearch()) {
            $this->compileColumnQuery();
        }
    }
804821
protected function compile()
	{
		$data = deserialize($this->columnset, true);
		$articles = array();

		$container = \Netzmacht\ColumnSet\ColumnSet::prepareContainer($this->columnset_id);
		$i=0;

		foreach($data as $article) {
			$articles[] = array(
				'article' => $this->getArticle($article['article'], false, !((bool) $this->articleMarkup)),
				'class'   => $container[$i++][0],
				'id'      => $article['article'],
			);
		}

		$this->Template->articles = $articles;
	}
703898
public function setComplete($iPaymentId, $aData = []): bool
    {
        $aData['status'] = self::STATUS_COMPLETE;
        return $this->update($iPaymentId, $aData);
    }
1148299
public function assign($aData)
    {
        if (!is_array($aData)) {
            return;
        }
        foreach ($aData as $sKey => $sValue) {
            $sFieldName = strtolower($this->_sTableName . '__' . $sKey);
            $this->$sFieldName = new \OxidEsales\Eshop\Core\Field($sValue);
        }
    }
500383
protected function &_NewElement(&$aData)
    {
        $oElement = false;
        $sTableObject = $this->sTableObject;
        if (array_key_exists('class', $aData)) {
            $sTableObject = $aData['class'];
        }

        // try to fetch the element from _items first
        $oElement = new $sTableObject();
        $oElement->table = $this->sTableName;
        $oElement->SetLanguage($this->iLanguageId);
        $oElement->LoadFromRow($aData);

        return $oElement;
    }
129857
private function checkEncodedData(array $encodedData): bool
    {
        $isValid = true;
        foreach ($encodedData as $locale => $namespaceResources) {
            $isValid = $isValid === true &&
                empty($locale) === false &&
                is_array($namespaceResources) === true && $this->checkNamespaceResources($namespaceResources);
        }

        return $isValid;
    }
41078
protected function compileStatement(array $match)
    {
        if (strpos($match[1], '@') !== false) {
            $match[0] = isset($match[3]) ? $match[1] . $match[3] : $match[1];
        } elseif (isset($this->directives[$match[1]])) {
            $match[0] = call_user_func($this->directives[$match[1]], isset($match[3]) ? $match[3] : null);
        } elseif (method_exists($this, $method = 'compile' . ucfirst($match[1]))) {
            $match[0] = $this->$method(isset($match[3]) ? $match[3] : null);
        }

        return isset($match[3]) ? $match[0] : $match[0] . $match[2];
    }
1160222
public function countAll($aData)
    {
        $this->getCountCommonEvent($aData);
        $oDb = Factory::service('Database');
        return $oDb->count_all_results($this->sTable . ' ' . $this->sTableAlias);
    }
1162710
public static function populatePageData(array &$aData)
    {
        /** @var Locale $oLocale */
        $oLocale       = Factory::service('Locale');
        $aData['page'] = (object) [
            'title'     => '',
            'html_lang' => $oLocale->get()->getLanguage(),
            'seo'       => (object) [
                'title'       => '',
                'description' => '',
                'keywords'    => '',
            ],
        ];
    }
610976
protected function getCountCommonCompileHavings(array &$aData)
    {
        $oDb = Factory::service('Database');

        /**
         * Handle having's
         *
         * This is an array of the various type of having that can be passed in via $aData.
         * The first element is the key and the second is how multiple items within the
         * group should be glued together.
         *
         * Each type of having is grouped in it's own set of parenthesis, multiple groups
         * are glued together with ANDs
         */

        $aHavings = [
            'having'    => 'AND',
            'or_having' => 'OR',
        ];

        $aHavingCompiled = [];

        foreach ($aHavings as $sHavingType => $sHavingGlue) {

            if (!empty($aData[$sHavingType])) {

                $aHavingCompiled[$sHavingType] = [];

                if (is_array($aData[$sHavingType])) {

                    /**
                     * The value is an array. For each element we need to compile as appropriate
                     * and add to $aHavingCompiled.
                     */

                    foreach ($aData[$sHavingType] as $mHaving) {

                        if (is_string($mHaving)) {

                            /**
                             * The value is a straight up string, assume this is a compiled
                             * having string,
                             */

                            $aHavingCompiled[$sHavingType][] = $mHaving;

                        } else {

                            /**
                             * The value is an array, try and determine the various parts
                             * of the query. We use strings which are unlikely to be found
                             * as falsey values (such as null) are perfectly likely.
                             */

                            //  Work out column
                            $mColumn = isset($mHaving['column']) ? $mHaving['column'] : '[NAILS-COL-NOT-FOUND]';

                            if ($mColumn === '[NAILS-COL-NOT-FOUND]') {
                                $mColumn = isset($mHaving[0]) && is_string($mHaving[0]) ? $mHaving[0] : null;
                            }

                            //  Work out value
                            $mVal = isset($mHaving['value']) ? $mHaving['value'] : '[NAILS-VAL-NOT-FOUND]';

                            if ($mVal === '[NAILS-VAL-NOT-FOUND]') {
                                $mVal = isset($mHaving[1]) ? $mHaving[1] : null;
                            }

                            //  Escaped?
                            $bEscape = isset($mHaving['escape']) ? (bool) $mHaving['escape'] : '[NAILS-ESCAPE-NOT-FOUND]';

                            if ($bEscape === '[NAILS-ESCAPE-NOT-FOUND]') {
                                $bEscape = isset($mHaving[2]) ? $mHaving[2] : true;
                            }

                            //  If the $mColumn is an array then we should concat them together
                            if (is_array($mColumn)) {
                                $mColumn = 'CONCAT_WS(" ", ' . implode(',', $mColumn) . ')';
                            }

                            //  Test if there's an SQL operator
                            if (!(bool) preg_match('/(<|>|!|=|\sIS NULL|\sIS NOT NULL|\sEXISTS|\sBETWEEN|\sLIKE|\sIN\s*\(|\s)/i', trim($mColumn))) {
                                $sOperator = is_null($mVal) ? ' IS ' : '=';
                            } else {
                                $sOperator = '';
                            }

                            //  Got something?
                            if ($mColumn) {

                                switch ($sHavingType) {

                                    case 'having' :
                                    case 'or_having' :

                                        if ($bEscape) {
                                            $mVal = $oDb->escape($mVal);
                                        }

                                        $aHavingCompiled[$sHavingType][] = $mColumn . $sOperator . $mVal;
                                        break;
                                }
                            }
                        }
                    }

                } elseif (is_string($aData[$sHavingType])) {

                    /**
                     * The value is a straight up string, assume this is a compiled
                     * having string,
                     */

                    $aHavingCompiled[$sHavingType][] = $aData[$sHavingType];
                }
            }
        }

        /**
         * Now we need to compile all the conditionals into one big super query.
         * $aHavingStr is an array of the compressed having strings... will make
         * sense shortly...
         */

        if (!empty($aHavingCompiled)) {

            $aHavingStr = [];

            foreach ($aHavingCompiled as $sHavingType => $sValue) {
                if (!empty($sValue)) {
                    $aHavingStr[] = '(' . implode(' ' . $aHavings[$sHavingType] . ' ', $sValue) . ')';
                }
            }

            //  And reduce $aHavingStr to an actual string, like the name suggests
            if (!empty($aHavingStr)) {
                $aHavingStr = implode(' AND ', $aHavingStr);
                $oDb->having($aHavingStr);
            }
        }
    }
210779
protected function compile($text, $sandbox=false){

        // disable php in sandbox mode
        if ($sandbox) {
            $text = str_replace( array("<?","?>"), array("&lt;?","?&gt;"), $text);
        }

        foreach ($this->compilers as $compiler) {
            $method = "compile_{$compiler}";
            $text   = $this->{$method}($text);
        }

        if($sandbox) {

            $lines = explode("\n", $text);

            foreach ($lines as $ln => &$line) {
                if($errors = $this->check_security($line)) {
                    return 'illegal call(s): '.implode(", ", $errors)." - on line ".$ln.($this->srcinfo ? ' ('.$this->srcinfo.') ':'');
                }
            }
        }

        if($errors = $this->check_syntax($text)) {

            if($this->srcinfo) $errors[] = '('.$this->srcinfo.')';

            return implode("\n", $errors);
        }

        return $text;
    }
678901
protected function compile() {
        $this->import('Database');
        $arrWorkshop = $this->Database->prepare("SELECT * FROM tl_workshop WHERE id = ?")
            ->execute($this->arrData['wb_workshop'])->fetchAssoc();
        $arrWorkshop['time_string'] = WBGym::workshopTimeString($arrWorkshop);  
        
        //unset non-active dates, they are saved in the DB due to the contao DCA behaviour
        if(!$arrWorkshop['isAll']) {
            unset($arrWorkshop['weekday_all']);
        }
        if(!$arrWorkshop['isA']) {
            unset($arrWorkshop['weekday_a']);
        }
        if(!$arrWorkshop['isB']) {
            unset($arrWorkshop['weekday_b']);
        }
        
        $arrWorkshop['next'] = date('d.m.Y',strtotime(WBCalendar::getNextRecurring($arrWorkshop['weekday_all'],$arrWorkshop['weekday_a'],$arrWorkshop['weekday_b'])));

        $this->Template->workshop = $arrWorkshop;
    }