/** * Custom logic code here for setting placeholders, etc * @param array $scriptProperties * @return array */ public function process(array $scriptProperties = array()) { $placeholders = array(); $this->checkForWelcomeScreen(); $this->dashboard = $this->modx->user->getDashboard(); $placeholders['dashboard'] = $this->dashboard->render($this); return $placeholders; }
/** * Get all the User Groups assigned to this Dashboard * @return array */ public function getUserGroups() { $c = $this->modx->newQuery('modUserGroup'); $c->where(array('dashboard' => $this->dashboard->get('id'))); $c->sortby('name', 'ASC'); $usergroups = $this->modx->getCollection('modUserGroup', $c); $list = array(); /** @var modUserGroup $usergroup */ foreach ($usergroups as $usergroup) { $list[] = array($usergroup->get('id'), $usergroup->get('name')); } return $list; }
/** * Ensure the rendering of the dashboard works properly */ public function testRender() { /** @var modManagerController $controller Fake running the welcome controller */ $controller = new WelcomeManagerController($this->modx, array('namespace' => 'core', 'namespace_name' => 'core', 'namespace_path' => MODX_MANAGER_PATH, 'lang_topics' => 'dashboards', 'controller' => 'system/dashboards')); /** @var modDashboard $dashboard */ $dashboard = modDashboard::getDefaultDashboard($this->modx); $output = $dashboard->render($controller); $this->assertNotEmpty($output); }
/** * Get the active Dashboard for the User * @return modDashboard|null */ public function getDashboard() { $this->modx->loadClass('modDashboard'); /** @var modUserGroup $userGroup */ $userGroup = $this->modx->user->getOne('PrimaryGroup'); if ($userGroup) { /** @var modDashboard $dashboard */ $dashboard = $userGroup->getOne('Dashboard'); if (empty($dashboard)) { $dashboard = modDashboard::getDefaultDashboard($this->modx); } } else { $dashboard = modDashboard::getDefaultDashboard($this->modx); } return $dashboard; }
/** * Override xPDOObject::remove() to revert to the default dashboard any user groups using this Dashboard * * @see xPDOObject::remove() * @param array $ancestors * @return boolean */ public function remove(array $ancestors = array()) { $dashboardId = $this->get('id'); $removed = parent::remove($ancestors); if ($removed) { $defaultDashboard = modDashboard::getDefaultDashboard($this->xpdo); if (empty($defaultDashboard)) { /** @var modDashboard $defaultDashboard */ $defaultDashboard = $this->xpdo->newObject('modDashboard'); $defaultDashboard->set('id', 0); } $userGroups = $this->xpdo->getCollection('modUserGroup', array('dashboard' => $dashboardId)); /** @var modUserGroup $userGroup */ foreach ($userGroups as $userGroup) { $userGroup->set('dashboard', $defaultDashboard->get('id')); $userGroup->save(); } } return $removed; }