query base
@param type $fields
@param type $languageEmpty
@param type $languageStrict
@return string
770219
protected function initQuery() {
        
        $table = $this->getOptions()['table'];
        
        return $this->getDriverEscaper()->dbCommand('SELECT') . ' ' .
                    $this->getDriverEscaper()->dbCommand('DISTINCT') .'(' .
                    $this->getDriverEscaper()->reserved('subject') . ')' . ' ' . 
                    $this->operationSeparator .
                    $this->getDriverEscaper()->dbCommand('FROM') . ' ' .
                    $this->getDriverEscaper()->reserved($table) . ' ' .
                    $this->operationSeparator .
                    $this->getDriverEscaper()->dbCommand('WHERE') . ' ' .
                    $this->getDriverEscaper()->reserved('subject') . ' ' .
                    $this->getDriverEscaper()->dbCommand('IN') . 
                    $this->operationSeparator . '(' .
                    $this->getDriverEscaper()->dbCommand('SELECT') .  ' ' .
                    $this->getDriverEscaper()->reserved('subject') .  ' ' .
                    $this->getDriverEscaper()->dbCommand('FROM') . ' ' .
                    $this->operationSeparator . '(' .
                    $this->getDriverEscaper()->dbCommand('SELECT') . ' ' . 
                    $this->getDriverEscaper()->dbCommand('DISTINCT') .'(' .
                    $this->getDriverEscaper()->reserved('subject') . ')' . ' ' . 
                    $this->operationSeparator .
                    $this->getDriverEscaper()->dbCommand('FROM') . ' ' . 
                    $this->getDriverEscaper()->reserved($table) . ' ' .
                    $this->getDriverEscaper()->dbCommand('WHERE') .  
                    $this->operationSeparator ;
    }
1147917
public function select(string $fields): QueryBuilderInterface
	{
		// Split fields by comma
		$fieldsArray = explode(',', $fields);
		$fieldsArray = array_map('mb_trim', $fieldsArray);

		// Split on 'As'
		foreach ($fieldsArray as $key => $field)
		{
			if (stripos($field, 'as') !== FALSE)
			{
				$fieldsArray[$key] = preg_split('` as `i', $field);
				$fieldsArray[$key] = array_map('mb_trim', $fieldsArray[$key]);
			}
		}

		// Quote the identifiers
		$safeArray = $this->driver->quoteIdent($fieldsArray);

		unset($fieldsArray);

		// Join the strings back together
		for($i = 0, $c = count($safeArray); $i < $c; $i++)
		{
			if (\is_array($safeArray[$i]))
			{
				$safeArray[$i] = implode(' AS ', $safeArray[$i]);
			}
		}

		$this->state->appendSelectString(implode(', ', $safeArray));

		return $this;
	}
255740
public function currentLanguage(string $language, array $queryParams = [], string $separator = '&'): string
	{
		return $this->current($queryParams, $separator, $language);
	}
1355847
private function resolveFromLanguage(array $parameters): ?Language
    {
        if (isset($parameters['fromLanguage'])) {
            return $parameters['fromLanguage'];
        }

        if (isset($parameters['fromLanguageCode'])) {
            return $this->loadLanguage($parameters['fromLanguageCode']);
        }

        return null;
    }
148784
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
    {
        if ($platform->getName() === 'mysql') {
            /** @var MySqlPlatform $platform */
            return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration)
                // . " CHARACTER SET utf8"
                . " " . $platform->getColumnCollationDeclarationSQL('utf8_bin')
                . " COMMENT '(DC2Type:binary_string)'"
                ;
        }

        return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
    }
730061
public function getByLangOrFirst($key, $languageId)
    {
        $templateId = EmailTemplate::getIdByKey($key);

        if ($template = EmailTemplateTranslation::findOne([
            'template_id' => $templateId,
            'language_id' => $languageId
        ])) {
            return Template::buildTemplate($template);
        }
        elseif ($templates = EmailTemplateTranslation::findAll([
            'template_id' => $templateId
        ])) {
            return Template::buildTemplate($templates[0]);
        }

        return null;
    }
1234637
static public function fetchTagTreeCount( $parentTagID, $depth, $depthOperator, $includeSynonyms, $language = false )
    {
        if ( !is_numeric( $parentTagID ) || (int) $parentTagID < 0 )
            return array( 'result' => 0 );

        $params = array( 'IncludeSynonyms' => $includeSynonyms );

        if ( $depth !== false )
        {
            $params['Depth'] = $depth;
            $params['DepthOperator'] = $depthOperator;
        }

        if ( $language )
        {
            if ( !is_array( $language ) )
                $language = array( $language );
            eZContentLanguage::setPrioritizedLanguages( $language );
        }

        $tagsCount = eZTagsObject::subTreeCountByTagID( $params, $parentTagID );

        if ( $language )
            eZContentLanguage::clearPrioritizedLanguages();

        return array( 'result' => $tagsCount );
    }
