Piwik\Archive::build PHP Method

build() public static method

This method uses data that is found in query parameters, so the parameters to this function can be string values. If you want to create an Archive instance with an array of Period instances, use {@link Archive::factory()}.
public static build ( string | integer | array $idSites, string $period, Date | string $strDate, boolean | false | string $segment = false, boolean | false | string $_restrictSitesToLogin = false ) : static
$idSites string | integer | array A single ID (eg, `'1'`), multiple IDs (eg, `'1,2,3'` or `array(1, 2, 3)`), or `'all'`.
$period string 'day', `'week'`, `'month'`, `'year'` or `'range'`
$strDate Date | string 'YYYY-MM-DD', magic keywords (ie, 'today'; {@link Date::factory()} or date range (ie, 'YYYY-MM-DD,YYYY-MM-DD').
$segment boolean | false | string Segment definition or false if no segment should be used. {@link Piwik\Segment}
$_restrictSitesToLogin boolean | false | string Used only when running as a scheduled task.
return static
    public static function build($idSites, $period, $strDate, $segment = false, $_restrictSitesToLogin = false)
    {
        $websiteIds = Site::getIdSitesFromIdSitesString($idSites, $_restrictSitesToLogin);
        $timezone = false;
        if (count($websiteIds) == 1) {
            $timezone = Site::getTimezoneFor($websiteIds[0]);
        }
        if (Period::isMultiplePeriod($strDate, $period)) {
            $oPeriod = PeriodFactory::build($period, $strDate, $timezone);
            $allPeriods = $oPeriod->getSubperiods();
        } else {
            $oPeriod = PeriodFactory::makePeriodFromQueryParams($timezone, $period, $strDate);
            $allPeriods = array($oPeriod);
        }
        $segment = new Segment($segment, $websiteIds);
        $idSiteIsAll = $idSites == self::REQUEST_ALL_WEBSITES_FLAG;
        $isMultipleDate = Period::isMultiplePeriod($strDate, $period);
        return static::factory($segment, $allPeriods, $websiteIds, $idSiteIsAll, $isMultipleDate);
    }

Usage Example

Exemplo n.º 1
0
Arquivo: API.php Projeto: piwik/piwik
 protected function getNumeric($idSite, $period, $date, $segment, $toFetch)
 {
     Piwik::checkUserHasViewAccess($idSite);
     $archive = Archive::build($idSite, $period, $date, $segment);
     $dataTable = $archive->getDataTableFromNumeric($toFetch);
     return $dataTable;
 }
All Usage Examples Of Piwik\Archive::build