Returns product selections lists array (used in azure theme)

@param int   $iLimit  if given - will load limited count of selections [optional]
@param array $aFilter selection filter [optional]

@return array
338076
public function getSelections($iLimit = null, $aFilter = null)
    {
        $sId = $this->getId() . ((int) $iLimit);
        if (!array_key_exists($sId, self::$_aSelections)) {
            $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
            $sSLViewName = getViewName('oxselectlist');

            $sQ = "select {$sSLViewName}.* from oxobject2selectlist join {$sSLViewName} on $sSLViewName.oxid=oxobject2selectlist.oxselnid
                   where oxobject2selectlist.oxobjectid=%s order by oxobject2selectlist.oxsort";

            if (($iLimit = (int) $iLimit)) {
                $sQ .= " limit $iLimit ";
            }

            // vat value for price
            $dVat = 0;
            if (($oPrice = $this->getPrice()) != null) {
                $dVat = $oPrice->getVat();
            }

            // all selectlists this article has
            $oList = oxNew(\OxidEsales\Eshop\Core\Model\ListModel::class);
            $oList->init('oxselectlist');
            $oList->getBaseObject()->setVat($dVat);
            $oList->selectString(sprintf($sQ, $oDb->quote($this->getId())));

            //#1104S if this is variant and it has no selectlists, trying with parent
            if ($oList->count() == 0 && $this->oxarticles__oxparentid->value) {
                $oList->selectString(sprintf($sQ, $oDb->quote($this->oxarticles__oxparentid->value)));
            }

            self::$_aSelections[$sId] = $oList->count() ? $oList : false;
        }

        if (self::$_aSelections[$sId]) {
            // marking active from filter
            $aFilter = ($aFilter === null) ? \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("sel") : $aFilter;
            if ($aFilter) {
                $iSelIdx = 0;
                foreach (self::$_aSelections[$sId] as $oSelection) {
                    if (isset($aFilter[$iSelIdx])) {
                        $oSelection->setActiveSelectionByIndex($aFilter[$iSelIdx]);
                    }
                    $iSelIdx++;
                }
            }
        }

        return self::$_aSelections[$sId];
    }
493803
public function listFilesWithType(string $type, array $filter = null, array $sortOrder = null, array $limit = null) {
		$timeStamp = microtime(true);
	    $typeOpts = array('a', 'i', 'v', 'f', 'd', 'p', 's', 'c');
        if(!in_array($type, $typeOpts)){
	        throw new InvalidFileTypeException($type);
		}
        $filter[] = array(
            'glue' => ' and',
            'condition' => array(
                'column' => $this->entity['f']['alias'] . '.type',
                'comparison' => '=',
                'value' => $type)
        );
        $response = $this->listFiles($filter, $sortOrder, $limit);

		$response->stats->execution->start = $timeStamp;
		$response->stats->execution->end = microtime(true);

		return $response;
    }
815266
public function getFilters()
    {
        return [
            new Twig_SimpleFilter('add_filter_value', [$this->urlBuilder, 'addFilterValue']),
            new Twig_SimpleFilter('remove_filter_value', [$this->urlBuilder, 'removeFilterValue']),
            new Twig_SimpleFilter('remove_price_range_filter', [$this->urlBuilder, 'removePriceRangeFilter']),
            new Twig_SimpleFilter('add_prev_page', [$this->urlBuilder, 'addPrevPage']),
            new Twig_SimpleFilter('add_page', [$this->urlBuilder, 'addPage']),
            new Twig_SimpleFilter('add_next_page', [$this->urlBuilder, 'addNextPage']),
            new Twig_SimpleFilter('add_sort_by', [$this->urlBuilder, 'addSortBy']),
        ];
    }
