Loads similar articles with given parameters.

@param int $limit
@param array|null $types
@param null $locale
@param bool $ignoreWebspaces

@throws ArticleInRequestNotFoundException

@return ArticleResourceItem[]
519868
public function loadSimilar(
        $limit = ArticleViewDocumentRepository::DEFAULT_LIMIT,
        array $types = null,
        $locale = null,
        $ignoreWebspaces = false
    ) {
        $uuid = null;

        $request = $this->requestStack->getCurrentRequest();

        $articleDocument = $request->get('object');
        if ($articleDocument instanceof ArticleDocument) {
            $uuid = $articleDocument->getUuid();

            if (!$types) {
                $types = [$this->getArticleType($articleDocument)];
            }
        }

        if (!$uuid) {
            throw new ArticleInRequestNotFoundException();
        }

        if (!$locale) {
            $locale = $request->getLocale();
        }

        $webspaceKey = $this->getWebspaceKey($request, $ignoreWebspaces);

        $articleViewDocuments = $this->articleViewDocumentRepository->findSimilar(
            $uuid,
            $limit,
            $types,
            $locale,
            $webspaceKey
        );

        return $this->getResourceItems($articleViewDocuments);
    }
128252
public function getCatalogs($locale = null, $domain = null) {
		$cache = $this->getCacheFrontend();
		
		if (is_array($locale)) {
			$catalogs = $cache->getMany($locale);
			
			return empty($catalogs) ? null : $catalogs;
		}
		
		$catalogs = $cache->get($locale);
		
		if ($catalogs === null) {
			return;
		}
		
		return [$locale => $catalogs];
	}
939095
public function getResults($searchParams, $sort = false, $limit = false)
    {
        $searchParams = array_filter((array)$searchParams, array($this, 'clearEmptySearchFields'));

        // getQuery actually returns a DataList
        return $this->getQuery($searchParams, $sort, $limit);
    }
375322
public function load($filenames='common', $basePath=null, $locale=null)
	{
	    $locale = $locale ?: $this->locale;
	    
	    $filenames = (array) $filenames;
	    
	    if (!$basePath) {
	        $basePath = Config::getCommonPath();
	    } elseif (!file_exists($basePath)) {
	        $basePath = Config::getRootPath() . trim($basePath, '/');
	    }
	    
	    foreach ($filenames as $file) {
	        if (!is_file($file)) {
	            $file = rtrim($basePath, '/') . '/lang/' . $locale . '/'. $file . '.lang.php';
	        }
	        
	        $content = Ioc::load($file);
	        
	        if ($content && is_array($content)) {
	            $this->data = array_merge($this->data, $content);
	        }
	    }
	}
3007
public static function load_db_logs(
			$filters = false,
			$limit = 200,
			$offset = 0,
			$order = false
		) {
			global $wpdb;

			$query = self::build_db_logs_query(
				$filters,
				$limit,
				$offset,
				$order
			);

			return $wpdb->get_results( $query );
		}
348690
public function loadArray(array $lines, $locale, $group, $namespace = '*')
    {
        // Transform the lines into a flat dot array:
        $lines = array_dot($lines);
        foreach ($lines as $item => $text) {
            if (is_string($text)) {
                // Check if the entry exists in the database:
                $translation = Translation::whereLocale($locale)
                    ->whereNamespace($namespace)
                    ->whereGroup($group)
                    ->whereItem($item)
                    ->first();

                // If the translation already exists, we update the text:
                if ($translation && !$translation->isLocked()) {
                    $translation->text = $text;
                    $saved             = $translation->save();
                    if ($saved && $translation->locale === $this->defaultLocale) {
                        $this->flagAsUnstable($namespace, $group, $item);
                    }
                }
                // If no entry was found, create it:
                else {
                    $this->create(compact('locale', 'namespace', 'group', 'item', 'text'));
                }
            }
        }
    }
1136704
final public function startGetCategories(
        $limit = null,
        $offset = null,
        array $uids = array(),
        $responseType = 'xml'
    ) {
        switch ($responseType) {
            default:
            case 'xml':
                $this->buffer->setFile($this->config->getCategoriesXmlPath());
                break;

            case 'json':
                $this->buffer->setFile($this->config->getCategoriesJsonPath());
                break;
        }

        $this->createCategories($limit, $offset, $uids);
        $this->buffer->finish();
    }
