Piwik\Plugins\MultiSites\Dashboard::moveSitesHavingAGroupIntoSubtables PHP Method

moveSitesHavingAGroupIntoSubtables() private method

private moveSitesHavingAGroupIntoSubtables ( DataTable $sites )
$sites Piwik\DataTable
    private function moveSitesHavingAGroupIntoSubtables(DataTable $sites)
    {
        /** @var DataTableSummaryRow[] $groups */
        $groups = array();
        $sitesByGroup = $this->makeCloneOfDataTableSites($sites);
        $sitesByGroup->enableRecursiveFilters();
        // we need to make sure filters get applied to subtables (groups)
        foreach ($sites->getRows() as $site) {
            $group = $site->getMetadata('group');
            if (!empty($group) && !array_key_exists($group, $groups)) {
                $row = new DataTableSummaryRow();
                $row->setColumn('label', $group);
                $row->setMetadata('isGroup', 1);
                $row->setSubtable($this->createGroupSubtable($sites));
                $sitesByGroup->addRow($row);
                $groups[$group] = $row;
            }
            if (!empty($group)) {
                $groups[$group]->getSubtable()->addRow($site);
            } else {
                $sitesByGroup->addRow($site);
            }
        }
        foreach ($groups as $group) {
            // we need to recalculate as long as all rows are there, as soon as some rows are removed
            // we can no longer recalculate the correct value. We might even calculate values for groups
            // that are not returned. If this becomes a problem we need to keep a copy of this to recalculate
            // only actual returned groups.
            $group->recalculate();
        }
        return $sitesByGroup;
    }