Version: current

     1 <?php
     2
     3 /**
     4  * Базовый класс webylon для областей виджетов
     5  *
     6  * @package widgets
     7  * @author  menedem
     8  */
     9 class WebylonWidgetArea extends WidgetArea {
    10
    11     static $db = array(
    12         'TechName' => 'Varchar(100)', // техническое имя - должно быть уникально в пределах одного ParentID
    13         'Sort' => 'Int', // так проще потом выводить
    14         'Active' => 'Boolean', // возможность скрытия областей
    15     );
    16
    17     static $has_one = array(
    18         'Parent' => 'SiteTree',
    19         'SiteConfig' => 'SiteConfig',
    20     );
    21
    22     static $widgetClass = 'WebylonWidget';
    23
    24     static $default_sort = 'Sort';
    25
    26     public $template = __CLASS__;
    27
    28     function getTitle() {
    29         return _t('WebylonWidgetArea', 'Title_' . $this->TechName, $this->TechName);
    30     }
    31
    32     function ActiveWidgets() {
    33         $widgets = DataObject::get(self::$widgetClass, "ParentID={$this->ID} AND Enabled=1");
    34         if ($widgets) {
    35             foreach($widgets as $widget) {
    36                 if (!$widget->canCreate() || !$widget->hasContent()) {
    37                     $widgets->remove($widget);
    38                 }
    39             }
    40         }
    41         return $widgets;
    42     }
    43
    44     function forTemplate() {
    45         return $this->renderWith($this->getTemplates());
    46     }
    47
    48     function getTemplates() {
    49         $templates = array();
    50         $class = $this->ClassName;
    51
    52         while ($class) {
    53             $templates[] = "{$class}_{$this->TechName}";
    54             $templates[] = $class;
    55             if ($class == 'WidgetArea') {
    56                 break;
    57             }
    58             $class = get_parent_class($class);
    59         }
    60         return $templates;
    61     }
    62 }

[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. -