829253
private function _findInIndex($keywords, $filter=null, $sortBy=null, $limit=10)
    {
        $ret = array();
        $query = $this->client->createSelect();
        // create a filterquery
        if (!empty($keywords))
        {
            // if isbn
            if (preg_match('/^\d{10,13}$/', $keywords)) {
                $query->addFilterQuery(array(
                    'key' => 'fq1',
                    // 'tag' => array('populationLimit'),
                    'query' => 'ISBN:'.$keywords,
                ));
            } else {
                $query->addFilterQuery(array(
                    'key' => 'fq1',
                    // 'tag' => array('populationLimit'),
                    'query' => '"'.$keywords.'"'.'~0.5',
                ));
            }
        }
        if (!empty($filter))
        {
            if (!empty($filter['categoryNames']))
            {
                $query->addFilterQuery(array(
                    'key' => 'fq4',
                    // 'tag' => array('populationLimit'),
                    'query' => 'categories:'.implode(' ',$filter['categoryNames']),
                    ));
            }
            
            if(!empty($filter['min']) && !empty($filter['max'])) {
                $query->addFilterQuery(array(
                    'key'=> 'fq2',
                    'query' => 'min_investment: ['.($filter['min']*10000).' TO *]'
                ));
                $query->addFilterQuery(array(
                    'key'=> 'fq3',
                    'query' => 'max_investment: [* TO '.($filter['max']*10000).']'
                ));
            } elseif(!empty($filter['min']) && empty($filter['max'])) {
                $query->addFilterQuery(array(
                    'key'=> 'fq2',
                    'query' => 'min_investment: ['.($filter['min']*10000).' TO *]'
                ));
            } elseif(empty($filter['min']) && !empty($filter['max'])) {
                $query->addFilterQuery(array(
                    'key'=> 'fq3',
                    'query' => 'max_investment: [* TO '.($filter['max']*10000).']'
                ));
            }
        }
        $query->setRows($limit);
        //:['' TO *]
        //
        // *:* is equivalent to telling solr to return all docs
        $resultSet = $this->client->select($query);
        $index = 0;
        foreach ($resultSet as $result) {
            $klass = new \StdClass;
            $klass->id = $result->id;
            $klass->name = $result->name;
            $klass->description = $result->description;
            $klass->min_investment = $result->min_investment;
            $klass->max_investment = $result->max_investment;
            $klass->address = $result->address;
            $klass->tags = $this->_getTagsOrCategories($result->tags);
            $klass->categories = $this->_getTagsOrCategories($result->categories);
            $klass->url = $result->url;
            $klass->contact_name = $result->contact_name;
            $klass->contact_email = $result->contact_email;
            $klass->contact_phone = $result->contact_phone;
            if (isset($result->big_image_url)) {
                $klass->big_image_url = $this->base_url.\Config::get('core::core.defaults.image_base_url.item').$result->big_image_url;
            } else {
                $klass->big_image_url = $this->base_url.\Config::get('core::core.defaults.image_base_url.item').\Config::get('core::core.defaults.image.item');
            }
            if (isset($result->medium_image_url)) {
                $klass->medium_image_url = $this->base_url.\Config::get('core::core.defaults.image_base_url.item').$result->medium_image_url;
            } else {
                $klass->medium_image_url = $this->base_url.\Config::get('core::core.defaults.image_base_url.item').\Config::get('core::core.defaults.image.item');
            }
            if (isset($result->small_image_url)) {
                $klass->small_image_url = $this->base_url.\Config::get('core::core.defaults.image_base_url.item').$result->small_image_url;
            } else {
                $klass->small_image_url = $this->base_url.\Config::get('core::core.defaults.image_base_url.item').\Config::get('core::core.defaults.image.item');
            }
            $klass->company = $this->_getCompany($result->companyId, $result->companyName, $result->companyBigImageUrl, $result->companyMediumImageUrl, $result->companySmallImageUrl);
            $klass->territory = $this->_getTerritory($result->territoryId, $result->territoryName, $result->countryId, $result->countryName);
            $ret[$index++] = $klass;
        }

        return $this->_mapSearchResult($ret, $filter);
    }