815472
public function getAllSentOrders($storeIds, $limit)
    {
        $collection = $this->addFieldToFilter('email_imported', 1)
            ->addFieldToFilter('store_id', ['in' => $storeIds]);

        $collection->getSelect()->limit($limit);

        return $collection->load();
    }
761069
public function getTransUnitList(array $locales = null, $rows = 20, $page = 1, array $filters = null)
    {
        $sortColumn = isset($filters['sidx']) ? $filters['sidx'] : 'id';
        $order = isset($filters['sord']) ? $filters['sord'] : 'ASC';

        $builder = $this->createQueryBuilder()
            ->hydrate(false)
            ->select('id');

        $this->addTransUnitFilters($builder, $filters);
        $this->addTranslationFilter($builder, $locales, $filters);

        $results = $builder->sort($sortColumn, $order)
            ->skip($rows * ($page - 1))
            ->limit($rows)
            ->getQuery()
            ->execute();

        $ids = array();
        foreach ($results as $result) {
            $ids[] = $result['_id'];
        }

        $transUnits = array();

        if (count($ids) < 1) {
            return $transUnits;
        }

        $results = $this->createQueryBuilder()
            ->hydrate(false)
            ->field('id')->in($ids)
            ->field('translations.locale')->in($locales)
            ->sort(array($sortColumn => $order, 'translations.locale' => 'asc'))
            ->getQuery()
            ->execute();

        foreach ($results as $item) {
            $end = count($item['translations']);
            for ($i = 0; $i < $end; $i++) {
                if (!in_array($item['translations'][$i]['locale'], $locales)) {
                    unset($item['translations'][$i]);
                }
            }
            sort($item['translations']);
            $transUnits[] = $item;
        }

        return $transUnits;
    }
969741
protected function getAdminExtensionReferenceByTypes(array $types)
    {
        $references = [];
        foreach ($types as $type) {
            $references[$type] = new Reference('sonata_translation.admin.extension.'.$type.'_translatable');
        }

        return $references;
    }
1284559
public function findAll($start, $limit, $sortBy, $sortOrder = 'ASC', $params)
    {
        $query = count($params) ? $this->createFilterQuery($params) : new Query();
        $query->setFrom($start);

        // Sort & order
        $fieldName = (isset($sortBy['fieldName'])) ? $sortBy['fieldName'] : null;

        if ($fieldName !== null && $fieldName !== $this->modelIdentifier) {

            if (isset($this->fieldsMapping[$fieldName])) {
                $fieldName = $this->fieldsMapping[$fieldName];
            }
            $query->setSort(array($fieldName => array('order' => strtolower($sortOrder))));
        } else {
            $query->setSort(array(
                $this->modelIdentifier => array('order' => strtolower($sortOrder)),
            ));
        }

        // Custom filter for admin
        if(method_exists($this->admin, 'getExtraFilter')) {
            $query->setFilter($this->admin->getExtraFilter());
        }

        // Limit
        if ($limit === null) {
            $limit = 10000; // set to 0 does not seem to work
        }

        return $this->finder->find($query, $limit);
    }
409961
public function getSearchNodeBuilder($keywords, $type = null, $limit = null, $locale = null)
    {
        // Because of the searchable trait we have to reset global scopes
        $builder = PublishedNode::withoutGlobalScopes()
            ->published()
            ->typeMailing()
            ->translatedIn($locale)
            ->groupBy('nodes.id');

        if ($type)
        {
            $builder->withType($type);
        }

        if ($limit)
        {
            $builder->limit($limit);
        }

        $builder->search($keywords, 20, true);

        return $builder;
    }
