Returns array with sql code and parameters returning all ids
of users who meet this particular criterion.

@return array list($join, $where, $params)
515439
public function get_completed_criteria_sql() {
        $join = '';
        $where = '';
        $params = array();

        if ($this->method == BADGE_CRITERIA_AGGREGATION_ANY) {
            foreach ($this->params as $param) {
                $roledata[] = " bma.issuerrole = :issuerrole{$param['role']} ";
                $params["issuerrole{$param['role']}"] = $param['role'];
            }
            if (!empty($roledata)) {
                $extraon = implode(' OR ', $roledata);
                $join = " JOIN {badge_manual_award} bma ON bma.recipientid = u.id
                          AND bma.badgeid = :badgeid{$this->badgeid} AND ({$extraon})";
                $params["badgeid{$this->badgeid}"] = $this->badgeid;
            }
            return array($join, $where, $params);
        } else {
            foreach ($this->params as $param) {
                $roledata[] = " bma.issuerrole = :issuerrole{$param['role']} ";
                $params["issuerrole{$param['role']}"] = $param['role'];
            }
            if (!empty($roledata)) {
                $extraon = implode(' AND ', $roledata);
                $join = " JOIN {badge_manual_award} bma ON bma.recipientid = u.id
                          AND bma.badgeid = :badgeid{$this->badgeid} AND ({$extraon})";
                $params["badgeid{$this->badgeid}"] = $this->badgeid;
            }
            return array($join, $where, $params);
        }
    }
763155
public function fetchAll(): array
    {
        $sql = $this->builder->buildSql();
        $this->builder = new QueryBuilder($this->pdo);
        return $this->fetchAllBySql($sql);
    }
324306
private function _buildQueryParams() {
		$query = [];

		$this->_where = is_array($this->_where) ? $this->_where : [];
		foreach ($this->_where as $key => $val) {
			$query[$key] = is_numeric($val) ? (int) $val : $val;
		}

		if(count($this->_select)) {
			$query[$this->selectFieldsKey] = implode(',', $this->_select);
		}
		if($this->_limit !== null) {
			$query[$this->limitKey] = $this->_limit;
		}
		if($this->_offset !== null) {
			$query[$this->offsetKey] = $this->_offset;
		}

		return $query;
	}
1324037
private function getSearchQueryIdentities()
    {
        $identities = [];
        $queryIds   = [];
        $origData   = $this->optimizer->getOrigData();
        $data       = $this->optimizer->getData();

        // If optimizer was previously assigned to all queries, or is now set to all queries.
        $isAppliedToAllQueries = empty($data['quick_search_container'])
            || (bool) $data['quick_search_container']['apply_to'] === false;
        $wasAppliedToAllQueries = empty($origData['quick_search_container']['query_ids']);

        if (!empty($origData['quick_search_container']['query_ids'])) {
            $queryIds = array_merge($queryIds, $origData['quick_search_container']['query_ids']);
        }

        if (!empty($data['quick_search_container']['query_ids'])) {
            foreach ($data['quick_search_container']['query_ids'] as $query) {
                $queryIds[] = $query['id'];
            }
        }

        $queryIds = array_unique(array_filter($queryIds));

        if ($wasAppliedToAllQueries || $isAppliedToAllQueries) {
            $identities[] = \Smile\ElasticsuiteCatalog\Block\CatalogSearch\Result\Cache::POPULAR_SEARCH_CACHE_TAG;
        } elseif (!empty($queryIds)) {
            $popularQueryIds = $this->queryCollection
                ->setPopularQueryFilter($this->optimizer->getStoreId())
                ->setPageSize($this->getMaxCountCacheableSearchTerms($this->optimizer->getStoreId()))
                ->load()
                ->getColumnValues('query_id');

            if (!empty(array_intersect($queryIds, $popularQueryIds))) {
                $identities[] = \Smile\ElasticsuiteCatalog\Block\CatalogSearch\Result\Cache::POPULAR_SEARCH_CACHE_TAG;
            }
        }

        return $identities;
    }
1368086
protected function getIDListFromDB() : array
    {
        $arElementIDList = (array) Product::getByCategory($this->sValue)->lists('id');

        //Get product ID list for additional category relation
        $arAdditionalElementIDList = (array) DB::table('lovata_shopaholic_additional_categories')->where('category_id', $this->sValue)->lists('product_id');
        $arElementIDList = array_merge($arElementIDList, $arAdditionalElementIDList);
        $arElementIDList = array_unique($arElementIDList);

        return $arElementIDList;
    }
479186
public function getJoins()
    {
        $template = "%s JOIN %s ON %s";
        $joinsStr = null;

        $joins = $this->_sql->getJoins();
        $tmpJoin = array();
        if (count($joins) > 0) {
            foreach ($joins as $join) {
                $tmpJoin[] = sprintf(
                    $template,
                    $join['type'],
                    $join['table'],
                    $join['onClause']
                );
            }
            $joinsStr = implode(PHP_EOL, $tmpJoin);
        }

        return $joinsStr;
    }
1330664
public function getAllUsers() : array {
		$result = $this->db->query("SELECT id FROM accounts;");
		$users = [];
		foreach ($result->fetch_all(MYSQLI_ASSOC) as $user) {
			$users[(int)$user["id"]] = $this->getUserFromId((int)$user["id"]);
		}
		return $users;
	}