33753
protected function _getFilterSql($sCatId, $aFilter)
    {
        $sArticleTable = getViewName('oxarticles');
        $aIds = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC)->getAll($this->_getFilterIdsSql($sCatId, $aFilter));
        $sIds = '';

        if ($aIds) {
            foreach ($aIds as $aArt) {
                if ($sIds) {
                    $sIds .= ', ';
                }
                $sIds .= \OxidEsales\Eshop\Core\DatabaseProvider::getDb()->quote(current($aArt));
            }

            if ($sIds) {
                $sFilterSql = " and $sArticleTable.oxid in ( $sIds ) ";
            }
            // bug fix #0001695: if no articles found return false
        } elseif (!(current($aFilter) == '' && count(array_unique($aFilter)) == 1)) {
            $sFilterSql = " and false ";
        }

        return $sFilterSql;
    }
1193360
public function discardUnusedReservations($iLimit)
    {
        // We force reading from master to prevent issues with slow replications or open transactions (see ESDEV-3804 and ESDEV-3822).
        $database = \OxidEsales\Eshop\Core\DatabaseProvider::getMaster(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);

        $iStartTime = \OxidEsales\Eshop\Core\Registry::getUtilsDate()->getTime() - (int) \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('iPsBasketReservationTimeout');

        $oRs = $database->select("select oxid from oxuserbaskets where oxtitle = 'reservations' and oxupdate <= $iStartTime limit $iLimit", false);
        if ($oRs->EOF) {
            return;
        }
        $aFinished = [];
        while (!$oRs->EOF) {
            $aFinished[] = $database->quote($oRs->fields['oxid']);
            $oRs->fetchRow();
        }

        $database->startTransaction();
        try {
            $oRs = $database->select("select oxartid, oxamount from oxuserbasketitems where oxbasketid in (" . implode(",", $aFinished) . ")", false);
            while (!$oRs->EOF) {
                $oArticle = oxNew(\OxidEsales\Eshop\Application\Model\Article::class);
                if ($oArticle->load($oRs->fields['oxartid'])) {
                    $oArticle->reduceStock(-$oRs->fields['oxamount'], true);
                }
                $oRs->fetchRow();
            }
            $database->execute("delete from oxuserbasketitems where oxbasketid in (" . implode(",", $aFinished) . ")");
            $database->execute("delete from oxuserbaskets where oxid in (" . implode(",", $aFinished) . ")");

            // cleanup basket history also..
            $database->execute("delete from oxuserbaskets where oxtitle = 'savedbasket' and oxupdate <= $iStartTime");

            $database->commitTransaction();
        } catch (Exception $exception) {
            $database->rollbackTransaction();

            throw $exception;
        }


        $this->_aCurrentlyReserved = null;
    }
396799
protected function &GetOrderByFilterList()
    {
        $aFilterIds = $this->oModuleConf->GetMLTIdList('shop_module_articlelist_orderby');
        $oList = TdbShopModuleArticlelistOrderbyList::GetListForIds($aFilterIds);
        $oList->bAllowItemCache = true;
        // fill item cache
        $i = 0;
        while ($oItem = $oList->Next()) {
            ++$i;
        }
        $oList->GoToStart();

        return $oList;
    }
930831
public function toArray(iFilter $filter)
	{
		$result = array();
		if($this->uuid != null)
			$result[Database::XML_UUID] = $this->uuid;
		if($this->name != null)
			$result[Database::XML_NAME] = $this->name;
		if($this->icon != null && $filter->acceptIcons())
			$result[Database::XML_ICONID] = $this->icon;
		if($this->customIcon != null && $filter->acceptIcons())
			$result[Database::XML_CUSTOMICONUUID] = $this->customIcon;
		if($this->groups != null)
		{
			$groups = array();
			foreach($this->groups as &$group)
			{
				if($filter->acceptGroup($group))
					$groups[] = $group->toArray($filter);
			}
			if(!empty($groups))
				$result[Database::GROUPS] = $groups;
		}
		if($this->entries != null)
		{
			$entries = array();
			foreach($this->entries as &$entry)
			{
				if($filter->acceptEntry($entry))
					$entries[] = $entry->toArray($filter);
			}
			if(!empty($entries))
				$result[Database::ENTRIES] = $entries;
		}
		return $result;
	}
