Version: current

     1 <?php
     2 // Виджет Календарь для Sidebar - пока не ясно, какие параметры
     3 class EventCalendarWidget extends SidebarWidget {
     4
     5     static $has_one = array(
     6         'Holder' => 'EventHolder'
     7     );
     8
     9     public $needObjects = array(
    10         'EventHolder' => 'Page'
    11     );
    12
    13     function getCMSFields() {
    14         if (!$this->canCreate()) {
    15             return $this->getFailCMSFields();
    16         }
    17
    18         $fields = parent::getCMSFields();
    19         $holders = DataObject::get('EventHolder');
    20         if ($holders) {
    21             $holders = $holders->map();
    22         } else {
    23             $holders = array();
    24         }
    25         $fields->addFieldToTab('Root.Main', new DropdownField("HolderID", $this->fieldLabel('Holder'), $holders, "", null, _t('Widgets.All', 'All')));
    26         return $fields;
    27     }
    28
    29     function Calendar() {
    30         if ($this->HolderID && $this->Holder()) {
    31             $holder = $this->Holder();
    32         } else {
    33             $holder = DataObject::get_one('EventHolder');
    34         }
    35         if ($holder) {
    36             $calendar = $holder->getCalendar('');
    37             return $calendar->renderWith('EventCalendarWidget');
    38         }
    39         return false;
    40     }
    41
    42     function hasContent() {
    43         if ($this->Calendar()) {
    44             return true;
    45         }
    46         return false;
    47     }
    48
    49     function getMoreLink() {
    50         if ($this->HolderID && $this->Holder()) {
    51             return $this->Holder()->Link();
    52         }
    53         if ($holder = DataObject::get_one('EventHolder')) {
    54             return $holder->Link();
    55         }
    56         return false;
    57     }
    58 }
    59
    60

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -