public function createDashboard($name, $createDefault = false)
 {
     $url = preg_replace('/ +/', '-', trim($name));
     // Replace any spaces
     $url = preg_replace('/[^A-Za-z0-9.+_\\-]/', '', $url);
     // Replace non alphanumeric characters
     $url = strtolower($url);
     $existing = $this->getNamedDashboard($url);
     if ($existing) {
         return $existing;
     }
     $dashboard = new DashboardPage();
     $dashboard->URLSegment = $url;
     $dashboard->Title = trim($name);
     $dashboard->OwnerID = $this->owner->ID;
     $dashboard->write();
     if ($createDefault) {
         $defaults = Config::inst()->get('DashboardUser', 'default_dashlets');
         /* @deprecated Please use the default_layout */
         if (count($defaults)) {
             foreach ($defaults as $dbid => $dashlets) {
                 foreach ($dashlets as $type) {
                     if (class_exists($type)) {
                         $dashlet = new $type();
                         $db = $dashboard->getDashboard($dbid);
                         if ($db && $dashlet->canCreate()) {
                             $dashlet->ParentID = $db->ID;
                             $dashlet->write();
                         }
                     }
                 }
             }
         }
         $layout = Config::inst()->get('DashboardUser', 'default_layout');
         if (count($layout)) {
             foreach ($layout as $type => $properties) {
                 if (class_exists($type)) {
                     $dashlet = new $type();
                     /* @var $dashlet Dashlet */
                     $db = $dashboard->getDashboard(0);
                     if ($db && $dashlet->canCreate()) {
                         $dashlet->ParentID = $db->ID;
                         if (is_array($properties)) {
                             $dashlet->update($properties);
                         }
                         $dashlet->write();
                     }
                 }
             }
         }
         $dashboard = $this->getNamedDashboard($url);
         $this->owner->extend('updateCreatedDashboard', $dashboard);
     }
     return $dashboard;
 }
 public function doAddDashlet($data, $form)
 {
     $classes = $this->getDashletsList();
     $type = $data['DashletClass'];
     if (isset($classes[$type])) {
         $dashlet = $this->injector->create($type);
         if (!$dashlet->canCreate()) {
             throw new PermissionDeniedException('CreateChildren');
         }
         $dashboard = $this->currentDashboard->getDashboard(0);
         $dashboard->addDashlet($dashlet);
     }
     //return $this->redirect($this->currentDashboard->Link());
     return $this->redirectBack();
 }
 public function createDashboard($name, $createDefault = false)
 {
     $url = preg_replace('/ +/', '-', trim($name));
     // Replace any spaces
     $url = preg_replace('/[^A-Za-z0-9.+_\\-]/', '', $url);
     // Replace non alphanumeric characters
     $url = strtolower($url);
     $existing = $this->getNamedDashboard($url);
     if ($existing) {
         return $existing;
     }
     $dashboard = new DashboardPage();
     $dashboard->URLSegment = $url;
     $dashboard->Title = trim($name);
     $dashboard->OwnerID = $this->owner->ID;
     $dashboard->write();
     if ($createDefault) {
         $currentStage = null;
         if (Widget::has_extension('Versioned')) {
             $currentStage = Versioned::current_stage();
             Versioned::reading_stage('Stage');
         }
         $layout = Config::inst()->get('DashboardUser', 'default_layout');
         if (count($layout)) {
             foreach ($layout as $type => $properties) {
                 if (class_exists($type)) {
                     $dashlet = $type::create();
                     /* @var $dashlet Dashlet */
                     $dashletColumn = isset($properties['DashletColumn']) ? $properties['DashletColumn'] : 0;
                     $db = $dashboard->getDashboard($dashletColumn);
                     if ($db && $dashlet->canCreate()) {
                         $dashlet->ParentID = $db->ID;
                         if (is_array($properties)) {
                             $dashlet->update($properties);
                         }
                         $dashlet->write();
                     }
                 }
             }
         }
         if ($currentStage) {
             Versioned::reading_stage($currentStage);
         }
         $dashboard = $this->getNamedDashboard($url);
         $this->owner->extend('updateCreatedDashboard', $dashboard);
     }
     return $dashboard;
 }