353923
protected function getResourceRepresentation(ResourceInterface $resource, FieldSetFilterInterface $filter): array
    {
        $representation = [
            DocumentInterface::KEYWORD_TYPE => $resource->getType(),
        ];

        if (($index = $resource->getId()) !== null) {
            $representation[DocumentInterface::KEYWORD_ID] = $index;
        }

        $attributes = $this->getAttributesRepresentation($filter->getAttributes($resource));
        if (empty($attributes) === false) {
            \assert(
                \json_encode($attributes) !== false,
                'Attributes for resource type `' . $resource->getType() .
                '` cannot be converted into JSON. Please check its Schema returns valid data.'
            );
            $representation[DocumentInterface::KEYWORD_ATTRIBUTES] = $attributes;
        }

        $relationships = $this->getRelationshipsRepresentation($filter->getRelationships($resource));
        if (empty($relationships) === false) {
            \assert(
                \json_encode($relationships) !== false,
                'Relationships for resource type `' . $resource->getType() .
                '` cannot be converted into JSON. Please check its Schema returns valid data.'
            );
            $representation[DocumentInterface::KEYWORD_RELATIONSHIPS] = $relationships;
        }

        if ($resource->hasLinks() === true) {
            $links = $this->getLinksRepresentation($this->getUrlPrefix(), $resource->getLinks());
            \assert(
                \json_encode($links) !== false,
                'Links for resource type `' . $resource->getType() .
                '` cannot be converted into JSON. Please check its Schema returns valid data.'
            );
            $representation[DocumentInterface::KEYWORD_LINKS] = $links;
        }

        if ($resource->hasResourceMeta() === true) {
            $meta = $resource->getResourceMeta();
            \assert(
                \json_encode($meta) !== false,
                'Meta for resource type `' . $resource->getType() .
                '` cannot be converted into JSON. Please check its Schema returns valid data.'
            );
            $representation[DocumentInterface::KEYWORD_META] = $meta;
        }

        return $representation;
    }
647953
protected function _cleanFilter($aFilter)
    {
        $aCleanFilter = false;
        if (is_array($aFilter) && count($aFilter)) {
            foreach ($aFilter as $iKey => $sFilter) {
                if ($sFilter) {
                    $aCleanFilter[$iKey] = $sFilter;
                }
            }
        }

        return $aCleanFilter;
    }
1021579
public function GetFilterValuesForFilterType($sFilterSystemName)
    {
        $aActiveFilter = $this->GetFromInternalCache('aFilterDataAsArrayFor'.$sFilterSystemName);
        if (is_null($aActiveFilter)) {
            $aActiveFilter = false;

            $aFilterData = $this->GetCurrentFilterAsArray();
            if (is_array($aFilterData) && array_key_exists(TdbPkgShopListfilterItem::URL_PARAMETER_FILTER_DATA, $aFilterData) && is_array($aFilterData[TdbPkgShopListfilterItem::URL_PARAMETER_FILTER_DATA]) && count($aFilterData[TdbPkgShopListfilterItem::URL_PARAMETER_FILTER_DATA]) > 0) {
                $aFilterData = $aFilterData[TdbPkgShopListfilterItem::URL_PARAMETER_FILTER_DATA];
                $oFilterId = TdbPkgShopListfilterItem::GetNewInstance();
                if ($oFilterId->LoadFromFields(array('pkg_shop_listfilter_id' => $this->id, 'systemname' => $sFilterSystemName))) {
                    if (is_array($aFilterData) && array_key_exists($oFilterId->id, $aFilterData)) {
                        if (is_array($aFilterData[$oFilterId->id]) && count($aFilterData[$oFilterId->id]) > 0) {
                            $aActiveFilter = $aFilterData[$oFilterId->id];
                        }
                    }
                }
            }
            $this->SetInternalCache('aFilterDataAsArrayFor'.$sFilterSystemName, $aActiveFilter);
        }

        return $aActiveFilter;
    }
