Webylon 3.1 API Docs
  • Package
  • Class
  • Tree
  • Deprecated
  • Download
Version: current
  • 3.2
  • 3.1

Packages

  • auth
  • Booking
  • cart
    • shipping
    • steppedcheckout
  • Catalog
  • cms
    • assets
    • batchaction
    • batchactions
    • bulkloading
    • comments
    • content
    • core
    • export
    • newsletter
    • publishers
    • reports
    • security
    • tasks
  • Dashboard
  • DataObjectManager
  • event
  • faq
  • forms
    • actions
    • core
    • fields-basic
    • fields-dataless
    • fields-datetime
    • fields-files
    • fields-formatted
    • fields-formattedinput
    • fields-relational
    • fields-structural
    • transformations
    • validators
  • googlesitemaps
  • guestbook
  • installer
  • newsletter
  • None
  • photo
    • gallery
  • PHP
  • polls
  • recaptcha
  • sapphire
    • api
    • bulkloading
    • control
    • core
    • cron
    • dev
    • email
    • fields-formattedinput
    • filesystem
    • formatters
    • forms
    • i18n
    • integration
    • misc
    • model
    • parsers
    • search
    • security
    • tasks
    • testing
    • tools
    • validation
    • view
    • widgets
  • seo
    • open
      • graph
  • sfDateTimePlugin
  • spamprotection
  • stealth
    • captha
  • subsites
  • userform
    • pagetypes
  • userforms
  • webylon
  • widgets

Classes

  • Announcement_Controller
  • AnnouncementHolder_Controller
  • BookingAdminPage_Controller
  • BookingPage_Controller
  • Cart_Controller
  • CartPage_Controller
  • Catalog_Controller
  • CheckoutPage_Controller
  • ChequePayment_Handler
  • ContactsPage_Controller
  • ContentController
  • ContentNegotiator
  • Controller
  • DataObjectManager_Controller
  • DatePickerField_Controller
  • Director
  • DocPage_Controller
  • DocumentsPage_Controller
  • Event_Controller
  • EventHolder_Controller
  • FileDataObjectManager_Controller
  • FindCyrillic_Controller
  • HomePage_Controller
  • LastDoc_Controller
  • LiveCalendarWidget_Controller
  • MapObject_Controller
  • MapObjectGroup_Controller
  • MapPage_Controller
  • MediawebPage_Controller
  • ModelAsController
  • MultiUploadControls
  • NewsArchive
  • Orders1CExchange_Controller
  • Page_Controller
  • Payment_Handler
  • PhotoAlbumManager_Controller
  • Product_Controller
  • ProductSearchPage_Controller
  • ProfilePage_Controller
  • PublHolder_Controller
  • Publication_Controller
  • RatingExtension_Controller
  • RegistrationPage_Controller
  • RemoveOrphanedPagesTask
  • RequestHandler
  • Room_Controller
  • RoomCatalog_Controller
  • RootURLController
  • SapphireInfo
  • Search_Controller
  • Session
  • SimpleOrderPage_Controller
  • SiteMap_Controller
  • SpecialCatalog_Controller
  • SS_HTTPRequest
  • SS_HTTPResponse
  • StartCatalog_Controller
  • SubsitesSelectorPage_Controller
  • VideoBankPage_Controller

Interfaces

  • NestedController

