@param int $siteId
@param $fromDate
@param $toDate
@param $filter
@param int $limit

@return array
553057
public function getReportQuery($siteId, $fromDate, $toDate, $filter, $limit = null)
    {
        $siteList = [];
        $filter   = strtolower($filter);

        if (empty($fromDate)) {
            $fromDate = (new DateTime('first day of the year'))->format('Y-m-d');
        }

        if (empty($toDate)) {
            $toDate = (new DateTime('last day of this month'))->format('Y-m-d');
        }

        $builder = $this->getEntityManager()->createQuerybuilder();
        $query   = $builder->select(
            [
                '(e.popularity) total',
                'DATE(e.rankedAt) regDay',
                's.domain domain',
                '1 valid',
                'e.rankedAt createdAt',
            ]
        )->from($this->getEntity(), 'e')
            ->innerJoin('e.site', 's')
            ->where('e.rankedAt >= :start')
            ->andWhere('e.rankedAt <= :end')
            //->andWhere('s.siteType = :siteType')
            ->addOrderBy('e.rankedAt')
            ->addOrderBy('e.popularity')
            ->addGroupBy('e.site')
            ->setParameters(
                [
                    ':start'    => $fromDate,
                    ':end'      => $toDate,
                   // ':siteType' => 1,
                ]
            );

        if ($siteId) {
            $siteList = array_filter(array_unique(array_merge($siteList, (array)$siteId)));
        } elseif ($limit) {
            $subQueryBuilder = $builder = $this->getEntityManager()->createQuerybuilder();
            $subQuery        = $subQueryBuilder->select('f.id, s.id site_id')
                ->from($this->getEntity(), 'f')
                ->innerJoin('f.site', 's')
                ->groupBy('s.id')
                ->orderBy('f.popularity', 'ASC')
                ->setMaxResults($limit);

            foreach ($subQuery->getQuery()->getArrayResult() as $item) {
                $siteList[] = $item['site_id'];
            }
        }

        if ($siteList) {
            $query->andWhere($builder->expr()->in('s.id', $siteList));
        }
        switch ($filter) {
            case 'year':
                $query->addSelect('YEAR(e.rankedAt) regYear')
                    ->addGroupBy('regYear');
                break;
            case 'month':
                $query->addSelect('Month(e.rankedAt) regMonth')
                    ->addGroupBy('regMonth');
                break;
            case 'week':
                $query->addSelect('WEEK(e.rankedAt) regWeek')
                    ->addGroupBy('regWeek');
                break;
            case 'hour':
                $query->addSelect('HOUR(e.rankedAt) regHour')
                    ->addGroupBy('regHour');
                break;
            case 'day':
            default:
                $query->addGroupBy('regDay');
        }

        return $query->getQuery()->getArrayResult();
    }
836331
public function getDataBySiteIdAndPageId($siteId, $pageId)
	{
	    $select = $this->tableGateway->getSql()->select();
	     
	    $select->columns(array('*'));
	     
	    $select->where(array("s404_site_id" => $siteId, 's404_page_id' => $pageId));
	    $resultSet = $this->tableGateway->selectWith($select);
	     
	    return $resultSet;
	}
893239
public function downtime(int $siteId, string $startedAt, string $endedAt): array
    {
        return $this->transformCollection(
            $this->get("sites/$siteId/downtime?filter[started_at]={$startedAt}&filter[ended_at]={$endedAt}")['data'],
            Downtime::class
        );
    }