846418
public function getFilters()
    {
        return [
            new \Twig_SimpleFilter('*ize', [$this, 'inflectorFilter']),
            new \Twig_SimpleFilter('absolute_url', [$this, 'absoluteUrlFilter']),
            new \Twig_SimpleFilter('contains', [$this, 'containsFilter']),
            new \Twig_SimpleFilter('chunk_split', [$this, 'chunkSplitFilter']),
            new \Twig_SimpleFilter('nicenumber', [$this, 'niceNumberFunc']),
            new \Twig_SimpleFilter('nicefilesize', [$this, 'niceFilesizeFunc']),
            new \Twig_SimpleFilter('nicetime', [$this, 'nicetimeFunc']),
            new \Twig_SimpleFilter('defined', [$this, 'definedDefaultFilter']),
            new \Twig_SimpleFilter('ends_with', [$this, 'endsWithFilter']),
            new \Twig_SimpleFilter('fieldName', [$this, 'fieldNameFilter']),
            new \Twig_SimpleFilter('ksort', [$this, 'ksortFilter']),
            new \Twig_SimpleFilter('ltrim', [$this, 'ltrimFilter']),
            new \Twig_SimpleFilter('markdown', [$this, 'markdownFunction'], ['is_safe' => ['html']]),
            new \Twig_SimpleFilter('md5', [$this, 'md5Filter']),
            new \Twig_SimpleFilter('base32_encode', [$this, 'base32EncodeFilter']),
            new \Twig_SimpleFilter('base32_decode', [$this, 'base32DecodeFilter']),
            new \Twig_SimpleFilter('base64_encode', [$this, 'base64EncodeFilter']),
            new \Twig_SimpleFilter('base64_decode', [$this, 'base64DecodeFilter']),
            new \Twig_SimpleFilter('randomize', [$this, 'randomizeFilter']),
            new \Twig_SimpleFilter('modulus', [$this, 'modulusFilter']),
            new \Twig_SimpleFilter('rtrim', [$this, 'rtrimFilter']),
            new \Twig_SimpleFilter('pad', [$this, 'padFilter']),
            new \Twig_SimpleFilter('regex_replace', [$this, 'regexReplace']),
            new \Twig_SimpleFilter('safe_email', [$this, 'safeEmailFilter']),
            new \Twig_SimpleFilter('safe_truncate', ['\Grav\Common\Utils', 'safeTruncate']),
            new \Twig_SimpleFilter('safe_truncate_html', ['\Grav\Common\Utils', 'safeTruncateHTML']),
            new \Twig_SimpleFilter('sort_by_key', [$this, 'sortByKeyFilter']),
            new \Twig_SimpleFilter('starts_with', [$this, 'startsWithFilter']),
            new \Twig_SimpleFilter('truncate', ['\Grav\Common\Utils', 'truncate']),
            new \Twig_SimpleFilter('truncate_html', ['\Grav\Common\Utils', 'truncateHTML']),
            new \Twig_SimpleFilter('json_decode', [$this, 'jsonDecodeFilter']),
            new \Twig_SimpleFilter('array_unique', 'array_unique'),
            new \Twig_SimpleFilter('basename', 'basename'),
            new \Twig_SimpleFilter('dirname', 'dirname'),
            new \Twig_SimpleFilter('print_r', 'print_r'),
            new \Twig_SimpleFilter('yaml_encode', [$this, 'yamlEncodeFilter']),
            new \Twig_SimpleFilter('yaml_decode', [$this, 'yamlDecodeFilter']),
            new \Twig_SimpleFilter('nicecron', [$this, 'niceCronFilter']),

            // Translations
            new \Twig_SimpleFilter('t', [$this, 'translate'], ['needs_environment' => true]),
            new \Twig_SimpleFilter('tl', [$this, 'translateLanguage']),
            new \Twig_SimpleFilter('ta', [$this, 'translateArray']),

            // Casting values
            new \Twig_SimpleFilter('string', [$this, 'stringFilter']),
            new \Twig_SimpleFilter('int', [$this, 'intFilter'], ['is_safe' => ['all']]),
            new \Twig_SimpleFilter('bool', [$this, 'boolFilter']),
            new \Twig_SimpleFilter('float', [$this, 'floatFilter'], ['is_safe' => ['all']]),
            new \Twig_SimpleFilter('array', [$this, 'arrayFilter']),

            // Object Types
            new \Twig_SimpleFilter('get_type', [$this, 'getTypeFunc']),
            new \Twig_SimpleFilter('of_type', [$this, 'ofTypeFunc'])
        ];
    }
