Example #1
0
 public static function getInstance()
 {
     if (self::$instance == null) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Example #2
0
 public static function getInstance()
 {
     if (self::$instance == null) {
         $c = __CLASS__;
         self::$instance = new $c();
     }
     return self::$instance;
 }
Example #3
0
 private function addReportData()
 {
     $archive = Piwik_Archive::build($this->idSite, 'year', $this->dateTime);
     $archive->getNumeric('nb_visits', 'nb_hits');
     Piwik_VisitorInterest_API::getInstance()->getNumberOfVisitsPerVisitDuration($this->idSite, 'year', $this->dateTime);
     // months are added via the 'year' period, but weeks must be done manually
     for ($daysAgo = $this->daysAgoStart; $daysAgo > 0; $daysAgo -= 7) {
         $dateTime = $this->dateTime->subDay($daysAgo);
         $archive = Piwik_Archive::build($this->idSite, 'week', $dateTime);
         $archive->getNumeric('nb_visits');
         Piwik_VisitorInterest_API::getInstance()->getNumberOfVisitsPerVisitDuration($this->idSite, 'week', $dateTime);
     }
     // add segment for one day
     $archive = Piwik_Archive::build($this->idSite, 'day', '2012-01-14', 'browserName==FF');
     $archive->getNumeric('nb_visits', 'nb_hits');
     Piwik_VisitorInterest_API::getInstance()->getNumberOfVisitsPerVisitDuration($this->idSite, 'day', '2012-01-14', 'browserName==FF');
     // add range within January
     $rangeEnd = Piwik_Date::factory('2012-01-29');
     $rangeStart = $rangeEnd->subDay(1);
     $range = $rangeStart->toString('Y-m-d') . "," . $rangeEnd->toString('Y-m-d');
     $rangeArchive = Piwik_Archive::build($this->idSite, 'range', $range);
     $rangeArchive->getNumeric('nb_visits', 'nb_hits');
     Piwik_VisitorInterest_API::getInstance()->getNumberOfVisitsPerVisitDuration($this->idSite, 'range', $range);
     // add range between January & February
     $rangeStart = $rangeEnd;
     $rangeEnd = $rangeStart->addDay(3);
     $range = $rangeStart->toString('Y-m-d') . "," . $rangeEnd->toString('Y-m-d');
     $rangeArchive = Piwik_Archive::build($this->idSite, 'range', $range);
     $rangeArchive->getNumeric('nb_visits', 'nb_hits');
     Piwik_VisitorInterest_API::getInstance()->getNumberOfVisitsPerVisitDuration($this->idSite, 'range', $range);
     // when archiving is initiated, the archive metrics & reports for EVERY loaded plugin
     // are archived. don't want this test to depend on every possible metric, so get rid of
     // the unwanted archive data now.
     $metricsToSave = array('nb_visits', 'nb_actions', Piwik_Goals::getRecordName('revenue'), Piwik_Goals::getRecordName('nb_conversions', 1), Piwik_Goals::getRecordName('revenue', Piwik_Tracker_GoalManager::IDGOAL_ORDER));
     $archiveTables = $this->getArchiveTableNames();
     foreach ($archiveTables['numeric'] as $table) {
         $realTable = Piwik_Common::prefixTable($table);
         Piwik_Query("DELETE FROM {$realTable} WHERE name NOT IN ('" . implode("','", $metricsToSave) . "') AND name NOT LIKE 'done%'");
     }
     foreach ($archiveTables['blob'] as $table) {
         $realTable = Piwik_Common::prefixTable($table);
         Piwik_Query("DELETE FROM {$realTable} WHERE name NOT IN ('VisitorInterest_timeGap')");
     }
     // add garbage metrics
     $janDate1 = '2012-01-05';
     $febDate1 = '2012-02-04';
     $sql = "INSERT INTO %s (idarchive,name,idsite,date1,date2,period,ts_archived,value)\n\t\t                VALUES (10000,?,1,?,?,?,?,?)";
     // one metric for jan & one for feb
     Piwik_Query(sprintf($sql, Piwik_Common::prefixTable($archiveTables['numeric'][0])), array(self::GARBAGE_FIELD, $janDate1, $janDate1, $janDate1, 1, 100));
     Piwik_Query(sprintf($sql, Piwik_Common::prefixTable($archiveTables['numeric'][1])), array(self::GARBAGE_FIELD, $febDate1, $febDate1, $febDate1, 1, 200));
     // add garbage reports
     Piwik_Query(sprintf($sql, Piwik_Common::prefixTable($archiveTables['blob'][0])), array(self::GARBAGE_FIELD, $janDate1, $janDate1, $janDate1, 10, 'blobval'));
     Piwik_Query(sprintf($sql, Piwik_Common::prefixTable($archiveTables['blob'][1])), array(self::GARBAGE_FIELD, $febDate1, $febDate1, $febDate1, 20, 'blobval'));
 }