本文整理汇总了PHP中Piwik\Date::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP Date::factory方法的具体用法?PHP Date::factory怎么用?PHP Date::factory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik\Date
的用法示例。
在下文中一共展示了Date::factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getArchiveIdAndVisits
public static function getArchiveIdAndVisits(ArchiveProcessor\Parameters $params, $minDatetimeArchiveProcessedUTC)
{
$idSite = $params->getSite()->getId();
$period = $params->getPeriod()->getId();
$dateStart = $params->getPeriod()->getDateStart();
$dateStartIso = $dateStart->toString('Y-m-d');
$dateEndIso = $params->getPeriod()->getDateEnd()->toString('Y-m-d');
$numericTable = ArchiveTableCreator::getNumericTable($dateStart);
$minDatetimeIsoArchiveProcessedUTC = null;
if ($minDatetimeArchiveProcessedUTC) {
$minDatetimeIsoArchiveProcessedUTC = Date::factory($minDatetimeArchiveProcessedUTC)->getDatetime();
}
$requestedPlugin = $params->getRequestedPlugin();
$segment = $params->getSegment();
$plugins = array("VisitsSummary", $requestedPlugin);
$doneFlags = Rules::getDoneFlags($plugins, $segment);
$doneFlagValues = Rules::getSelectableDoneFlagValues();
$results = self::getModel()->getArchiveIdAndVisits($numericTable, $idSite, $period, $dateStartIso, $dateEndIso, $minDatetimeIsoArchiveProcessedUTC, $doneFlags, $doneFlagValues);
if (empty($results)) {
return false;
}
$idArchive = self::getMostRecentIdArchiveFromResults($segment, $requestedPlugin, $results);
$idArchiveVisitsSummary = self::getMostRecentIdArchiveFromResults($segment, "VisitsSummary", $results);
list($visits, $visitsConverted) = self::getVisitsMetricsFromResults($idArchive, $idArchiveVisitsSummary, $results);
if (false === $visits && false === $idArchive) {
return false;
}
return array($idArchive, $visits, $visitsConverted);
}
示例2: renderTable
/**
* Computes the output for the given data table
*
* @param DataTable $table
* @return string
* @throws Exception
*/
protected function renderTable($table)
{
if (!$table instanceof DataTable\Map || $table->getKeyName() != 'date') {
throw new Exception("RSS feeds can be generated for one specific website &idSite=X." . "\nPlease specify only one idSite or consider using &format=XML instead.");
}
$idSite = Common::getRequestVar('idSite', 1, 'int');
$period = Common::getRequestVar('period');
$piwikUrl = SettingsPiwik::getPiwikUrl() . "?module=CoreHome&action=index&idSite=" . $idSite . "&period=" . $period;
$out = "";
$moreRecentFirst = array_reverse($table->getDataTables(), true);
foreach ($moreRecentFirst as $date => $subtable) {
/** @var DataTable $subtable */
$timestamp = $subtable->getMetadata(Archive\DataTableFactory::TABLE_METADATA_PERIOD_INDEX)->getDateStart()->getTimestamp();
$site = $subtable->getMetadata(Archive\DataTableFactory::TABLE_METADATA_SITE_INDEX);
$pudDate = date('r', $timestamp);
$dateInSiteTimezone = Date::factory($timestamp);
if ($site) {
$dateInSiteTimezone = $dateInSiteTimezone->setTimezone($site->getTimezone());
}
$dateInSiteTimezone = $dateInSiteTimezone->toString('Y-m-d');
$thisPiwikUrl = Common::sanitizeInputValue($piwikUrl . "&date={$dateInSiteTimezone}");
$siteName = $site ? $site->getName() : '';
$title = $siteName . " on " . $date;
$out .= "\t<item>\n\t\t<pubDate>{$pudDate}</pubDate>\n\t\t<guid>{$thisPiwikUrl}</guid>\n\t\t<link>{$thisPiwikUrl}</link>\n\t\t<title>{$title}</title>\n\t\t<author>http://piwik.org</author>\n\t\t<description>";
$out .= Common::sanitizeInputValue($this->renderDataTable($subtable));
$out .= "</description>\n\t</item>\n";
}
$header = $this->getRssHeader();
$footer = $this->getRssFooter();
return $header . $out . $footer;
}
示例3: testGetPrettyString
/**
* @group Core
*/
public function testGetPrettyString()
{
Translate::loadEnglishTranslation();
$year = new Year(Date::factory('2024-10-09'));
$shouldBe = '2024';
$this->assertEquals($shouldBe, $year->getPrettyString());
}
示例4: beforeTableDataCached
protected static function beforeTableDataCached()
{
$date = Date::factory('2010-03-01');
$archiveTableCreator = new ArchiveTableCreator();
$archiveTableCreator->getBlobTable($date);
$archiveTableCreator->getNumericTable($date);
}
示例5: __construct
/**
* Constructor.
*/
public function __construct()
{
$date = $this->month . '-01';
$classes = get_declared_classes();
sort($classes);
foreach ($classes as $className) {
if (is_subclass_of($className, 'Fixture') && !is_subclass_of($className, __CLASS__) && $className != __CLASS__ && $className != "Piwik_Test_Fixture_SqlDump" && $className != "Piwik\\Tests\\Fixtures\\UpdaterTestFixture") {
$klassReflect = new ReflectionClass($className);
if (!strpos($klassReflect->getFilename(), "tests/PHPUnit/Fixtures") && $className != "Test_Piwik_Fixture_CustomAlerts" && $className != "Piwik\\Plugins\\Insights\\tests\\Fixtures\\SomeVisitsDifferentPathsOnTwoDays") {
continue;
}
$fixture = new $className();
if (!property_exists($fixture, 'dateTime')) {
continue;
}
$fixture->dateTime = $this->adjustDateTime($fixture->dateTime, $date);
$this->fixtures[$className] = $fixture;
$date = Date::factory($date)->addDay(1)->toString();
}
}
$this->now = $this->fixtures['Test_Piwik_Fixture_ManySitesImportedLogsWithXssAttempts']->now;
// make sure Test_Piwik_Fixture_ManySitesImportedLogsWithXssAttempts is the first fixture
$fixture = $this->fixtures['Test_Piwik_Fixture_ManySitesImportedLogsWithXssAttempts'];
unset($this->fixtures['Test_Piwik_Fixture_ManySitesImportedLogsWithXssAttempts']);
$this->fixtures = array_merge(array('Test_Piwik_Fixture_ManySitesImportedLogsWithXssAttempts' => $fixture), $this->fixtures);
}
示例6: index
public function index()
{
Piwik::checkUserHasSuperUserAccess();
$view = new View('@TasksTimetable/index.twig');
$this->setGeneralVariablesView($view);
$tasks = Option::get('TaskScheduler.timetable');
if (!empty($tasks)) {
$tasks = unserialize($tasks);
}
if (empty($tasks)) {
$tasks = array();
} else {
asort($tasks);
}
$tsNow = Date::now()->getTimestamp();
$dateFormat = Piwik::translate(Date::DATE_FORMAT_LONG) . ' h:mm:ss';
$formatter = new Formatter();
$tasksFormatted = array();
foreach ($tasks as $name => $timestamp) {
$tasksFormatted[] = array('name' => $name, 'executionDate' => Date::factory($timestamp)->getLocalized($dateFormat), 'ts_difference' => $formatter->getPrettyTimeFromSeconds($timestamp - $tsNow));
}
$view->currentTime = Date::now()->getLocalized($dateFormat);
$view->tasks = $tasksFormatted;
return $view->render();
}
示例7: trackVisits
private function trackVisits()
{
$dateTime = $this->dateTime;
$idSite = 1;
$idGoal_OneConversionPerVisit = $this->idGoal_OneConversionPerVisit;
$idGoal_MultipleConversionPerVisit = $this->idGoal_MultipleConversionPerVisit;
$t = self::getTracker($idSite, $dateTime, $defaultInit = true);
// Record 1st goal, should only have 1 conversion
$t->setUrl('http://example.org/index.htm');
$t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.3)->getDatetime());
self::checkResponse($t->doTrackPageView('Thank you mate'));
$t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.4)->getDatetime());
self::checkResponse($t->doTrackGoal($idGoal_OneConversionPerVisit, $revenue = 10000000));
// Record 2nd goal, should record both conversions
$t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.5)->getDatetime());
self::checkResponse($t->doTrackGoal($idGoal_MultipleConversionPerVisit, $revenue = 300));
$t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.6)->getDatetime());
self::checkResponse($t->doTrackGoal($idGoal_MultipleConversionPerVisit, $revenue = 366));
// Update & set to not allow multiple
$goals = API::getInstance()->getGoals($idSite);
$goal = $goals[$idGoal_OneConversionPerVisit];
self::assertTrue($goal['allow_multiple'] == 0);
API::getInstance()->updateGoal($idSite, $idGoal_OneConversionPerVisit, $goal['name'], @$goal['match_attribute'], @$goal['pattern'], @$goal['pattern_type'], @$goal['case_sensitive'], $goal['revenue'], $goal['allow_multiple'] = 1);
self::assertTrue($goal['allow_multiple'] == 1);
// 1st goal should Now be tracked
$t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.61)->getDatetime());
self::checkResponse($t->doTrackGoal($idGoal_OneConversionPerVisit, $revenue = 656));
// few minutes later, create a new_visit
$t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.7)->getDatetime());
$t->setTokenAuth($this->getTokenAuth());
$t->setForceNewVisit();
$t->doTrackPageView('This is tracked in a new visit.');
}
示例8: setUp
public function setUp()
{
parent::setUp();
$this->archiveTableDao = self::$fixture->piwikEnvironment->getContainer()->get('Piwik\\DataAccess\\ArchiveTableDao');
ArchiveTableCreator::getBlobTable(Date::factory('2015-01-01'));
ArchiveTableCreator::getNumericTable(Date::factory('2015-01-01'));
}
示例9: trackVisits
private function trackVisits()
{
$dateTime = $this->dateTime;
$idSite = $this->idSite;
$t = self::getTracker($idSite, $dateTime, $defaultInit = true);
$t->setUrlReferrer('http://www.google.com/search?q=piwik');
$t->setUrl('http://example.org/foo/bar.html');
self::checkResponse($t->doTrackPageView('http://incredible.title/'));
$t->setUrl('https://example.org/foo/bar.html');
$t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.2)->getDatetime());
self::checkResponse($t->doTrackPageView('https://incredible.title/'));
$t->setUrl('https://wWw.example.org/foo/bar2.html');
$t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.3)->getDatetime());
self::checkResponse($t->doTrackPageView('http://www.incredible.title/'));
$t->setUrl('http://WwW.example.org/foo/bar2.html');
$t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.4)->getDatetime());
self::checkResponse($t->doTrackPageView('https://www.incredible.title/'));
$t->setUrl('http://www.example.org/foo/bar3.html');
$t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.5)->getDatetime());
self::checkResponse($t->doTrackPageView('incredible.title/'));
$t->setUrl('http://www.my.url/ꟽ碌㒧䊶亄ﶆⅅขκもኸόσशμεޖृ');
$t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.7)->getDatetime());
self::checkResponse($t->doTrackPageView('Valid URL, although strange looking'));
$t->setUrl('https://make.wordpress.org/?emoji=😎l¶m=test');
$t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.8)->getDatetime());
self::checkResponse($t->doTrackPageView('Emoji here: %F0%9F%98%8E'));
// this pageview should be last
$t->setUrl('https://example.org/foo/bar4.html');
$t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.6)->getDatetime());
self::checkResponse($t->doTrackPageView('incredible.title/'));
}
示例10: trackVisits
private function trackVisits()
{
$dateTime = $this->dateTime;
$idSite = $this->idSite;
$t = self::getTracker($idSite, $dateTime, $defaultInit = true, $useThirdPartyCookie = 1);
$t->setUrlReferrer('http://www.google.com.vn/url?sa=t&rct=j&q=%3C%3E%26%5C%22the%20pdo%20extension%20is%20required%20for%20this%20adapter%20but%20the%20extension%20is%20not%20loaded&source=web&cd=4&ved=0FjAD&url=http%3A%2F%2Fforum.piwik.org%2Fread.php%3F2%2C1011&ei=y-HHAQ&usg=AFQjCN2-nt5_GgDeg&cad=rja');
$t->setUrl('http://example.org/%C3%A9%C3%A9%C3%A9%22%27...%20%3Cthis%20is%20cool%3E!');
$t->setGenerationTime(523);
self::checkResponse($t->doTrackPageView('incredible title! <>,;'));
$t->setUrl('http://example.org/dir/file.php?foo=bar&foo2=bar');
$t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.2)->getDatetime());
$t->setGenerationTime(123);
self::checkResponse($t->doTrackPageView('incredible title! <>,;'));
$t->setUrl('http://example.org/dir/file.php?foo=bar&foo2=bar2');
$t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.3)->getDatetime());
$t->setGenerationTime(153);
self::checkResponse($t->doTrackPageView('incredible parent title! <>,; / subtitle <>,;'));
$t->setUrl('http://example.org/dir/file.php?foo=bar&foo2=bar2');
$t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.31)->getDatetime());
$t->setGenerationTime(153);
self::checkResponse($t->doTrackEvent('Category', 'Action', 'Name', 11111));
$t->setUrl('http://example.org/dir2/file.php?foo=bar&foo2=bar');
$t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.4)->getDatetime());
$t->setGenerationTime(1233);
self::checkResponse($t->doTrackPageView('incredible title! <>,;'));
$t->setUrl('http://example.org/dir2/sub/0/file.php');
$t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.4)->getDatetime());
// Very high Generation time should be ignored
$t->setGenerationTime(6350000);
self::checkResponse($t->doTrackPageView('incredible title! <>,;'));
$t->setUrl('http://example.org/0');
$t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.4)->getDatetime());
$t->setGenerationTime(635);
self::checkResponse($t->doTrackPageView('I am URL zero!'));
}
示例11: purgeOutdatedArchives
/**
* @return bool `true` if the purge was executed, `false` if it was skipped.
* @throws \Exception
*/
public function purgeOutdatedArchives()
{
if ($this->willPurgingCausePotentialProblemInUI()) {
$this->logger->info("Purging temporary archives: skipped (browser triggered archiving not enabled & not running after core:archive)");
return false;
}
$archiveTables = ArchiveTableCreator::getTablesArchivesInstalled();
$this->logger->info("Purging archives in {tableCount} archive tables.", array('tableCount' => count($archiveTables)));
// keep track of dates we purge for, since getTablesArchivesInstalled() will return numeric & blob
// tables (so dates will appear two times, and we should only purge once per date)
$datesPurged = array();
foreach ($archiveTables as $table) {
$date = ArchiveTableCreator::getDateFromTableName($table);
list($year, $month) = explode('_', $date);
// Somehow we may have archive tables created with older dates, prevent exception from being thrown
if ($year > 1990) {
if (empty($datesPurged[$date])) {
$dateObj = Date::factory("{$year}-{$month}-15");
$this->archivePurger->purgeOutdatedArchives($dateObj);
$this->archivePurger->purgeArchivesWithPeriodRange($dateObj);
$datesPurged[$date] = true;
} else {
$this->logger->debug("Date {date} already purged.", array('date' => $date));
}
} else {
$this->logger->info("Skipping purging of archive tables *_{year}_{month}, year <= 1990.", array('year' => $year, 'month' => $month));
}
}
return true;
}
示例12: setUp
public function setUp()
{
// add one thousand sites
$allIdSites = array();
for ($i = 0; $i < 1000; ++$i) {
$allIdSites[] = Fixture::createWebsite($this->date, $ecommerce = 1, $siteName = "Site #{$i}");
}
$urls = array();
for ($i = 0; $i != 3; ++$i) {
$url = "http://whatever.com/" . ($i - 1) . "/" . ($i + 1);
$title = "page view " . ($i - 1) . " / " . ($i + 1);
$urls[$url] = $title;
}
$visitTimes = array();
$date = Date::factory($this->date);
for ($i = 0; $i != 4; ++$i) {
$visitTimes[] = $date->addHour($i)->getDatetime();
}
// add 12000 visits (3 visitors with 4 visits each for each site) w/ 3 pageviews each on one day
foreach ($visitTimes as $visitTime) {
foreach ($allIdSites as $idSite) {
for ($visitor = 0; $visitor != 3; ++$visitor) {
$t = BenchmarkTestCase::getLocalTracker($idSite);
$ip = "157.5.6." . ($visitor + 1);
$t->setIp($ip);
$t->setNewVisitorId();
$t->setForceVisitDateTime($visitTime);
foreach ($urls as $url => $title) {
$t->setUrl($url);
$t->doTrackPageView($title);
}
}
}
}
}
示例13: addAnnotations
private function addAnnotations()
{
// create fake access for fake username
$access = new FakeAccess();
FakeAccess::$superUser = true;
Access::setSingletonInstance($access);
// add two annotations per week for three months, starring every third annotation
// first month in 2011, second two in 2012
$count = 0;
$dateStart = Date::factory('2011-12-01');
$dateEnd = Date::factory('2012-03-01');
while ($dateStart->getTimestamp() < $dateEnd->getTimestamp()) {
$starred = $count % 3 == 0 ? 1 : 0;
$site1Text = "{$count}: Site 1 annotation for " . $dateStart->toString();
$site2Text = "{$count}: Site 2 annotation for " . $dateStart->toString();
API::getInstance()->add($this->idSite1, $dateStart->toString(), $site1Text, $starred);
API::getInstance()->add($this->idSite2, $dateStart->toString(), $site2Text, $starred);
$nextDay = $dateStart->addDay(1);
++$count;
$starred = $count % 3 == 0 ? 1 : 0;
$site1Text = "{$count}: Site 1 annotation for " . $nextDay->toString();
$site2Text = "{$count}: Site 2 annotation for " . $nextDay->toString();
API::getInstance()->add($this->idSite1, $nextDay->toString(), $site1Text, $starred);
API::getInstance()->add($this->idSite2, $nextDay->toString(), $site2Text, $starred);
$dateStart = $dateStart->addPeriod(1, 'WEEK');
++$count;
}
}
示例14: trackVisits
private function trackVisits()
{
$dateTime = $this->dateTime;
$idSite = $this->idSite;
for ($referrerSite = 1; $referrerSite < 4; $referrerSite++) {
for ($referrerPage = 1; $referrerPage < 3; $referrerPage++) {
$offset = $referrerSite * 3 + $referrerPage;
$t = self::getTracker($idSite, Date::factory($dateTime)->addHour($offset)->getDatetime());
$t->setUrlReferrer('http://www.referrer' . $referrerSite . '.com/sub/dir/page' . $referrerPage . '.html');
$t->setCustomVariable(1, 'CustomVarVisit', 'CustomVarValue' . $referrerPage, 'visit');
for ($page = 0; $page < 3; $page++) {
$t->setUrl('http://example.org/dir' . $referrerSite . '/sub/dir/page' . $page . '.html');
$t->setCustomVariable(1, 'CustomVarPage', 'CustomVarValue' . $page, 'page');
$t->setGenerationTime($referrerPage * $referrerSite * ($page + 1) * 100);
self::checkResponse($t->doTrackPageView('title'));
}
}
}
$t = self::getTracker($idSite, Date::factory($dateTime)->addHour(24)->getDatetime());
$t->setCustomVariable(1, 'CustomVarVisit', 'CustomVarValue1', 'visit');
$t->setUrl('http://example.org/sub/dir/dir1/page1.html');
$t->setCustomVariable(1, 'CustomVarPage', 'CustomVarValue1', 'page');
self::checkResponse($t->doTrackPageView('title'));
$t = self::getTracker($idSite, Date::factory($dateTime)->addHour(24)->getDatetime());
$t->setUrl('http://example.org/page1.html');
self::checkResponse($t->doTrackPageView('title'));
}
示例15: trackVisits
private function trackVisits()
{
$dateTime = $this->dateTime;
$idSite = $this->idSite;
// two visits to site 1 & 3
$visitor1 = self::getTracker($idSite, $dateTime, $defaultInit = true);
$visitor1->setForceVisitDateTime(Date::factory($this->dateTime)->getDatetime());
$visitor1->setUrl('http://helios.org/alpha');
$visitor1->doTrackPageView("page title");
$visitor1->setIdSite($this->idSite2);
$visitor1->setForceVisitDateTime(Date::factory($this->dateTime)->addHour(1)->getDatetime());
$visitor1->setUrl('http://taura.org/');
$visitor1->doTrackPageView("page title");
// one visit to site 1
$visitor2 = self::getTracker($idSite, $dateTime, $defaultInit = true);
$visitor2->setForceVisitDateTime(Date::factory($this->dateTime)->addHour(2)->getDatetime());
$visitor2->setUrl('http://helios.org/beta');
$visitor2->doTrackPageView("page title 2");
// two visits to site 2 and 3
$visitor3 = self::getTracker($this->idSite1, $dateTime, $defaultInit = true);
$visitor3->setForceVisitDateTime(Date::factory($this->dateTime)->addHour(3)->getDatetime());
$visitor3->setUrl('http://virgon.org/');
$visitor3->doTrackPageView("page title 2");
$visitor3->setIdSite($this->idSite2);
$visitor3->setForceVisitDateTime(Date::factory($this->dateTime)->addHour(4)->getDatetime());
$visitor3->setUrl('http://taura.org/');
$visitor3->doTrackPageView("page title");
}