1152840
public function getRelatedCustomerIdsByIdProductList(int $idProductList): array
    {
        /** @var \Orm\Zed\ProductList\Persistence\SpyProductListCustomerQuery $productListCustomerQuery */
        $productListCustomerQuery = $this->getFactory()
            ->createProductListCustomerQuery()
            ->select(SpyProductListCustomerTableMap::COL_FK_CUSTOMER);

        return $productListCustomerQuery
            ->findByFkProductList($idProductList)
            ->toArray();
    }
39380
private function extractFilterVars(array $filter)
    {
        $collection = array_key_exists('collection', $filter) ? $filter['collection'] : null;
        $systemCollections = array_key_exists('systemCollections', $filter) ? $filter['systemCollections'] : true;
        $types = array_key_exists('types', $filter) ? $filter['types'] : null;
        $search = array_key_exists('search', $filter) ? $filter['search'] : null;
        $orderBy = array_key_exists('orderBy', $filter) ? $filter['orderBy'] : null;
        $orderSort = array_key_exists('orderSort', $filter) ? $filter['orderSort'] : null;
        $ids = array_key_exists('ids', $filter) ? $filter['ids'] : null;

        return [$collection, $systemCollections, $types, $search, $orderBy, $orderSort, $ids];
    }
1052206
public function loadTop5Articles($iLimit = null)
    {
        //has module?
        $myConfig = \OxidEsales\Eshop\Core\Registry::getConfig();

        if (!$myConfig->getConfigParam('bl_perfLoadPriceForAddList')) {
            $this->getBaseObject()->disablePriceLoad();
        }

        switch ($myConfig->getConfigParam('iTop5Mode')) {
            case 0:
                // switched off, do nothing
                break;
            case 1:
                // manually entered
                $this->loadActionArticles('oxtop5', $iLimit);
                break;
            case 2:
                $sArticleTable = getViewName('oxarticles');

                //by default limit 5
                $sLimit = ($iLimit > 0) ? "limit " . $iLimit : 'limit 5';

                $sSelect = "select * from $sArticleTable ";
                $sSelect .= "where " . $this->getBaseObject()->getSqlActiveSnippet() . " and $sArticleTable.oxissearch = 1 ";
                $sSelect .= "and $sArticleTable.oxparentid = '' and $sArticleTable.oxsoldamount>0 ";
                $sSelect .= "order by $sArticleTable.oxsoldamount desc $sLimit";

                $this->selectString($sSelect);
                break;
        }
    }
575890
public function PaginatedAllProducts($limit = 10)
    {
        $products = $this->AllProducts();
        $filter = $this->getFilter();

        if (count($filter)) {
            $products = $products->filter($filter);
        }

        return PaginatedList::create(
            $products,
            $this->getRequest()
        )->setPageLength($limit);
    }
668021
public function getDisplayedFilters()
    {
        $displayedFilters = array_filter(
            $this->getFilters(),
            function ($filter) {
                return $filter->getItemsCount() > 0;
            }
        );

        return array_values($displayedFilters);
    }