Source of file DashboardPage.php
Size: 4,789 Bytes - Last Modified: 2021-12-23T10:31:31+00:00
/var/www/docs.ssmods.com/process/src/code/dataobjects/DashboardPage.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 | <?php /** * A dashboard page is a url identifiable dashboard in the system that a user can * customise to their whim. This is NOT inherited from SS's SiteTree/Page, * but is a standalone type. * * These are accessed in the context of a DashboardController; that dashboard can be the controller * to a SilverStripe Page object, but doesn't need to be (ie this can * operate via direct controller requests). * * @author marcus@silverstripe.com.au * @license BSD License http://silverstripe.org/bsd-license/ */ class DashboardPage extends DataObject { private static $layouts = array( 'dynamic' => 'Dynamic', '2colLW' => 'Two Columns - Left Wide', '2colRW' => 'Two Columns - Right Wide', '3col' => 'Three Columns' ); private static $default_layout = 'dynamic'; public static $max_dashboards = 3; private static $db = array( 'Title' => 'Varchar(128)', 'URLSegment' => 'Varchar(64)', 'Layout' => 'Varchar(15)', 'IsLocked' => 'Boolean', ); private static $defaults = array( 'ColumnLayout' => 'dynamic' ); private static $has_many = array( 'Dashboards' => 'MemberDashboard', ); private static $extensions = array( 'Restrictable', ); private static $summary_fields = array( 'Title', 'Owner.Email', ); private $controller; public function getController() { return $this->controller; } /** * @param type $controller */ public function setController($controller) { $this->controller = $controller; } public function __construct($record = null, $isSingleton = false, $model = null) { parent::__construct($record, $isSingleton, $model); } public function getDashboard($index) { $dashboards = $this->Dashboards(); if (!$dashboards->count()) { $dashboards = $this->createDefaultBoards(); } $board = $dashboards->offsetGet($index); if ($board) { $board->parent = $this; } return $board; } public function onBeforeWrite() { parent::onBeforeWrite(); if ($this->isChanged('URLSegment')) { $this->URLSegment = URLSegmentFilter::create()->filter($this->URLSegment); } if (!$this->URLSegment) { $this->URLSegment = URLSegmentFilter::create()->filter($this->Title); } if (!$this->URLSegment) { $this->URLSegment = 'main'; } } public function onAfterWrite() { parent::onAfterWrite(); $dashboards = $this->Dashboards(); if (!$dashboards->Count()) { $this->createDefaultBoards(); } } public function onBeforeDelete() { parent::onBeforeDelete(); $dashboards = $this->Dashboards(); if ($dashboards->count()) { foreach ($dashboards as $board) { $board->delete(); } } } protected function createDefaultBoards() { $i = 0; $boards = ArrayList::create(); while ($i < self::$max_dashboards) { $area = MemberDashboard::create(); $area->DashboardID = $this->ID; $area->write(); $boards->push($area); $i++; } return $boards; } public function getFrontEndFields($params = null) { $fields = parent::getFrontEndFields($params); $fields->replaceField('Layout', $dd = DropdownField::create('Layout', null, $this->config()->layouts)); $dd->setHasEmptyDefault(true); $fields->removeByName('InheritPerms'); $fields->removeByName('OwnerID'); // $fields->removeByName('PublicAccess'); return $fields; } public function forTemplate() { if ($this->Layout) { $layout = $this->Layout; } else { $layout = $this->config()->default_layout; } return $this->renderWith("DashboardPage_$layout"); } public function DashboardLayout() { return $this->Layout ? $this->Layout : $this->config()->default_layout; } public function Link($action='') { $identifier = Member::get_unique_identifier_field(); $identifier = $this->Owner()->$identifier; if ($this->controller) { return Controller::join_links($this->controller->Link(), 'user', $identifier, $this->URLSegment, $action); } return Controller::join_links(Director::baseURL(), 'dashboard', 'user', $identifier, $this->URLSegment, $action); } } |