예제 #1
0
 /**
  * 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)));
 }
예제 #2
0
 public function testGetDefaultDashboards()
 {
     $dashboards = [$this->createDashboard('foo'), $this->createDashboard('bar')];
     $provider = \Phake::mock(ContributorInterface::class);
     \Phake::when($provider)->getItems()->thenReturn($dashboards);
     $group1 = \Phake::mock(Group::class);
     $user = \Phake::mock(User::class);
     \Phake::when($user)->getGroups()->thenReturn([$group1]);
     $userSettings = \Phake::mock(UserSettings::class);
     \Phake::when($userSettings)->getDashboardSettings()->thenReturn(array('defaultDashboard' => 'foo'));
     $groupSettings1 = \Phake::mock(GroupSettings::class);
     \Phake::when($groupSettings1)->getDashboardSettings()->thenReturn(array('defaultDashboard' => 'bar'));
     $userSettingsRepository = \Phake::mock(EntityRepository::class);
     \Phake::when($userSettingsRepository)->findOneBy(array('user' => $user))->thenReturn($userSettings);
     $groupSettingsRepository = \Phake::mock(GroupRepository::class);
     \Phake::when($groupSettingsRepository)->findOneBy(array('group' => $group1))->thenReturn($groupSettings1);
     $em = \Phake::mock(EntityManager::class);
     \Phake::when($em)->getRepository(UserSettings::class)->thenReturn($userSettingsRepository);
     \Phake::when($em)->getRepository(GroupSettings::class)->thenReturn($groupSettingsRepository);
     // ---
     $mgr = new DashboardManager($em, $provider);
     $indexedUserDashboards = array();
     foreach ($mgr->getDefaultDashboards($user) as $dashboard) {
         $indexedUserDashboards[$dashboard->getName()] = $dashboard;
     }
     $this->assertEquals(2, count($indexedUserDashboards));
     $this->assertSame($dashboards[0], $indexedUserDashboards['foo']);
     $this->assertSame($dashboards[1], $indexedUserDashboards['bar']);
 }