Adding folder check

@param array  $whereQuery SQL condition array
@param string $fullQuery  SQL query string

@return string
350167
protected function _prepareWhereQuery($whereQuery, $fullQuery)
    {
        $database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
        $query = parent::_prepareWhereQuery($whereQuery, $fullQuery);
        $config = \OxidEsales\Eshop\Core\Registry::getConfig();
        $folders = $config->getConfigParam('aOrderfolder');
        $folder = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('folder');
        // Searching for empty oxfolder fields
        if ($folder && $folder != '-1') {
            $query .= " and ( oxorder.oxfolder = " . $database->quote($folder) . " )";
        } elseif (!$folder && is_array($folders)) {
            $folderNames = array_keys($folders);
            $query .= " and ( oxorder.oxfolder = " . $database->quote($folderNames[0]) . " )";
        }

        return $query;
    }
1289072
protected function whereInRaw(Builder $query, $where)
    {
        if (! empty($where['values'])) {
            return $this->wrap($where['column']).' in ('.implode(', ', $where['values']).')';
        }

        return '0 = 1';
    }
704974
private function addConditionsToSqlWhithWhereIn(): string
    {
        if (count($this->wheresIn) === 0) {
            throw new OrmException('Argument 2 passed to "whereIn()" can not be an empty array.');
        }
        
        $paramsWhereIn = " ( ";

        foreach ($this->wheresIn as $value) {                
            $paramsWhereIn .= " ?, ";

            $this->wheresBindValue[] = $value;
        }

        $this->wheresIn = [];

        return rtrim($paramsWhereIn, ', ')." ) ";
    }
778424
public function makeUrl( $path = '', array $query = [], bool $context = false, bool $full = null ): string
	{
		if( is_null($full) )
		{
			$url = $this->base;
		}
		else if( $full )
		{
			$url = $this->getPrefix();
		}
		else
		{
			$url = $this->isBasePrefix() ? $this->base_prefix : "/";
		}

		if( is_array($path) )
		{
			$path = implode('/', $path);
		}
		else if( strlen($path) && $path[0] === "/" )
		{
			$path = substr($path, 1);
		}

		if( $context && $this->isContext() )
		{
			if( strlen($path) )
			{
				$path = substr($this->context, 1) . $path;
			}
			else
			{
				$path = trim($this->context, "/");
			}
		}

		return $this->getModeUrl($url, $path, $query);
	}
585886
protected function seed($fullPath, $table)
    {
         if (class_exists($fullPath)) {
            if ($this->option('class')) {
                $params['--class'] = $this->option('class');
            } else {
                $params['--class'] = $fullPath;
            }
            if ($option = $this->option('database')) {
                $params['--database'] = $option;
            }
            if ($option = $this->option('force')) {
                $params['--force'] = $option;
            }
            $this->call('db:seed', $params);
            $this->info('Seed: '. $table);
        }
    }
229757
private Where<ExtendedRelation, Long> addToWhere(
			QueryBuilder<ExtendedRelation, Long> qb,
			Where<ExtendedRelation, Long> where) {
		if (where == null) {
			where = qb.where();
		} else {
			where.and();
		}
		return where;
	}
446060
protected function get_file_id_by_path(\repository_onedrive\rest $client, $fullpath) {
        $fields = "id";
        try {
            $response = $client->call('get_file_by_path', ['fullpath' => $fullpath, '$select' => $fields]);
        } catch (\core\oauth2\rest_exception $re) {
            return false;
        }
        return $response->id;
    }
1092597
protected function getConditionStringFromQueryBuilder(QueryBuilder $query)
    {
        $initialQueryChunks = explode('where ', $query->toSql());

        if (count($initialQueryChunks) == 1) {
            throw new InvalidArgumentException(
                'The query builder instance must have a where clause to build a condition string from'
            );
        }

        $queryChunks = explode('?', $initialQueryChunks[1]);
        $chunkCount  = count($queryChunks);
        $bindings    = $query->getBindings();
        $whereString = '';

        for ($i = 0; $i < $chunkCount; $i++) {

            $whereString .= $queryChunks[ $i ];

            if (isset($bindings[ $i ])) {

                if (gettype($bindings[ $i ]) === 'string') {
                    $whereString .= '"' . $bindings[ $i ] . '"';
                }
            }
        }

        return $whereString;
    }
