示例#1
0
 /**
  * Queries archive tables for data and returns the result.
  * @param array|string $archiveNames
  * @param $archiveDataType
  * @param null|int $idSubtable
  * @return Archive\DataCollection
  */
 private function get($archiveNames, $archiveDataType, $idSubtable = null)
 {
     if (!is_array($archiveNames)) {
         $archiveNames = array($archiveNames);
     }
     // apply idSubtable
     if ($idSubtable !== null && $idSubtable != self::ID_SUBTABLE_LOAD_ALL_SUBTABLES) {
         foreach ($archiveNames as &$name) {
             $name = $this->appendIdsubtable($name, $idSubtable);
         }
     }
     $result = new Archive\DataCollection($archiveNames, $archiveDataType, $this->params->getIdSites(), $this->params->getPeriods(), $defaultRow = null);
     $archiveIds = $this->getArchiveIds($archiveNames);
     if (empty($archiveIds)) {
         return $result;
     }
     $loadAllSubtables = $idSubtable == self::ID_SUBTABLE_LOAD_ALL_SUBTABLES;
     $archiveData = ArchiveSelector::getArchiveData($archiveIds, $archiveNames, $archiveDataType, $loadAllSubtables);
     foreach ($archiveData as $row) {
         // values are grouped by idsite (site ID), date1-date2 (date range), then name (field name)
         $idSite = $row['idsite'];
         $periodStr = $row['date1'] . "," . $row['date2'];
         if ($archiveDataType == 'numeric') {
             $value = $this->formatNumericValue($row['value']);
         } else {
             $value = $this->uncompress($row['value']);
             $result->addMetadata($idSite, $periodStr, 'ts_archived', $row['ts_archived']);
         }
         $resultRow =& $result->get($idSite, $periodStr);
         $resultRow[$row['name']] = $value;
     }
     return $result;
 }
示例#2
0
 private function assertArchiveBlob(PiwikArchive\DataCollection $dataCollection, $date, $expectedBlob)
 {
     $dateIndex = $date . ',' . $date;
     $dataArrays = $dataCollection->get(1, $dateIndex);
     if (!empty($expectedBlob) && 0 !== reset($expectedBlob)) {
         $this->assertNotEmpty($dataArrays['_metadata']['ts_archived']);
         $dataArrays['_metadata']['ts_archived'] = true;
         unset($dataArrays['_metadata']);
     }
     $this->assertEquals($expectedBlob, $dataArrays);
 }