本文整理汇总了PHP中Piwik\Period\Range::parseDateRange方法的典型用法代码示例。如果您正苦于以下问题:PHP Range::parseDateRange方法的具体用法?PHP Range::parseDateRange怎么用?PHP Range::parseDateRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik\Period\Range
的用法示例。
在下文中一共展示了Range::parseDateRange方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeRender
public function beforeRender()
{
if ($this->requestConfig->idSubtable && $this->config->show_embedded_subtable) {
$this->config->show_visualization_only = true;
}
// we do not want to get a datatable\map
$period = Common::getRequestVar('period', 'day', 'string');
if (Period\Range::parseDateRange($period)) {
$period = 'range';
}
if ($this->dataTable->getRowsCount()) {
$request = new ApiRequest(array('method' => 'API.get', 'module' => 'API', 'action' => 'get', 'format' => 'original', 'filter_limit' => '-1', 'disable_generic_filters' => 1, 'expanded' => 0, 'flat' => 0, 'filter_offset' => 0, 'period' => $period, 'showColumns' => implode(',', $this->config->columns_to_display), 'columns' => implode(',', $this->config->columns_to_display), 'pivotBy' => ''));
$dataTable = $request->process();
$this->assignTemplateVar('siteSummary', $dataTable);
}
}
示例2: calculateEvolutionDateRange
/**
* Based on the period, date and evolution_{$period}_last_n query parameters,
* calculates the date range this evolution chart will display data for.
*/
private function calculateEvolutionDateRange()
{
$period = Common::getRequestVar('period');
$defaultLastN = self::getDefaultLastN($period);
$originalDate = Common::getRequestVar('date', 'last' . $defaultLastN, 'string');
if ('range' != $period) {
// show evolution limit if the period is not a range
$this->config->show_limit_control = true;
// set the evolution_{$period}_last_n query param
if (Range::parseDateRange($originalDate)) {
// if a multiple period
// overwrite last_n param using the date range
$oPeriod = new Range($period, $originalDate);
$lastN = count($oPeriod->getSubperiods());
} else {
// if not a multiple period
list($newDate, $lastN) = self::getDateRangeAndLastN($period, $originalDate, $defaultLastN);
$this->requestConfig->request_parameters_to_modify['date'] = $newDate;
$this->config->custom_parameters['dateUsedInGraph'] = $newDate;
}
$lastNParamName = self::getLastNParamName($period);
$this->config->custom_parameters[$lastNParamName] = $lastN;
}
}
示例3: isMultiplePeriod
/**
* Returns true if `$dateString` and `$period` represent multiple periods.
*
* Will return true for date/period combinations where date references multiple
* dates and period is not `'range'`. For example, will return true for:
*
* - **date** = `2012-01-01,2012-02-01` and **period** = `'day'`
* - **date** = `2012-01-01,2012-02-01` and **period** = `'week'`
* - **date** = `last7` and **period** = `'month'`
*
* etc.
*
* @static
* @param $dateString The **date** query parameter value.
* @param $period The **period** query parameter value.
* @return boolean
*/
public static function isMultiplePeriod($dateString, $period)
{
return is_string($dateString) && (preg_match('/^(last|previous){1}([0-9]*)$/D', $dateString, $regs) || Range::parseDateRange($dateString)) && $period != 'range';
}
示例4: generate
/**
* Generates the subperiods
*
* @throws Exception
*/
protected function generate()
{
if ($this->subperiodsProcessed) {
return;
}
parent::generate();
if (preg_match('/(last|previous)([0-9]*)/', $this->strDate, $regs)) {
$lastN = $regs[2];
$lastOrPrevious = $regs[1];
if (!is_null($this->defaultEndDate)) {
$defaultEndDate = $this->defaultEndDate;
} else {
$defaultEndDate = $this->today;
}
$period = $this->strPeriod;
if ($period == 'range') {
$period = 'day';
}
if ($lastOrPrevious == 'last') {
$endDate = $defaultEndDate;
} elseif ($lastOrPrevious == 'previous') {
if ('month' == $period) {
$endDate = $defaultEndDate->subMonth(1);
} else {
$endDate = $defaultEndDate->subPeriod(1, $period);
}
}
$lastN = $this->getMaxN($lastN);
// last1 means only one result ; last2 means 2 results so we remove only 1 to the days/weeks/etc
$lastN--;
$lastN = abs($lastN);
$startDate = $endDate->addPeriod(-1 * $lastN, $period);
} elseif ($dateRange = Range::parseDateRange($this->strDate)) {
$strDateStart = $dateRange[1];
$strDateEnd = $dateRange[2];
$startDate = Date::factory($strDateStart);
if ($strDateEnd == 'today') {
$strDateEnd = 'now';
} elseif ($strDateEnd == 'yesterday') {
$strDateEnd = 'yesterdaySameTime';
}
// we set the timezone in the Date object only if the date is relative eg. 'today', 'yesterday', 'now'
$timezone = null;
if (strpos($strDateEnd, '-') === false) {
$timezone = $this->timezone;
}
$endDate = Date::factory($strDateEnd, $timezone);
} else {
throw new Exception(Piwik::translate('General_ExceptionInvalidDateRange', array($this->strDate, ' \'lastN\', \'previousN\', \'YYYY-MM-DD,YYYY-MM-DD\'')));
}
if ($this->strPeriod != 'range') {
$this->fillArraySubPeriods($startDate, $endDate, $this->strPeriod);
return;
}
$this->processOptimalSubperiods($startDate, $endDate);
// When period=range, we want End Date to be the actual specified end date,
// rather than the end of the month / week / whatever is used for processing this range
$this->endDate = $endDate;
}
示例5: loadLastVisitorDetailsFromDatabase
private function loadLastVisitorDetailsFromDatabase($idSite, $period, $date, $segment = false, $countVisitorsToFetch = 100, $visitorId = false, $minTimestamp = false, $filterSortOrder = false)
{
$where = $whereBind = array();
list($whereClause, $idSites) = $this->getIdSitesWhereClause($idSite);
$where[] = $whereClause;
$whereBind = $idSites;
if (strtolower($filterSortOrder) !== 'asc') {
$filterSortOrder = 'DESC';
}
$orderBy = "idsite, visit_last_action_time " . $filterSortOrder;
$orderByParent = "sub.visit_last_action_time " . $filterSortOrder;
if (!empty($visitorId)) {
$where[] = "log_visit.idvisitor = ? ";
$whereBind[] = @Common::hex2bin($visitorId);
}
if (!empty($minTimestamp)) {
$where[] = "log_visit.visit_last_action_time > ? ";
$whereBind[] = date("Y-m-d H:i:s", $minTimestamp);
}
// If no other filter, only look at the last 24 hours of stats
if (empty($visitorId) && empty($countVisitorsToFetch) && empty($period) && empty($date)) {
$period = 'day';
$date = 'yesterdaySameTime';
}
// SQL Filter with provided period
if (!empty($period) && !empty($date)) {
$currentSite = new Site($idSite);
$currentTimezone = $currentSite->getTimezone();
$dateString = $date;
if ($period == 'range') {
$processedPeriod = new Range('range', $date);
if ($parsedDate = Range::parseDateRange($date)) {
$dateString = $parsedDate[2];
}
} else {
$processedDate = Date::factory($date);
if ($date == 'today' || $date == 'now' || $processedDate->toString() == Date::factory('now', $currentTimezone)->toString()) {
$processedDate = $processedDate->subDay(1);
}
$processedPeriod = Period\Factory::build($period, $processedDate);
}
$dateStart = $processedPeriod->getDateStart()->setTimezone($currentTimezone);
$where[] = "log_visit.visit_last_action_time >= ?";
$whereBind[] = $dateStart->toString('Y-m-d H:i:s');
if (!in_array($date, array('now', 'today', 'yesterdaySameTime')) && strpos($date, 'last') === false && strpos($date, 'previous') === false && Date::factory($dateString)->toString('Y-m-d') != Date::factory('now', $currentTimezone)->toString()) {
$dateEnd = $processedPeriod->getDateEnd()->setTimezone($currentTimezone);
$where[] = " log_visit.visit_last_action_time <= ?";
$dateEndString = $dateEnd->addDay(1)->toString('Y-m-d H:i:s');
$whereBind[] = $dateEndString;
}
}
if (count($where) > 0) {
$where = join("\n\t\t\t\tAND ", $where);
} else {
$where = false;
}
$segment = new Segment($segment, $idSite);
// Subquery to use the indexes for ORDER BY
$select = "log_visit.*";
$from = "log_visit";
$subQuery = $segment->getSelectQuery($select, $from, $where, $whereBind, $orderBy);
$sqlLimit = $countVisitorsToFetch >= 1 ? " LIMIT 0, " . (int) $countVisitorsToFetch : "";
// Group by idvisit so that a visitor converting 2 goals only appears once
$sql = "\n\t\t\tSELECT sub.* FROM (\n\t\t\t\t" . $subQuery['sql'] . "\n\t\t\t\t{$sqlLimit}\n\t\t\t) AS sub\n\t\t\tGROUP BY sub.idvisit\n\t\t\tORDER BY {$orderByParent}\n\t\t";
try {
$data = Db::fetchAll($sql, $subQuery['bind']);
} catch (Exception $e) {
echo $e->getMessage();
exit;
}
$dataTable = new DataTable();
$dataTable->addRowsFromSimpleArray($data);
// $dataTable->disableFilter('Truncate');
if (!empty($data[0])) {
$columnsToNotAggregate = array_map(function () {
return 'skip';
}, $data[0]);
$dataTable->setMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME, $columnsToNotAggregate);
}
return $dataTable;
}
示例6: getWhereClauseAndBind
/**
* @param string $whereClause
* @param array $bindIdSites
* @param $idSite
* @param $period
* @param $date
* @param $visitorId
* @param $minTimestamp
* @return array
* @throws Exception
*/
private function getWhereClauseAndBind($whereClause, $bindIdSites, $idSite, $period, $date, $visitorId, $minTimestamp)
{
$where = array();
$where[] = $whereClause;
$whereBind = $bindIdSites;
if (!empty($visitorId)) {
$where[] = "log_visit.idvisitor = ? ";
$whereBind[] = @Common::hex2bin($visitorId);
}
if (!empty($minTimestamp)) {
$where[] = "log_visit.visit_last_action_time > ? ";
$whereBind[] = date("Y-m-d H:i:s", $minTimestamp);
}
// SQL Filter with provided period
if (!empty($period) && !empty($date)) {
$currentSite = $this->makeSite($idSite);
$currentTimezone = $currentSite->getTimezone();
$dateString = $date;
if ($period == 'range') {
$processedPeriod = new Range('range', $date);
if ($parsedDate = Range::parseDateRange($date)) {
$dateString = $parsedDate[2];
}
} else {
$processedDate = Date::factory($date);
$processedPeriod = Period\Factory::build($period, $processedDate);
}
$dateStart = $processedPeriod->getDateStart()->setTimezone($currentTimezone);
$where[] = "log_visit.visit_last_action_time >= ?";
$whereBind[] = $dateStart->toString('Y-m-d H:i:s');
if (!in_array($date, array('now', 'today', 'yesterdaySameTime')) && strpos($date, 'last') === false && strpos($date, 'previous') === false && Date::factory($dateString)->toString('Y-m-d') != Date::factory('now', $currentTimezone)->toString()) {
$dateEnd = $processedPeriod->getDateEnd()->setTimezone($currentTimezone);
$where[] = " log_visit.visit_last_action_time <= ?";
$dateEndString = $dateEnd->addDay(1)->toString('Y-m-d H:i:s');
$whereBind[] = $dateEndString;
}
}
if (count($where) > 0) {
$where = join("\n\t\t\t\tAND ", $where);
} else {
$where = false;
}
return array($whereBind, $where);
}