diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2015-03-12 06:38:05 +0300 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2015-03-12 06:38:05 +0300 |
commit | 0e46ad7299d9f69b0ff57cfa7c3b9a6f59789495 (patch) | |
tree | f6d457a952c3d16a4b40cea0af6a91bda0f6d7c3 /plugins | |
parent | 2a1dcbd35ec0fd8dd8a384fe00671bf37ec7fd3e (diff) |
extracted expanding table into a method
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Referrers/API.php | 69 |
1 files changed, 42 insertions, 27 deletions
diff --git a/plugins/Referrers/API.php b/plugins/Referrers/API.php index bba6ca37af..2cacbb2833 100644 --- a/plugins/Referrers/API.php +++ b/plugins/Referrers/API.php @@ -324,33 +324,7 @@ class API extends \Piwik\Plugin\API $this->removeSubtableMetadata($dataTable); if ($flat) { - $urlsTable = Archive::createDataTableFromArchive(Archiver::WEBSITES_RECORD_NAME, $idSite, $period, $date, $segment, $expanded, $flat); - $urlsTable->filter('ColumnCallbackDeleteRow', array('label', function ($url) { return !isSocialUrl($url); })); - $urlsTable = $urlsTable->mergeSubtables(); - - foreach ($dataTable->getRows() as $row) { - $row->removeSubtable(); - - $social = $row->getColumn('label'); - $newTable = $urlsTable->getEmptyClone(); - - $rows = $urlsTable->getRows(); - foreach ($rows as $id => $urlsTableRow) { - $url = $urlsTableRow->getColumn('label'); - if (isSocialUrl($url, $social)) { - $newTable->addRow($urlsTableRow); - $urlsTable->deleteRow($id); - } - } - - if ($newTable->getRowsCount()) { - $newTable->filter('Piwik\Plugins\Referrers\DataTable\Filter\UrlsForSocial', array($expanded)); - $row->setSubtable($newTable); - } - } - - Common::destroy($urlsTable); - $urlsTable = null; + $this->buildExpandedTableForFlattenGetSocials($idSite, $period, $date, $segment, $expanded, $dataTable); } $dataTable->queueFilter('MetadataCallbackAddMetadata', array('url', 'logo', __NAMESPACE__ . '\getSocialsLogoFromUrl')); @@ -551,4 +525,45 @@ class API extends \Piwik\Plugin\API } } + /** + * @param int $idSite + * @param string $period + * @param string $date + * @param string|false $segment + * @param bool $expanded + * @param DataTable $dataTable + */ + private function buildExpandedTableForFlattenGetSocials($idSite, $period, $date, $segment, $expanded, $dataTable) + { + $urlsTable = Archive::createDataTableFromArchive(Archiver::WEBSITES_RECORD_NAME, $idSite, $period, $date, $segment, $expanded, $flat = true); + $urlsTable->filter('ColumnCallbackDeleteRow', array('label', function ($url) { + return !isSocialUrl($url); + })); + $urlsTable = $urlsTable->mergeSubtables(); + + foreach ($dataTable->getRows() as $row) { + $row->removeSubtable(); + + $social = $row->getColumn('label'); + $newTable = $urlsTable->getEmptyClone(); + + $rows = $urlsTable->getRows(); + foreach ($rows as $id => $urlsTableRow) { + $url = $urlsTableRow->getColumn('label'); + if (isSocialUrl($url, $social)) { + $newTable->addRow($urlsTableRow); + $urlsTable->deleteRow($id); + } + } + + if ($newTable->getRowsCount()) { + $newTable->filter('Piwik\Plugins\Referrers\DataTable\Filter\UrlsForSocial', array($expanded)); + $row->setSubtable($newTable); + } + } + + Common::destroy($urlsTable); + $urlsTable = null; + } + } |