974573
public function sourceRecords($params = [], $sort = null, $limit = null)
    {
        $records = [];

        // Get the query to apply across all variants: looks at all subsites, translations, live stage only.
        $crossVariant = (function ($dataQuery) {
            $params = [
                'Subsite.filter' => false,
                'Versioned.mode' => 'stage',
                'Versioned.stage' => Versioned::LIVE,
            ];

            return $dataQuery->setDataQueryParam($params);
        });

        // Total.
        $records[] = [
            'Name' => _t(
                __CLASS__ . '.TotalPageCount',
                'Total live page count, across all translations and subsites'
            ),
            'Count' => $crossVariant(SiteTree::get())->count(),
        ];

        if (class_exists(Subsite::class)) {
            // Main site.
            $records[] = [
                'Name' => _t(__CLASS__ . '.PagesForMainSite', '- in the main site'),
                'Count' => $crossVariant(SiteTree::get())
                    ->filter(['SubsiteID' => 0])
                    ->count(),
            ];

            // Per subsite.
            $subsites = Subsite::get();
            foreach ($subsites as $subsite) {
                $records[] = [
                    'Name' => _t(
                        __CLASS__ . '.PagesForSubsite',
                        "- in the subsite '{SubsiteTitle}'",
                        ['SubsiteTitle' => $subsite->Title]
                    ),
                    'Count' => $crossVariant(SiteTree::get())
                        ->filter(['SubsiteID' => $subsite->ID])
                        ->count(),
                ];
            }
        }

        // Files.
        $records[] = [
            'Name' => _t(__CLASS__ . '.FileCount', 'File count'),
            'Count' => File::get()
                ->setDataQueryParam('Subsite.filter', false)
                ->filter(['ClassName:not' => Folder::class])
                ->count(),
        ];

        return ArrayList::create($records);
    }
1022465
public static function limit($params) {
        $limit = $params['args'][0];
        $ormObject = !is_null($params['ormObject']) ? $params['ormObject'] : ORM::for_table($params['table']);
        
        return $ormObject->limit($limit);
    }
1216853
public function higherItems($limit = null)
    {
        if ($this->isNotInList()) return null;

        $query = $this->listifyScopedQuery()
            ->where($this->positionColumn(), '<', $this->getListifyPosition())
            ->orderBy($this->getTable() . '.' . $this->positionColumn(), 'DESC');

        if (null !== $limit) {
            $query->take($limit);
        }

        return $query->get();
    }
94271
private function executeQuery(string $url, string $locale = null, int $limit): Collection
    {
        if (null !== $locale) {
            $url = sprintf('%s&culture=%s', $url, str_replace('_', '-', $locale));
        }

        $content = $this->getUrlContents($url);
        $json = json_decode($content);

        if (!isset($json->resourceSets[0]) || !isset($json->resourceSets[0]->resources)) {
            return new AddressCollection([]);
        }

        $data = (array) $json->resourceSets[0]->resources;

        $results = [];
        foreach ($data as $item) {
            $builder = new AddressBuilder($this->getName());
            $coordinates = (array) $item->geocodePoints[0]->coordinates;
            $builder->setCoordinates($coordinates[0], $coordinates[1]);

            if (isset($item->bbox) && is_array($item->bbox) && count($item->bbox) > 0) {
                $builder->setBounds($item->bbox[0], $item->bbox[1], $item->bbox[2], $item->bbox[3]);
            }

            $builder->setStreetName($item->address->addressLine ?? null);
            $builder->setPostalCode($item->address->postalCode ?? null);
            $builder->setLocality($item->address->locality ?? null);
            $builder->setCountry($item->address->countryRegion ?? null);
            $builder->setCountryCode($item->address->countryRegionIso2 ?? null);

            foreach (['adminDistrict', 'adminDistrict2'] as $i => $property) {
                if (property_exists($item->address, $property)) {
                    $builder->addAdminLevel($i + 1, $item->address->{$property}, null);
                }
            }

            $results[] = $builder->build();

            if (count($results) >= $limit) {
                break;
            }
        }

        return new AddressCollection($results);
    }
91386
public function getGenericResources($limit = 10, $mode = AbstractQuery::HYDRATE_OBJECT)
    {
        $builder = $this->getEntityManager()->createQueryBuilder();

        $builder->select('e')
            ->from($this->getEntity(), 'e')
            ->where('e.isGeneric = 1')
            ->setMaxResults($limit);

        $query = LocaleAwareTrait::addHints($builder->getQuery());

        return $query->execute($mode);
    }