Version: current

     1 <?php
     2 /**
     3  * Страница объектоа
     4  * Не отображается в дереве, меню, поиске и на карте сайта.
     5  * Создается в дереве. Редактируется в админке MapObjectGroup.
     6  *
     7  * @author menedem
     8  */
     9 class MapObject extends Page {
    10
    11     static $can_be_root = false;
    12     static $default_parent = "MapObjectGroup";
    13     static $allowed_children = 'none';
    14
    15     static $db = array(
    16         'Address' => 'Varchar(200)',
    17         'Anons' => 'Text',
    18         'ObjectLink' => 'Varchar(200)',
    19         'Latitude' => 'Decimal(10,6)', //Широта
    20         'Longitude' => 'Decimal(10,6)' //Долгота
    21     );
    22
    23     static $has_one = array(
    24         'Image' => 'Image'
    25     );
    26
    27     static $summary_fields = array('Title', 'Address');
    28
    29     static $defaults = array(
    30         'ShowInMenus' => 0,
    31         'ShowInSearch' => 0,
    32         'ShowInSiteMap' => 0,
    33         'ShowOnlyInTab'=> 1,
    34     );
    35
    36     function canCreate($member = null) {
    37         $can = parent::canCreate($member);
    38         if (!SiteConfig::current_site_config()->isNeedMapApiKey()) {
    39             $can = false;
    40         }
    41         return $can;
    42     }
    43
    44     function Link() {
    45         if ($this->ObjectLink) {
    46             return $this->ObjectLink;
    47         }
    48         if ($this->Content) {
    49             return parent::Link();
    50         }
    51         return false;
    52     }
    53
    54     function getCMSFields() {
    55         $fields = parent::getCMSFields();
    56
    57         $contentField = $fields->dataFieldByName('Content');
    58         $fields->findOrMakeTab('Root.Content.Content', _t('MapObject.Content', 'Content'));
    59         $fields->addFieldToTab("Root.Content.Content", $contentField);
    60
    61         $sc = SiteConfig::current_site_config();
    62         if (!$sc->isNeedMapApiKey()) {
    63             $fields->addFieldToTab('Root.Content.Main', new LiteralField('NoMapApiKey', _t("SiteConfig.NoMapApiKeyMessage")));
    64         } else {
    65             $fields->addFieldToTab("Root.Content.Main", new TextField('Address', $this->FieldLabel('Address')));
    66             $fields->addFieldToTab("Root.Content.Main", new TextareaField('Anons', $this->FieldLabel('Anons')));
    67             $fields->addFieldToTab("Root.Content.Main", new ImageField('Image', $this->FieldLabel('Image')));
    68             $fields->addFieldToTab("Root.Content.Main", new TextField('ObjectLink', $this->FieldLabel('ObjectLink')));
    69             $fields->addFieldToTab("Root.Content.Main", new TextField('Latitude', $this->FieldLabel('Latitude')));
    70             $fields->addFieldToTab("Root.Content.Main", new TextField('Longitude', $this->FieldLabel('Longitude')));
    71             $fields->addFieldToTab("Root.Content.Main", new LiteralField('YandexMap', '<a href="#" class="popuplink" id="map_object_ymap_link">Указать объект на Яндекс.Карте</a>'));
    72             $fields->addFieldToTab("Root.Content.Main", new LiteralField('MapPageType', '<div state="not_loaded" id="map_object_ymap"></div>'));
    73
    74             $sc->RequireMapApi('https://api-maps.yandex.ru/2.0.48/?load=package.full&lang=ru-RU&apikey=');
    75             Requirements::css('map_objects/css/admin_object.css');
    76             Requirements::javascript('map_objects/js/admin_object.js');
    77         }
    78         return $fields;
    79     }
    80
    81     public function  getCMSActions() {
    82         Requirements::javascript('webylon/javascript/SubpageAction.js');
    83         $fields = parent::getCMSActions();
    84         $fields->push(new HiddenField('backLink', '', $this->Parent()->ID));
    85         $fields->unshift(new FormAction('goBack', _t('MapObject.BACKBUTTON','Back')));
    86         return $fields;
    87     }
    88
    89 }
    90
    91 class MapObject_Controller extends Page_Controller {
    92 }

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