1040334
public function filterByLanguagePresets($queryResult, array $presets) {
    $result = $queryResult;

    if (!empty($presets)) {
      $sysLanguageUid = $this->languageService->getSysLanguageUid();
      $preset         = intval($presets[$sysLanguageUid]);

      if (isset($preset)) {
        $result = [];

        foreach ($queryResult as $object) {
          $uid = $object->getSysLanguageUid();

          if (isset($uid) && $uid == $preset) {
            $result[] = $object;
          }
        }
      }
    }

    return $result;
  }
124816
public function getById($languageId, array $queryParams = [])
    {
        $response = $this->api->languages()->getById($languageId, $queryParams);

        return new LanguageResponse($response);
    }
202844
public function getMappedField($field, $language, $fallbackLanguage = null)
    {
        if ($this->mappedFields->containsKey($language)) {
            $mappedField = $this->mappedFields->get($language);
        } elseif ($this->mappedFields->containsKey($fallbackLanguage)) {
            $mappedField = $this->mappedFields->get($fallbackLanguage);
        } else {
            foreach ($this->mappedFields as $testMappedField) {
                if ($testMappedField->getLanguage() === $language) {
                    $mappedField = $testMappedField;
                    break;
                }
            }
            if (!isset($mappedField)) {
                foreach ($this->mappedFields as $testMappedField) {
                    if ($testMappedField->getLanguage() === $fallbackLanguage) {
                        $mappedField = $testMappedField;
                        break;
                    }
                }
            }
            if (!isset($mappedField)) {
                return null;
            }
        }

        if ($field === 'page') {
            if ($mappedField->getPage()) {
                return $mappedField->getPage();
            } else {
                $field = 'backend';
            }
        }

        if ($field === 'navigation') {
            if ($mappedField->getNavigation()) {
                return $mappedField->getNavigation();
            } else {
                $field = 'backend';
            }
        }

        if ($field === 'backend') {
            return $mappedField->getBackend();
        }

        if ($field === 'date' && $mappedField->getDate()) {
            return $mappedField->getDate();
        }

        if ($field === 'forward' && $mappedField->getForward()) {
            return json_decode($mappedField->getForward(), true);
        }

        if ($field === 'custom1' && $mappedField->getCustom1()) {
            return $mappedField->getCustom1();
        } elseif ($field === 'custom2' && $mappedField->getCustom2()) {
            return $mappedField->getCustom2();
        } elseif ($field === 'custom3' && $mappedField->getCustom3()) {
            return $mappedField->getCustom3();
        } elseif ($field === 'custom4' && $mappedField->getCustom4()) {
            return $mappedField->getCustom4();
        } elseif ($field === 'custom5' && $mappedField->getCustom5()) {
            return $mappedField->getCustom5();
        }

        return null;
    }
1013587
public function translateLanguage($args, array $languages = null, $array_support = false, $html_out = false)
    {
        /** @var Language $language */
        $language = $this->grav['language'];

        return $language->translate($args, $languages, $array_support, $html_out);
    }
24135
private function getLanguageQuery()
    {
        $languageQuery = $this->dbHandler->createSelectQuery();
        $languageQuery
            ->select(
                $languageQuery->expr->searchedCase(
                    [
                        $languageQuery->expr->lAnd(
                            $languageQuery->expr->eq(
                                $this->dbHandler->quoteColumn('initial_language_id'),
                                ':languageId'
                            ),
                            // wrap bitwise check into another "neq" to provide cross-DBMS compatibility
                            $languageQuery->expr->neq(
                                $languageQuery->expr->bitAnd(
                                    $this->dbHandler->quoteColumn('language_mask'),
                                    ':languageId'
                                ),
                                0
                            )
                        ),
                        $languageQuery->expr->bitOr(
                            ':languageId',
                            1
                        ),
                    ],
                    ':languageId'
                )
            )
            ->from('ezcontentobject')
            ->where(
                $languageQuery->expr->eq(
                    'id',
                    ':contentId'
                )
            );

        return $languageQuery;
    }
