public function actionPushDashboard($id)
 {
     $dashboard = Dashboard::getById(intval($id));
     $modelClassName = get_class($dashboard);
     if (isset($_POST[$modelClassName])) {
         $groupsAndUsers = PushDashboardUtil::resolveGroupsAndUsersFromPost($_POST[$modelClassName]);
         PushDashboardUtil::pushDashboardToUsers($dashboard, $groupsAndUsers);
         Yii::app()->user->setFlash('notification', Zurmo::t('HomeModule', 'Dashboard pushed successfully'));
         $this->redirect(array('default/dashboardDetails', 'id' => $dashboard->id));
     }
     $editView = new PushDashboardEditView($this->getId(), $this->getModule()->getId(), $dashboard, Zurmo::t('HomeModule', 'Push Dashboard'));
     $view = new HomePageView(ZurmoDefaultViewUtil::makeStandardViewForCurrentUser($this, $editView));
     echo $view->render();
 }
 public function testPushDashboardToUsers()
 {
     $super = Yii::app()->user->userModel;
     //Make and Get Five Users
     $users = UserTestHelper::generateBasicUsers(5);
     $this->assertEquals(5, count($users));
     //Remove any one portlet from super's default dashboard
     $defaultDashboards = Dashboard::getDefaultDashboardsByUser($super);
     if (count($defaultDashboards) == 0) {
         $defaultDashboard = Dashboard::setDefaultDashboardForUser($super);
     } else {
         $defaultDashboard = $defaultDashboards[0];
     }
     $defaultDashboardLayoutId = PushDashboardUtil::HOME_DASHBOARD . $defaultDashboard->layoutId;
     $defaultPortlets = Portlet::getByLayoutIdAndUserSortedById($defaultDashboardLayoutId, $super->id);
     if (empty($defaultPortlets)) {
         $metadata = HomeDashboardView::getDefaultMetadata();
         $portletCollection = Portlet::makePortletsUsingMetadataSortedByColumnIdAndPosition($defaultDashboardLayoutId, $metadata, $super, null);
         $this->assertNotEmpty($portletCollection);
         Portlet::savePortlets($portletCollection);
         $defaultPortlets = Portlet::getByLayoutIdAndUserSortedById($defaultDashboardLayoutId, $super->id);
     }
     $this->assertTrue(count($defaultPortlets) > 0);
     foreach ($defaultPortlets as $portlet) {
         $portlet->delete();
         break;
     }
     $defaultPortlets = Portlet::getByLayoutIdAndUserSortedById($defaultDashboardLayoutId, $super->id);
     $deafultPortletViews = array();
     foreach ($defaultPortlets as $portlet) {
         $deafultPortletViews[] = $portlet->viewType;
     }
     //Push super's default dashboard to five users
     $userIds = array();
     foreach ($users as $user) {
         $userIds[] = $user->id;
     }
     $groupsAndUsers = array();
     $groupsAndUsers['groups'] = array();
     $groupsAndUsers['users'] = $userIds;
     PushDashboardUtil::pushDashboardToUsers($defaultDashboard, $groupsAndUsers);
     //Validate and compare portlets of five user's dashboard with super's default dashboard
     foreach ($users as $user) {
         $userPortlets = Portlet::getByLayoutIdAndUserSortedById($defaultDashboardLayoutId, $user->id);
         $this->assertEquals(count($defaultPortlets), count($userPortlets));
         foreach ($userPortlets as $portlet) {
             $this->assertTrue(in_array($portlet->viewType, $deafultPortletViews));
         }
     }
 }