485426
public function generateOccurrences(Array $events, \DateTime $fromDate, \DateTime $toDate, $limit = null)
	{
		$return = array();
		$object = $this;

		$monthlyEvents = array_filter($events, function ($event) use ($object) {
			return $event->getRecurrenceType() === $object->getLabel();
		});

		foreach ($monthlyEvents as $monthlyEvent) {
			$monthlyEventTime = $monthlyEvent->getStartDate()->format('H:i:s');

			$monthlyDate = $monthlyEvent->getStartDate()->format('d');

			$start = $fromDate > $monthlyEvent->getStartDate()
				? clone($fromDate)
				: clone($monthlyEvent->getStartDate());

			$startMarker = clone($start);
			$startMarker->setDate($start->format('Y'), $start->format('m'), 1);

			$maxEndMarker = clone($startMarker);
			$maxEndMarker->modify($this->limit);

			$endMarker = $monthlyEvent->getRecurrenceUntil()
				? min($monthlyEvent->getRecurrenceUntil(), clone($toDate), $maxEndMarker)
				: min(clone($toDate), $maxEndMarker);

			$actualEndMarker = clone($endMarker);

			// The DatePeriod class does not actually include the end date so you have to increment it first
			$endMarker->modify('+1 day');

			$dateInterval = new \DateInterval('P1M');
			$datePeriod = new \DatePeriod($startMarker, $dateInterval, $endMarker);

			$limitMarker = 0;

			foreach ($datePeriod as $date) {
				if (($limit and ($limit === $limitMarker)) or ($date > $actualEndMarker)) {
					break;
				}

				if ($monthlyDate > $date->format('t')) {
					continue;
				}

				$date->setDate($date->format('Y'), $date->format('m'), sprintf('%2d', $monthlyDate));

				$newMonthlyEvent = clone($monthlyEvent);
				$newStartDate = new \DateTime($date->format('Y-m-d').' '.$monthlyEventTime);

				if ($newStartDate < $startMarker) {
					continue;
				}

				$duration = $newMonthlyEvent->getDuration();

				$newMonthlyEvent->setStartDate($newStartDate);

				$newEndDate = clone($newStartDate);
				$newEndDate->add($duration);
				
				$newMonthlyEvent->setEndDate($newEndDate);
				$newMonthlyEvent->setRecurrenceType();

				$return[] = $newMonthlyEvent;

				$limit and $limitMarker++;
			}
		}

		return $return;
	}
1137299
public function getParameterFilterWidgets(
        $idList,
        $filterUrlList,
        $jumpToList,
        FrontendFilterOptions $frontendFilterOptions
    ) {
        // If defined as static, return nothing as not to be manipulated via editors.
        if (!$this->enableFEFilterWidget()) {
            return [];
        }

        $filterWidgets               = [];
        $GLOBALS['MM_FILTER_PARAMS'] = \array_merge(
            ($GLOBALS['MM_FILTER_PARAMS'] ?? []),
            [
                $this->getParamName(),
                $this->getParamNameRange()
            ]
        );

        // Address search.
        $widgets      = $this->getSearchWidget($frontendFilterOptions);
        $rangeWidgets = $this->getRangeWidget();

        // Add filter.
        $filterWidgets[$this->getParamName()] = $this
            ->prepareFrontendFilterWidget($widgets, $filterUrlList, $jumpToList, $frontendFilterOptions);

        // Add range filter if we have one.
        if ($rangeWidgets) {
            $filterWidgets[$this->getParamNameRange()] = $this
                ->prepareFrontendFilterWidget($rangeWidgets, $filterUrlList, $jumpToList, $frontendFilterOptions);
        }

        return $filterWidgets;
    }
1336279
protected function getDbRoutes($siteId = null): array
    {
        if ($siteId === null) {
            $siteId = Craft::$app->getSites()->currentSite->id;
        }
        if ($siteId === 'global') {
            $siteId = null;
        }
        // If we're on Craft 3.1 or later, just return the array from getProjectConfigRoutes();
        if (RouteMap::$craft31) {
            return Craft::$app->getRoutes()->getProjectConfigRoutes();
        }

        // Normalize the URL
        $results = (new Query())
            ->select(['uriPattern', 'template'])
            ->from(['{{%routes}}'])
            ->where([
                'or',
                ['siteId' => $siteId],
            ])
            ->orderBy(['sortOrder' => SORT_ASC])
            ->all();

        return ArrayHelper::map($results, 'uriPattern', function ($results) {
            return ['template' => $results['template']];
        });
    }
1300513
private function getSearchableCategories($storeId, $categoryIds = null, $fromId = 0, $limit = 100)
    {
        return $this->resourceModel->getSearchableCategories($storeId, $categoryIds, $fromId, $limit);
    }
1217516
public function getDeleteSQL($from, $joins, $where, $values, $order, $limit) {
        $len    = count($joins);
        $jw     = [];
        $sql [] = 'DELETE FROM ' . implode(' AS ', $from [0]);
        if ($len) {
            $sql [] = 'USING';

            foreach ($joins as $join) {
                $jw[]   = $join[1];
                $sql [] = $join [0] . ' AS ' . $join [3];
            }
        }

        if ($where && count($where) > 0) {
            $sql [] = 'WHERE';
            $sql [] = $where->getWhereCondition($this, $values);
        }
        if ($jw) {
            if ($where && count($where) > 0) {
                $sql[] = 'AND ' . implode(' AND ', $jw);
            } else {
                $sql[] = 'WHERE ' . implode(' AND ', $jw);
            }
        }

        return implode(' ', $sql);
    }