1020038
protected function getFieldCondition(SelectQuery $query, array $languageSettings, $fieldTableName)
    {
        // 1. Use main language(s) by default
        if (empty($languageSettings['languages'])) {
            return $query->expr->gt(
                $query->expr->bitAnd(
                    $this->dbHandler->quoteColumn('initial_language_id', 'ezcontentobject'),
                    $this->dbHandler->quoteColumn('language_id', $fieldTableName)
                ),
                $query->bindValue(0, null, PDO::PARAM_INT)
            );
        }

        // 2. Otherwise use prioritized languages
        $leftSide = $query->expr->bitAnd(
            $query->expr->sub(
                $this->dbHandler->quoteColumn('language_mask', 'ezcontentobject'),
                $query->expr->bitAnd(
                    $this->dbHandler->quoteColumn('language_mask', 'ezcontentobject'),
                    $this->dbHandler->quoteColumn('language_id', $fieldTableName)
                )
            ),
            $query->bindValue(1, null, PDO::PARAM_INT)
        );
        $rightSide = $query->expr->bitAnd(
            $this->dbHandler->quoteColumn('language_id', $fieldTableName),
            $query->bindValue(1, null, PDO::PARAM_INT)
        );

        for ($index = count($languageSettings['languages']) - 1, $multiplier = 2; $index >= 0; $index--, $multiplier *= 2) {
            $languageId = $this->languageHandler
                ->loadByLanguageCode($languageSettings['languages'][$index])->id;

            $addToLeftSide = $query->expr->bitAnd(
                $query->expr->sub(
                    $this->dbHandler->quoteColumn('language_mask', 'ezcontentobject'),
                    $query->expr->bitAnd(
                        $this->dbHandler->quoteColumn('language_mask', 'ezcontentobject'),
                        $this->dbHandler->quoteColumn('language_id', $fieldTableName)
                    )
                ),
                $query->bindValue($languageId, null, PDO::PARAM_INT)
            );
            $addToRightSide = $query->expr->bitAnd(
                $this->dbHandler->quoteColumn('language_id', $fieldTableName),
                $query->bindValue($languageId, null, PDO::PARAM_INT)
            );

            if ($multiplier > $languageId) {
                $factor = $multiplier / $languageId;
                for ($shift = 0; $factor > 1; $factor = $factor / 2, $shift++);
                $factorTerm = ' << ' . $shift;
                $addToLeftSide .= $factorTerm;
                $addToRightSide .= $factorTerm;
            } elseif ($multiplier < $languageId) {
                $factor = $languageId / $multiplier;
                for ($shift = 0; $factor > 1; $factor = $factor / 2, $shift++);
                $factorTerm = ' >> ' . $shift;
                $addToLeftSide .= $factorTerm;
                $addToRightSide .= $factorTerm;
            }

            $leftSide = $query->expr->add($leftSide, "($addToLeftSide)");
            $rightSide = $query->expr->add($rightSide, "($addToRightSide)");
        }

        return $query->expr->lAnd(
            $query->expr->gt(
                $query->expr->bitAnd(
                    $this->dbHandler->quoteColumn('language_mask', 'ezcontentobject'),
                    $this->dbHandler->quoteColumn('language_id', $fieldTableName)
                ),
                $query->bindValue(0, null, PDO::PARAM_INT)
            ),
            $query->expr->lt($leftSide, $rightSide)
        );
    }
1188940
public function getAllWithoutPagination($lang = "")
    {
        $result = DB::table('categories')->join('post_type', 'post_type.postTypeID', 'categories.postTypeID')->orderBy('name', 'postTypeID')->get();
        return Language::filterRows($result, false);
    }
930798
protected function getContentDbFieldsStmt(array $fields)
    {
        $query = $this->databaseHandler->createSelectQuery();
        $query->select($fields)
            ->from($this->databaseHandler->quoteTable(self::CONTENTOBJECT_TABLE))
            ->where($query->expr->eq('status', ContentInfo::STATUS_PUBLISHED));
        $stmt = $query->prepare();
        $stmt->execute();

        return $stmt;
    }
283160
public function translate(string $text, string $languageTo, string $languageFrom = ''): TranslateResponse
    {
        return $this->getTranslateApi()->translate($text, new Language($languageTo), new Language($languageFrom));
    }
206911
public function getSimpleTreeRecursive($fields=array(),$transfields=array(),$lang='',$wh=array()){
		$list=$this->getSimpleTree($fields,$transfields,$lang,$wh);
		if(!is_array($list)){
			return array();
			}
		$tree=array();
		foreach($list as $li){
			$id=(int)$li->{$this->primaryKeyName};
		        $ti=$li;
			//TODO: finish children
			$ti->children=array();
			$tree[]=$ti;
			}
		return $tree;
		}