537475
protected function compileWheres(array $wheres = [], $query = '')
    {
        foreach ($wheres as $where) {
            $query .= $this->compileWhere($where);
        }

        return $query;
    }
1032975
function addQuery() {
		if( !isset( $this->query ) ) {
			return FALSE;
		}

		$this->queries[] = $return = trim($this->query);

		unset( $this->query );

		return $return;
	}
458
private static function _setWhere($where, QueryBuilder $query, string $primaryKey = "id") : QueryBuilder
    {
        if(!is_array($where)) {
            return $query->where([
                $primaryKey => $where
            ]);
        }

        $columns = $where;

        unset($columns["ORDER BY"]);
        unset($columns["LIMIT"]);
        unset($columns["OFFSET"]);

        if(!empty($columns)) {
            $query->where($columns);
        }

        if(isset($where["ORDER BY"])) {
            $order = $where["ORDER BY"];
            if(!is_array($order)) {
                $order = [$order];
            }

            $query->order(... $order);
        }
        if(isset($where["LIMIT"])) {
            $limit = $where["LIMIT"];
            if(!is_array($limit)) {
                $limit = [$limit];
            }

            $query->limit(... $limit);
        }
        if(isset($where["OFFSET"])) {
            $query->offset($where["OFFSET"]);
        }

        return $query;
    }