Exceptions

  • SS_HTTPResponse_Exception
  1 <?php
  2 /**
  3  * Контейнер для данных анонса
  4  *
  5  * @author inxo
  6  */
  7 class Announcement extends Page {
  8     static $icon = 'anons/img/anons';
  9 
 10     static $can_be_root = false;
 11     static $allowed_children = 'none';
 12     static $default_parent = 'AnnouncementHolder';
 13 
 14     static $db = array(
 15             'Date' => 'Date',
 16             'LinkType' => 'Int',
 17             'Description' => 'Text',
 18             'ExternalLink' => 'Text',
 19     );
 20 
 21     static $has_one = array(
 22             'Photo' => 'Image',
 23             'InternalLink' => 'SiteTree'
 24     );
 25 
 26     static $defaults = array(
 27             'LinkType' => 0,
 28             'ShowOnlyInTab' => 0,
 29             'ShowInSearch' => 0,
 30             'ShowInMenus' => 0,
 31             'AutoChild' => 0,
 32     );
 33     static $summary_fields = array(
 34             'Title','Date','Link','Description'
 35     );
 36 
 37     static $searchable_fields = array(
 38         'Title','Description','Content'
 39     );
 40 
 41     public function Link() {
 42         $Link = false;
 43         switch ($this->LinkType) {
 44             case 1:
 45                 $Link = $this->ExternalLink;
 46                 break;
 47             case 2:
 48                 $Link = $this->InternalLink()->Link();
 49                 break;
 50             case 3:
 51                 $Link = Controller::join_links(Director::baseURL(), $this->RelativeLink());
 52                 break;
 53             default:
 54                 break;
 55         }
 56         return $Link;
 57     }
 58 
 59     function getCMSFields() {
 60         $fields = parent::getCMSFields();
 61 
 62         $fields->addFieldToTab('Root.Content.Main', $dateField = new DateField('Date', $this->fieldLabel('Date')));
 63         if (!property_exists('FormField', 'use_html5') || !FormField::use_html5()) {
 64             $dateField->setLocale('ru_RU');
 65             $dateField->setConfig('dateformat', 'dd/MM/yyyy');
 66             $dateField->setConfig('showcalendar',1);
 67         }
 68 
 69         $fields->addFieldToTab('Root.Content.Main', new TextField('Title', $this->fieldLabel('Title')));
 70         $fields->addFieldToTab('Root.Content.Main', new TextareaField('Description', $this->fieldLabel('Description')));
 71 
 72         $fields->addFieldToTab('Root.Content.Main', $imageField = new ImageField('Photo', $this->fieldLabel('Photo')));
 73         $imageField->setFolderName('Anons');        
 74         
 75         // задаем max размеры для ImageAutoResize
 76         if ($this->ParentID && AnnouncementHolder::is_slider_holder($this->ParentID)) {
 77             $imageField->AutoresizeMaxWidth = AnnouncementHolder::$max_slider_width;
 78         }
 79 
 80         $fields->addFieldToTab('Root.Content', new Tab('Link', $this->fieldLabel(_t('Announcement.tab_Link', 'Information'))), 'PagePhotos');
 81 
 82         $fields->addFieldToTab('Root.Content.Link', $type = new SelectionGroup('LinkType', array(
 83             '0//' . _t('Announcement.NoLink', 'No Link') => new LiteralField('NoLink', ''),
 84             '1//' . _t('Announcement.ExternalLink', 'External Link') => new TextField('ExternalLink', _t('Announcement.ExternalLink', 'External Link')),
 85             '2//' . _t('Announcement.InternalLink', 'Internal Link') => new TreeDropdownField('InternalLinkID', _t('Announcement.InternalLink', 'Internal Link'), 'SiteTree'),
 86             '3//' . _t('Announcement.db_Content', 'Content') => $fields->dataFieldByName('Content')
 87         )));
 88         $fields->removeFieldFromTab('Root.Content.Main', 'Content');
 89 
 90         $this->extend('hideCMSFields', $fields); // extend для скрытия полей из админки
 91         return $fields;
 92     }
 93     
 94     function onBeforeWrite() {
 95         parent::onBeforeWrite();
 96         
 97         // нельзя ссылаться на самого себя - происходит зацикливание
 98         if ($this->InternalLinkID == $this->ID) {
 99             $this->InternalLinkID = 0;
100         }
101     }
102 
103     public function  getCMSActions() {
104         Requirements::javascript('webylon/javascript/SubpageAction.js');
105         $fields = parent::getCMSActions();
106         $fields->push(new HiddenField('backLink', '', $this->Parent()->ID));
107         $fields->insertBefore(new FormAction('goBack', _t('Announcement.BACKBUTTON','Back')),'action_unpublish');
108         return $fields;
109     }
110 
111     public function populateDefaults() {
112         parent::populateDefaults();
113         $this->Date = date('d/m/Y');
114     }
115 
116     public function Widget($id=null, $limit=null) {
117         if (is_numeric($id) && $id > 0) {
118             $parent = DataObject::get_by_id(self::$default_parent, $id);
119         }
120         else if ($id) {
121             $parent = DataObject::get_one(self::$default_parent, "URLSegment='" . Convert::raw2sql($id) . "'");
122         }
123         else {
124             $parent = DataObject::get_one(self::$default_parent);
125         }
126 
127         if (!$parent) return FALSE;
128 
129         $showtype = $parent->ShowTypeBlock;
130         if (!$showtype) return FALSE;
131 
132         switch ($showtype) {
133             case 1:
134                 $sort = 'Date DESC';
135                 break;
136             case 2:
137                 $sort = 'RAND()';
138                 break;
139             case 3:
140                 $sort = 'Sort';
141                 break;
142             default:
143                 break;
144         }
145         if ($limit == null) {
146             if ($showtype == 3) {
147                 $limit = '';
148             } else {
149                 $limit = $parent->PerBlock;
150             }
151         }
152         return DataObject::get($this->ClassName, "`ParentID` = {$parent->ID} AND `Status` LIKE '%Published%'", $sort, '', $limit);
153     }
154 }
155 
156 class Announcement_Controller extends Page_Controller {
157 
158 }
159 
[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. -
Webylon 3.1 API Docs API documentation generated by ApiGen 2.8.0