100857
public function delete(): array
	{
		$sql  = $this->query->getPrefix();
		$sql .= 'DELETE FROM ';
		$sql .= $this->escapeTable($this->query->getTable());
		$sql .= $this->wheres($this->query->getWheres());

		return ['sql' => $sql, 'params' => $this->params];
	}
597141
public function users()
    {
        $list  = [];
        $users = User::all();

        foreach ($users as $key => $user) {
            $list[$user->id] = $user->name;
        }

        return $list;
    }
1246973
protected function getSelectedIds()
    {
        $ids = array();
        foreach ($_REQUEST as $parameter => $value) {
            $matches = array();
            preg_match('/select_(.*)/', $parameter, $matches);
            if ($matches) {
                $ids[] = $matches[1];
            }
        }

        return $ids;
    }
343178
public function findAllIdentifiers(): array
    {
        $queryBuilder = $this->createQuery();
        $rows = $queryBuilder->select('identifier')
            ->from($this->getTableName())
            ->groupBy('identifier')
            ->execute()
            ->fetchAll();

        $cacheIdentifiers = [];
        foreach ($rows as $row) {
            $cacheIdentifiers[] = $row['identifier'];
        }

        return $cacheIdentifiers;
    }
1263100
public function _getSql()
    {
        $sql = '';
        $params = [];
        try {
            list($sql, $params) = $this->getSqlCompiler(BaseOrm::getDbConnection())->asSql();
        } catch (OrmException $e) {
        }

        $sql = str_replace('?', '%s', $sql);

        return vsprintf($sql, $params);
    }
1370198
protected function _getQuery()
    {
        $sSLViewName = $this->_getViewName('oxselectlist');
        $sArtViewName = $this->_getViewName('oxarticles');
        $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();

        $sArtId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('oxid');
        $sSynchArtId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('synchoxid');

        $sOxid = ($sArtId) ? $sArtId : $sSynchArtId;
        $sQ = "select oxparentid from {$sArtViewName} where oxid = " . $oDb->quote($sOxid) . " and oxparentid != '' ";
        $sQ .= "and (select count(oxobjectid) from oxobject2selectlist " .
               "where oxobjectid = " . $oDb->quote($sOxid) . ") = 0";
        // We force reading from master to prevent issues with slow replications or open transactions (see ESDEV-3804 and ESDEV-3822).
        $sParentId = \OxidEsales\Eshop\Core\DatabaseProvider::getMaster()->getOne($sQ);

        // all selectlists article is in
        $sQAdd = " from oxobject2selectlist left join {$sSLViewName} " .
                 "on {$sSLViewName}.oxid=oxobject2selectlist.oxselnid  " .
                 "where oxobject2selectlist.oxobjectid = " . $oDb->quote($sOxid) . " ";
        if ($sParentId) {
            $sQAdd .= "or oxobject2selectlist.oxobjectid = " . $oDb->quote($sParentId) . " ";
        }
        // all not assigned selectlists
        if ($sSynchArtId) {
            $sQAdd = " from {$sSLViewName}  " .
                     "where {$sSLViewName}.oxid not in ( select oxobject2selectlist.oxselnid {$sQAdd} ) ";
        }

        return $sQAdd;
    }
385474
public function getQueryParams() : array
    {
        $this->queryStrings->usePercentEncode(false);
        $r = $this->queryStrings->toArray(true);
        $this->queryStrings->usePercentEncode(true);

        return $r;
    }
505651
protected function whereSql() {
        $this->params = [];
        $sql = $this->parseWhere($this->wheres, $this->params);
        if ($sql) {
            $sql = " WHERE " . $sql;
        }
        return $sql;
    }
520512
public function findAllBySql($sql,$params=array())
	{
		Yii::trace(get_class($this).'.findAllBySql()','system.db.ar.CActiveRecord');
		$this->beforeFind();
		if(($criteria=$this->getDbCriteria(false))!==null && !empty($criteria->with))
		{
			$this->resetScope(false);
			$finder=$this->getActiveFinder($criteria->with);
			return $finder->findAllBySql($sql,$params);
		}
		else
		{
			$command=$this->getCommandBuilder()->createSqlCommand($sql,$params);
			return $this->populateRecords($command->queryAll());
		}
	}
961757
public function get_completed_criteria_sql() {
        $join = '';
        $where = '';
        $params = array();

        if ($this->method == BADGE_CRITERIA_AGGREGATION_ANY) {
            // User has received ANY of the required badges.
            $join = " LEFT JOIN {badge_issued} bi2 ON bi2.userid = u.id";
            $where = "AND (";
            $i = 0;
            foreach ($this->params as $param) {
                if ($i == 0) {
                    $where .= ' bi2.badgeid = :badgeid'.$i;
                } else {
                    $where .= ' OR bi2.badgeid = :badgeid'.$i;
                }
                $params['badgeid'.$i] = $param['badge'];
                $i++;
            }
            $where .= ") ";
            return array($join, $where, $params);
        } else {
            // User has received ALL of the required badges.
            $join = " LEFT JOIN {badge_issued} bi2 ON bi2.userid = u.id";
            $i = 0;
            foreach ($this->params as $param) {
                $i++;
                $where = ' AND bi2.badgeid = :badgeid'.$i;
                $params['badgeid'.$i] = $param['badge'];
            }
            return array($join, $where, $params);
        }
    }