/** * Merge in dashboard list into runtime configuration. * * {@inheritdoc} */ public function merge(array $currentConfig) { /** @var User $user */ $user = $this->tokenStorage->getToken()->getUser(); $defaultDashboardNames = []; foreach ($this->dashboardMgr->getDefaultDashboards($user) as $dashboard) { $defaultDashboardNames[] = $dashboard->getName(); } $isDefaultFound = false; $result = array(); foreach ($this->dashboardMgr->getUserDashboards($user) as $dashboard) { if (!$dashboard->isAllowed($this->container)) { continue; } $isDefault = in_array($dashboard->getName(), $defaultDashboardNames); if ($isDefault) { $isDefaultFound = true; } $result[] = array_merge($this->serializeDashboard($dashboard), array('default' => $isDefault)); } if (!$isDefaultFound) { // if there's no default dashboard available for a given user then we will display a dashboard // where user will be able to pick one he/she needs $dashboard = new SimpleDashboard('default', 'List of user dashboards', 'Modera.backend.dashboard.runtime.DashboardListDashboardActivity'); $result[] = array_merge($this->serializeDashboard($dashboard), array('default' => true)); } return array_merge($currentConfig, array('modera_backend_dashboard' => array('dashboards' => $result))); }
public function testGetDashboards() { $em = \Phake::mock(EntityManager::class); $dashboards = [$this->createDashboard('foo'), $this->createDashboard('bar')]; $provider = \Phake::mock(ContributorInterface::class); \Phake::when($provider)->getItems()->thenReturn($dashboards); $mgr = new DashboardManager($em, $provider); $returnedDashboards = $mgr->getDashboards(); $this->assertEquals(2, count($dashboards)); $this->assertSame($dashboards[0], $returnedDashboards[0]); $this->assertSame($dashboards[1], $returnedDashboards[1]); }