111758
private function makeEntityQuery(
      $options,
      $selectors,
      $etypeDirty,
      $subquery = false
  ) {
    $fullQueryCoverage = true;
    $sort = $options['sort'] ?? 'cdate';
    $etype = '_'.SQLite3::escapeString($etypeDirty);
    $queryParts = $this->iterateSelectorsForQuery($selectors, function ($value) use ($options, $etypeDirty, &$fullQueryCoverage) {
      $subquery = $this->makeEntityQuery(
          $options,
          [$value],
          $etypeDirty,
          true
      );
      $fullQueryCoverage = $fullQueryCoverage && $subquery['fullCoverage'];
      return $subquery['query'];
    }, function (&$curQuery, $key, $value, $typeIsOr, $typeIsNot) use ($etype, &$fullQueryCoverage) {
      $clauseNot = $key[0] === '!';
      // Any options having to do with data only return if the
      // entity has the specified variables.
      foreach ($value as $curValue) {
        switch ($key) {
          case 'guid':
          case '!guid':
            foreach ($curValue as $curGuid) {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid"='.(int) $curGuid;
            }
            break;
          case 'tag':
          case '!tag':
            foreach ($curValue as $curTag) {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."tags" LIKE \'%,'.
                  str_replace(
                      ['%', '_', ':'],
                      [':%', ':_', '::'],
                      SQLite3::escapeString($curTag)
                  ).',%\' ESCAPE \':\'';
            }
            break;
          case 'isset':
          case '!isset':
            foreach ($curValue as $curVar) {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= 'ie."guid" '.
                  (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'IN (SELECT "guid" FROM "'.
                  $this->prefix.'data'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curVar).
                  '\' AND "value"!=\'N;\')';
            }
            break;
          case 'ref':
          case '!ref':
            $guids = [];
            if (is_array($curValue[1])) {
              if (key_exists('guid', $curValue[1])) {
                $guids[] = (int) $curValue[1]['guid'];
              } else {
                foreach ($curValue[1] as $curEntity) {
                  if (is_object($curEntity)) {
                    $guids[] = (int) $curEntity->guid;
                  } elseif (is_array($curEntity)) {
                    $guids[] = (int) $curEntity['guid'];
                  } else {
                    $guids[] = (int) $curEntity;
                  }
                }
              }
            } elseif (is_object($curValue[1])) {
              $guids[] = (int) $curValue[1]->guid;
            } else {
              $guids[] = (int) $curValue[1];
            }
            foreach ($guids as $curQguid) {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'references'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).'\' AND "reference"='.
                  SQLite3::escapeString((int) $curQguid).')';
            }
            break;
          case 'strict':
          case '!strict':
            if ($curValue[0] === 'cdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."cdate"='.((float) $curValue[1]);
              break;
            } elseif ($curValue[0] === 'mdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."mdate"='.((float) $curValue[1]);
              break;
            } else {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              if (is_callable([$curValue[1], 'toReference'])) {
                $svalue = serialize($curValue[1]->toReference());
              } else {
                $svalue = serialize($curValue[1]);
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.$this->prefix.'data'.
                  $etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).
                  '\' AND "value"=\''.
                  SQLite3::escapeString(
                      (
                        strpos($svalue, "\0") !== false
                        ? '~'.addcslashes($svalue, chr(0).'\\')
                        : $svalue
                      )
                  ).'\')';
            }
            break;
          case 'like':
          case '!like':
            if ($curValue[0] === 'cdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  '(ie."cdate" LIKE \''.
                  SQLite3::escapeString($curValue[1]).
                  '\' ESCAPE \'\\\')';
              break;
            } elseif ($curValue[0] === 'mdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  '(ie."mdate" LIKE \''.
                  SQLite3::escapeString($curValue[1]).
                  '\' ESCAPE \'\\\')';
              break;
            } else {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).
                  '\' AND "string" LIKE \''.
                  SQLite3::escapeString($curValue[1]).
                  '\' ESCAPE \'\\\')';
            }
            break;
          case 'ilike':
          case '!ilike':
            if ($curValue[0] === 'cdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  '(ie."cdate" LIKE \''.
                  SQLite3::escapeString($curValue[1]).
                  '\' ESCAPE \'\\\')';
              break;
            } elseif ($curValue[0] === 'mdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  '(ie."mdate" LIKE \''.
                  SQLite3::escapeString($curValue[1]).
                  '\' ESCAPE \'\\\')';
              break;
            } else {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).
                  '\' AND lower("string") LIKE lower(\''.
                  SQLite3::escapeString($curValue[1]).
                  '\') ESCAPE \'\\\')';
            }
            break;
          case 'pmatch':
          case '!pmatch':
            if ($curValue[0] === 'cdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  '(ie."cdate" REGEXP \''.
                  SQLite3::escapeString($curValue[1]).'\')';
              break;
            } elseif ($curValue[0] === 'mdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  '(ie."mdate" REGEXP \''.
                  SQLite3::escapeString($curValue[1]).'\')';
              break;
            } else {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).
                  '\' AND "string" REGEXP \''.
                  SQLite3::escapeString($curValue[1]).'\')';
            }
            break;
          case 'ipmatch':
          case '!ipmatch':
            if ($curValue[0] === 'cdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  '(ie."cdate" REGEXP \''.
                  SQLite3::escapeString($curValue[1]).'\')';
              break;
            } elseif ($curValue[0] === 'mdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  '(ie."mdate" REGEXP \''.
                  SQLite3::escapeString($curValue[1]).'\')';
              break;
            } else {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).
                  '\' AND lower("string") REGEXP lower(\''.
                  SQLite3::escapeString($curValue[1]).'\'))';
            }
            break;
          case 'match':
          case '!match':
            if ($curValue[0] === 'cdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .=
                  (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'preg_match(\''.SQLite3::escapeString($curValue[1]).
                  '\', ie."cdate")';
              break;
            } elseif ($curValue[0] === 'mdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .=
                  (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'preg_match(\''.SQLite3::escapeString($curValue[1]).
                  '\', ie."mdate")';
              break;
            } else {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .=
                  (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.
                  '" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).
                  '\' AND "string" IS NOT NULL AND '.
                  'preg_match(\''.SQLite3::escapeString($curValue[1]).
                  '\', "string"))';
            }
            break;
          case 'gt':
          case '!gt':
            if ($curValue[0] === 'cdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."cdate">'.((float) $curValue[1]);
              break;
            } elseif ($curValue[0] === 'mdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."mdate">'.((float) $curValue[1]);
              break;
            } else {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .=
                  (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).'\' AND '.
                  '(("is_int"=\'1\' AND "int" IS NOT NULL AND "int" > '.
                  ((int) $curValue[1]).') OR ('.
                  'NOT "is_int"=\'1\' AND "float" IS NOT NULL AND "float" > '.
                  ((float) $curValue[1]).')))';
            }
            break;
          case 'gte':
          case '!gte':
            if ($curValue[0] === 'cdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."cdate">='.((float) $curValue[1]);
              break;
            } elseif ($curValue[0] === 'mdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."mdate">='.((float) $curValue[1]);
              break;
            } else {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .=
                  (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).'\' AND '.
                  '(("is_int"=\'1\' AND "int" IS NOT NULL AND "int" >= '.
                  ((int) $curValue[1]).') OR ('.
                  'NOT "is_int"=\'1\' AND "float" IS NOT NULL AND "float" >= '.
                  ((float) $curValue[1]).')))';
            }
            break;
          case 'lt':
          case '!lt':
            if ($curValue[0] === 'cdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."cdate"<'.((float) $curValue[1]);
              break;
            } elseif ($curValue[0] === 'mdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."mdate"<'.((float) $curValue[1]);
              break;
            } else {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .=
                  (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).'\' AND '.
                  '(("is_int"=\'1\' AND "int" IS NOT NULL AND "int" < '.
                  ((int) $curValue[1]).') OR ('.
                  'NOT "is_int"=\'1\' AND "float" IS NOT NULL AND "float" < '.
                  ((float) $curValue[1]).')))';
            }
            break;
          case 'lte':
          case '!lte':
            if ($curValue[0] === 'cdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."cdate"<='.((float) $curValue[1]);
              break;
            } elseif ($curValue[0] === 'mdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."mdate"<='.((float) $curValue[1]);
              break;
            } else {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .=
                  (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).'\' AND '.
                  '(("is_int"=\'1\' AND "int" IS NOT NULL AND "int" <= '.
                  ((int) $curValue[1]).') OR ('.
                  'NOT "is_int"=\'1\' AND "float" IS NOT NULL AND "float" <= '.
                  ((float) $curValue[1]).')))';
            }
            break;
          // Cases after this point contains special values where
          // it can be solved by the query, but if those values
          // don't match, just check the variable exists.
          case 'equal':
          case '!equal':
          case 'data':
          case '!data':
            if ($curValue[0] === 'cdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."cdate"='.((float) $curValue[1]);
              break;
            } elseif ($curValue[0] === 'mdate') {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."mdate"='.((float) $curValue[1]);
              break;
            } elseif ($curValue[1] === true || $curValue[1] === false) {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).
                  '\' AND "eq_true"='.
                  ($curValue[1] ? '1' : '0').')';
              break;
            } elseif ($curValue[1] === 1) {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).
                  '\' AND "eq_one"=1)';
              break;
            } elseif ($curValue[1] === 0) {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).
                  '\' AND "eq_zero"=1)';
              break;
            } elseif ($curValue[1] === -1) {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).
                  '\' AND "eq_negone"=1)';
              break;
            } elseif ($curValue[1] === []) {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
                  'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).
                  '\' AND "eq_emptyarray"=1)';
              break;
            }
            // Fall through.
          case 'array':
          case '!array':
            if (!($typeIsNot xor $clauseNot)) {
              if ($curQuery) {
                $curQuery .= $typeIsOr ? ' OR ' : ' AND ';
              }
              $curQuery .= 'ie."guid" IN (SELECT "guid" FROM "'.
                  $this->prefix.'data'.$etype.'" WHERE "name"=\''.
                  SQLite3::escapeString($curValue[0]).'\')';
            }
            $fullQueryCoverage = false;
            break;
        }
      }
    });

    switch ($sort) {
      case 'guid':
        $sort = '"guid"';
        break;
      case 'mdate':
        $sort = '"mdate"';
        break;
      case 'cdate':
      default:
        $sort = '"cdate"';
        break;
    }
    if (isset($options['reverse']) && $options['reverse']) {
      $sort .= ' DESC';
    }

    if ($queryParts) {
      if ($subquery) {
        $query = "((".implode(') AND (', $queryParts)."))";
      } else {
        $limit = "";
        if ($fullQueryCoverage && key_exists('limit', $options)) {
          $limit = " LIMIT ".((int) $options['limit']);
        }
        $offset = "";
        if ($fullQueryCoverage && key_exists('offset', $options)) {
          $offset = " OFFSET ".((int) $options['offset']);
        }
        $query =
            "SELECT e.\"guid\", e.\"tags\", e.\"cdate\", e.\"mdate\", ".
              "d.\"name\", d.\"value\" ".
            "FROM \"{$this->prefix}entities{$etype}\" e ".
            "LEFT JOIN \"{$this->prefix}data{$etype}\" d USING (\"guid\") ".
            "INNER JOIN (".
              "SELECT \"guid\" ".
              "FROM \"{$this->prefix}entities{$etype}\" ie ".
              "WHERE (".
                implode(') AND (', $queryParts).
              ") ".
              "ORDER BY ie.{$sort}{$limit}{$offset}".
            ") f USING (\"guid\") ".
            "ORDER BY {$sort};";
      }
    } else {
      if ($subquery) {
        $query = '';
      } else {
        $limit = "";
        if (key_exists('limit', $options)) {
          $limit = " LIMIT ".((int) $options['limit']);
        }
        $offset = "";
        if (key_exists('offset', $options)) {
          $offset = " OFFSET ".((int) $options['offset']);
        }
        if ($limit || $offset) {
          $query =
              "SELECT e.\"guid\", e.\"tags\", e.\"cdate\", e.\"mdate\", ".
                "d.\"name\", d.\"value\" ".
              "FROM \"{$this->prefix}entities{$etype}\" e ".
              "LEFT JOIN \"{$this->prefix}data{$etype}\" d USING (\"guid\") ".
              "INNER JOIN (".
                "SELECT \"guid\" ".
                "FROM \"{$this->prefix}entities{$etype}\" ie ".
                "ORDER BY ie.{$sort}{$limit}{$offset}".
              ") f USING (\"guid\") ".
              "ORDER BY {$sort};";
        } else {
          $query =
              "SELECT e.\"guid\", e.\"tags\", e.\"cdate\", e.\"mdate\", ".
                "d.\"name\", d.\"value\" ".
              "FROM \"{$this->prefix}entities{$etype}\" e ".
              "LEFT JOIN \"{$this->prefix}data{$etype}\" d USING (\"guid\") ".
              "ORDER BY {$sort};";
        }
      }
    }

    return [
      'fullCoverage' => $fullQueryCoverage,
      'limitOffsetCoverage' => $fullQueryCoverage,
      'query' => $query
    ];
  }
932863
protected function compileOrWheres(array $orWheres = [], $query = '')
    {
        $or = '';

        foreach ($orWheres as $where) {
            $or .= $this->compileWhere($where);
        }

        // Make sure we wrap the query in an 'or' if using multiple
        // orWheres. For example (|(QUERY)(ORWHEREQUERY)).
        if (($query && count($orWheres) > 0) || count($orWheres) > 1) {
            $query .= $this->compileOr($or);
        } else {
            $query .= $or;
        }

        return $query;
    }
89149
protected function applyWhere(Builder $query, array $where)
    {
        foreach ($where as $key => $value) {
            if (is_null($value)) {
                $query = $query->whereNull($key);
            } else {
                if (is_array($value)) {
                    $query = $query->where($key, $value[0], $value[1]);
                } else {
                    $query = $query->where($key, '=', $value);
                }
            }
        }

        return $query;
    }
87981
public function addPageQuery($url, $page, $full = false)
    {
        // If the first page's URL is requested and $full is set to false, there's nothing to be added.
        if ($page === 1 && ! $full) {
            return $url;
        }

        return trim($url, '/')."/{$this->pageKeyword}/{$page}";
    }
736718
public function writeEntityRepositoryClass($fullClassName, $outputDirectory)
    {
        $code = $this->generateEntityRepositoryClass($fullClassName);

        $path = $outputDirectory . DIRECTORY_SEPARATOR
              . str_replace('\\', \DIRECTORY_SEPARATOR, $fullClassName) . '.php';
        $dir = dirname($path);

        if ( ! is_dir($dir)) {
            mkdir($dir, 0775, true);
        }

        if ( ! file_exists($path)) {
            file_put_contents($path, $code);
            chmod($path, 0664);
        }
    }
1153057
public function search($query, bool $full = false): stdClass
	{
		$res = $this->request('search/tweets', 'GET', is_array($query) ? $query : ['q' => $query]);
		return $full ? $res : $res->statuses;
	}