164951
public function build(int $limit = 50000)
    {
        $sitemaps = [];

        $entities = $this->fetchEntities();

        if (count($entities) > $limit) {
            $sitemapIndex = new SiteMapIndexEntity();

            foreach (array_chunk($entities, $limit) as $i => $chunk) {
                $sitemap = $this->saveSitemap(sprintf('%s/sitemap-%s.xml', $this->path, $i), $chunk);
                $loc = sprintf('%s/sitemap-%s.xml', rtrim($this->hostWithScheme, '/'), $i);
                $sitemap->setLoc($loc);
                $sitemaps[] = sprintf('%s/sitemap-%s.xml', rtrim($this->path, '/'), $i);

                $sitemapIndex->addSiteMap($sitemap);
            }

            $this->saveFile(sprintf('%s/sitemap.xml', rtrim($this->path, '/')), $sitemapIndex->getXml());
        } else {
            $this->saveSitemap(sprintf('%s/sitemap.xml', rtrim($this->path, '/')), $entities);
        }

        $sitemaps[] = sprintf('%s/sitemap.xml', rtrim($this->path, '/'));

        return $sitemaps;
    }
898806
public function getProductsInModifiedInterval(int $siteId, \DateTimeInterface $dateStart, \DateTimeInterface $dateEnd) : array
    {
        Assert::that($siteId)->greaterThan(0, 'The $siteId has to be positive');
        Assert::that($dateStart)->lessThan($dateEnd, '$dateStart has to be before $dateEnd');

        return (array)$this->master->doRequest(
            'GET',
            sprintf(
                '/admin/WEBAPI/Endpoints/v1_0/ProductService/{KEY}/GetByModifiedInterval/%d?start=%s&end=%s',
                $siteId,
                $dateStart->format('Y-m-d\TH:i:s'),
                $dateEnd->format('Y-m-d\TH:i:s')
            )
        );
    }
750884
public function actionGetAllUrls(array $criteria = [], $siteId = null): Response
    {
        return $this->asJson(RouteMap::$plugin->routes->getAllUrls($criteria, $siteId));
    }
110719
public function findItemsToIndex(Site $site, int $limit = 50) : array
    {
        $queryBuilder = $this->getQueryBuilder();
        // determine which items to index with this run
        $indexQueueItemRecords = $queryBuilder
            ->select('*')
            ->from($this->table)
            ->andWhere(
                $queryBuilder->expr()->eq('root', $site->getRootPageId()),
                $queryBuilder->expr()->gt('changed', 'indexed'),
                $queryBuilder->expr()->lte('changed', time()),
                $queryBuilder->expr()->eq('errors', $queryBuilder->createNamedParameter(''))
            )
            ->orderBy('indexing_priority', 'DESC')
            ->addOrderBy('changed', 'DESC')
            ->addOrderBy('uid', 'DESC')
            ->setMaxResults($limit)
            ->execute()->fetchAll();

        return $this->getIndexQueueItemObjectsFromRecords($indexQueueItemRecords);
    }
1131263
public function getLookupResults($type, $filter = '', $limit = 10)
    {
        return $this->getRepository()->getValueList($type, $filter, $limit);
    }
640701
public function sqlDelete(
		$from,
		$where,
		array $where_params,
		$limit = null
	) {
		$sql = $this->queryBuilder->buildDelete($from, $where, $limit);
		$query = $this->database->prepare($sql);
		$query->execute($where_params);
		$this->addQuery($query->queryString, $where_params);
		return $query->rowCount();
	}
69542
public function getFromWhere($from, $where=NULL, $where_values=array(), $order=NULL, $limit=NULL, $offset=NULL){
        $res= FALSE;
        try{
            //Armo partes de la consulta
            if($order != NULL){$order= " ORDER BY " . $order;}
            if($limit != NULL){
                $limit= " LIMIT " . $limit;
                if($offset != NULL){$limit.= ' OFFSET ' . $offset;}
            }
            //Armo y preparo la consulta
            $query= $this->prepareSelect($this->select, $from, $where, '', '', $order, $limit);
            //Ejecuto la consulta
            $query->execute($where_values);
            //Controlo que este todo bien
            if($this->isOk($query)){
                $res= $query;
            }
            //Limpio las variables del AR
            $this->cleanVars();
        } catch (\PDOException $e) {
            $this->cleanVars();
            throw $e;
        }
        return $res;
    }
632317
public function replayTransactionLog($fromDate = null, $toDate = null)
    {
        return $this->getDataUpdater()->replayTransactionLog($fromDate, $toDate);
    }
784108
public function actionGetSectionUrls(string $section, array $criteria = [], $siteId = null): Response
    {
        return $this->asJson(RouteMap::$plugin->routes->getSectionUrls($section, $criteria, $siteId));
    }