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

  • Address
  • AddSubsiteTask
  • Announcement
  • AnnouncementDecorator
  • AnnouncementHolder
  • AssociatedFolderDecorator
  • AttachedFiles
  • AudioPhpCaptcha
  • AutoCompleteField
  • BaseMediawebImportParser
  • BookingOrder_StatusLog
  • CalendarUtil
  • CalendarWidgetExtention
  • CatalogCatalogLinkedDecorator
  • CatalogImportTask
  • CatalogOldFieldsDecorator
  • CatalogProductLinkedDecorator
  • CheckoutStep_ShippingMethod
  • ChequePayment
  • ClearHistoryTask
  • ClientEmailOrderNotification_SiteConfig
  • ClientVKOrderNotification_SiteConfig
  • CommentsSiteConfig
  • ContactsPage
  • CookieExtention
  • CostTableShippingRate
  • CustomMenu
  • CustomMenuAdmin
  • CustomMenuDecorator
  • CustomMenuHolder
  • CustomMenuItem
  • CustomPayment
  • DataObjectLoggerExtension
  • DataObjectSubsites
  • DefaultCMSActionDecorator
  • DeleteOldAssociatedFoldersTask
  • DocPage
  • DocumentDirection
  • DocumentHaving
  • DocumentSearchForm
  • DocumentSiteConfig
  • DocumentsPage
  • DocumentType
  • DOMUtil
  • ExtendPageAnnouncement
  • ExtendPageNews
  • ExtendPagePoll
  • FileOversizeDecorator
  • FindCyrillicSiteConfig
  • FolderRenameTask
  • GDMergeAlpha
  • HomePage
  • ImageAutoResize
  • ImageResizeTask
  • ImportAdmin
  • ImportAutoStartTask
  • ImportCatalogMessage
  • ImportConfig
  • ImportLog
  • ImportSiteConfig
  • ImportTask
  • LoggerAdmin
  • LogItem
  • ManagerEmailOrderNotification_SiteConfig
  • MapObject
  • MapObjectGroup
  • MapPage
  • MediawebForm
  • MediawebImportParser
  • MemberLoggerExtension
  • MultiUploadConfig
  • NearestEventExtention
  • NewDocumentsAdmin
  • News_Controller
  • NewsEntry
  • NewsEntry_Controller
  • NewsHolder
  • NewsHolder_Controller
  • NewsLiveCalendarWidget
  • NewsSiteConfig
  • Order_StatusLog
  • Orders1CExchange
  • PageHideFieldsExtension
  • PageInformerRates
  • PageInformerWeather
  • Payment_Failure
  • Payment_Processing
  • Payment_Result
  • Payment_Success
  • PaymentMethod
  • PaymentSiteConfig
  • PayPalPayment
  • PayPalPayment_Handler
  • PhoneField
  • PhotoAlbumExtentions
  • PhpCaptcha
  • PhpCaptchaColour
  • PhpCaptchaField
  • phpMorphy
  • phpMorphy_AncodesResolver_AsIs
  • phpMorphy_AncodesResolver_Proxy
  • phpMorphy_AncodesResolver_ToDialingAncodes
  • phpMorphy_AncodesResolver_ToText
  • phpMorphy_AnnotDecoder_Base
  • phpMorphy_AnnotDecoder_Common
  • phpMorphy_AnnotDecoder_Factory
  • phpMorphy_AnnotDecoder_Predict
  • phpMorphy_FilesBundle
  • phpMorphy_Fsa
  • phpMorphy_Fsa_Decorator
  • phpMorphy_Fsa_Proxy
  • phpMorphy_Fsa_Sparse_File
  • phpMorphy_Fsa_Sparse_Mem
  • phpMorphy_Fsa_Sparse_Shm
  • phpMorphy_Fsa_Tree_File
  • phpMorphy_Fsa_Tree_Mem
  • phpMorphy_Fsa_Tree_Shm
  • phpMorphy_Fsa_WordsCollector
  • phpMorphy_GramInfo
  • phpMorphy_GramInfo_AncodeCache
  • phpMorphy_GramInfo_Decorator
  • phpMorphy_Graminfo_File
  • phpMorphy_Graminfo_Mem
  • phpMorphy_GramInfo_Proxy
  • phpMorphy_GramInfo_Proxy_WithHeader
  • phpMorphy_GramInfo_RuntimeCaching
  • phpMorphy_Graminfo_Shm
  • phpMorphy_GrammemsProvider_Base
  • phpMorphy_GrammemsProvider_Decorator
  • phpMorphy_GrammemsProvider_Empty
  • phpMorphy_GrammemsProvider_Factory
  • phpMorphy_GrammemsProvider_ForFactory
  • phpMorphy_GrammemsProvider_ru_RU
  • phpMorphy_GramTab
  • phpMorphy_GramTab_Empty
  • phpMorphy_GramTab_Proxy
  • phpMorphy_Link
  • phpMorphy_Link_Annot
  • phpMorphy_Link_Base
  • phpMorphy_Morphier_Base
  • phpMorphy_Morphier_Bulk
  • phpMorphy_Morphier_Common
  • phpMorphy_Morphier_Empty
  • phpMorphy_Morphier_Finder_Base
  • phpMorphy_Morphier_Finder_Common
  • phpMorphy_Morphier_Finder_Predict_Databse
  • phpMorphy_Morphier_Finder_Predict_Suffix
  • phpMorphy_Morphier_Helper
  • phpMorphy_Morphier_Predict_Database
  • phpMorphy_Morphier_Predict_Suffix
  • phpMorphy_Morphier_PredictCollector
  • phpMorphy_Semaphore
  • phpMorphy_Semaphore_Empty
  • phpMorphy_Semaphore_Nix
  • phpMorphy_Semaphore_Win
  • phpMorphy_Shm_Cache
  • phpMorphy_Shm_Cache_FileDescriptor
  • phpMorphy_Shm_Header
  • phpMorphy_Source_Dba
  • phpMorphy_Source_Fsa
  • phpMorphy_State
  • phpMorphy_Storage
  • phpMorphy_Storage_Factory
  • phpMorphy_Storage_File
  • phpMorphy_Storage_Mem
  • phpMorphy_Storage_Proxy
  • phpMorphy_Storage_Shm
  • phpMorphy_UnicodeHelper
  • phpMorphy_UnicodeHelper_Base
  • phpMorphy_UnicodeHelper_MultiByteFixed
  • phpMorphy_UnicodeHelper_singlebyte
  • phpMorphy_UnicodeHelper_ucs_2be
  • phpMorphy_UnicodeHelper_ucs_2le
  • phpMorphy_UnicodeHelper_ucs_4be
  • phpMorphy_UnicodeHelper_ucs_4le
  • phpMorphy_UnicodeHelper_utf_16_Base
  • phpMorphy_UnicodeHelper_utf_16be
  • phpMorphy_UnicodeHelper_utf_16le
  • phpMorphy_UnicodeHelper_utf_32_Base
  • phpMorphy_UnicodeHelper_utf_32be
  • phpMorphy_UnicodeHelper_utf_32le
  • phpMorphy_UnicodeHelper_utf_8
  • phpMorphy_WordDescriptor
  • phpMorphy_WordDescriptor_Collection
  • phpMorphy_WordDescriptor_Collection_Serializer
  • phpMorphy_WordForm
  • ProductImportV1Decorator
  • ProductOldFieldsDecorator
  • ProductProductLinkedDecorator
  • PublHolder
  • Publication
  • PublicationSiteTree
  • RatingDataObject
  • RatingExtension
  • RealtySiteConfigDecorator
  • RecentComments
  • RecentFiles
  • RecentPages
  • RelatedPageLink
  • RepairImportTask
  • RoomRate_PriceField
  • RussianUpLower
  • SberbankPayment
  • SberbankPayment_Handler
  • SetMainSiteHomePageTypeTask
  • ShippingEstimator
  • ShippingPackage
  • ShowUserFromExtension
  • SiteConfigDecorator
  • SiteConfigSubsites
  • SiteTreeSubsites
  • SMSCOrderNotification_SiteConfig
  • SMSOrderNotification_SiteConfig
  • SortCMSActionDecorator
  • SS_Report_FakeQuery
  • SSMorphy
  • SSNController
  • SteppedCheckout_PageMessages
  • SubpageListField
  • SubscribeFormAllPagesExtension
  • SubsiteDropdownField
  • SubsiteReportWrapper
  • TableShippingRate
  • UnitellerPayment
  • UnitellerPayment_Handler
  • UnmoderatedComments
  • VideoManager
  • VideoSiteConfig
  • WatermarkImage
  • WatermarkSiteConfig
  • WebylonImportAdmin
  • WebylonImportCatalog
  • WeightTableShippingRate
  • XMLValidate
  • YaMoneyPayment
  • YaMoneyPayment_Handler
  • YMLExporter
  • YMLSiteConfig

Interfaces

  • ImportInterface
  • PaymentObjectInterface
  • phpMorphy_AncodesResolver_Interface
  • phpMorphy_AnnotDecoder_Interface
  • phpMorphy_Fsa_Interface
  • phpMorphy_GramInfo_Interace
  • phpMorphy_GrammemsProvider_Interface
  • phpMorphy_GramTab_Interface
  • phpMorphy_Morphier_Finder_Interface
  • phpMorphy_Morphier_Interface
  • phpMorphy_Shm_Cache_Interface
  • phpMorphy_Source_Interface

Exceptions

  • phpMorphy_Exception

Functions

  • column_sort
  • column_sort_callback_basic
  • encodeFileForEmail
  • encodeMultipart
  • getMimeType
  • htmlEmail
  • loadMimeTypes
  • phpmorphy_overload_mb_funcs
  • plaintextEmail
  • processHeaders
  • QuotedPrintable_encode
  • supressOutput
  • validateError
  • validEmailAddr
  • wrapImagesInline
  • wrapImagesInline_rewriter
  1 <?php
  2 
  3 /**
  4  * Decorate a data object so that it has an associated folder on the file system that
  5  * lives and dies with this object.
  6  * You can access this associated folder from the object via myObj->AssociatedFolder()
  7  * Extend a DataObject class by calling
  8  * DataObject::add_extension('MyDataObject', 'AssociatedFolderDecorator');
  9  *
 10  */
 11 class AssociatedFolderDecorator extends SiteTreeDecorator {
 12 
 13     function extraStatics() {
 14         return array(
 15             'has_one' => array(
 16                 'AssociatedFolder' => 'Folder'
 17             )
 18         );
 19     }
 20     
 21     /**
 22      * Флаг - создавать ли прикрепленную папку. По умолчанию true.
 23      * Можно использовать при импорте - когда не нужно создавать папки сразу.
 24      *
 25      * @var boolean
 26      */
 27     static $createFolders = true;
 28     
 29 
 30     /**
 31      * The folder name to use if the decorated object's parent has no associated folder of its own.
 32      *
 33      * @var string
 34      */
 35     protected static $defaultRootFolderName = "page-files";
 36 
 37     /**
 38      * Set the folder name to use if the decorated object's parent has no associated folder of its own.
 39      *
 40      * @param string $folderName
 41      */
 42     static function setDefaultRootFolderName($folderName) {
 43         AssociatedFolderDecorator::$defaultRootFolderName = $folderName;
 44     }
 45 
 46     /**
 47      * Get the folder name to use if the decorated object's parent has no associated folder of its own.
 48      *
 49      * @return string
 50      */
 51     static function getDefaultRootFolderName() {
 52         return AssociatedFolderDecorator::$defaultRootFolderName;
 53     }
 54 
 55     /**
 56      * Do stuff before the decorated object is written.
 57      * In this case create the associated folder if it does not already exist.
 58      *
 59      */
 60     function onAfterWrite() {
 61         parent::onAfterWrite();
 62 
 63         $folder = null;
 64 
 65         // Check whether the folder id is 0 or the Folder object does not exist
 66         if ($this->owner->AssociatedFolderID != 0) {
 67             $folder = DataObject::get_by_id('Folder', $this->owner->AssociatedFolderID);
 68         }
 69 
 70         if (!$folder || !$folder->ID) {
 71             // A valid folder does not exist
 72             if ((!class_exists('WebylonImportAdmin') || Director::urlParam('Controller') != 'ImportTask') && self::$createFolders) {
 73                 $this->createAssociatedFolder();
 74             }
 75         } else {
 76             if (!file_exists($folder->getFullPath())) {
 77                 // The folder object may exist but the folder on the file system does not.
 78                 mkdir($folder->getFullPath(), Filesystem::$folder_create_mask, true);
 79             }
 80             if ($folder->Title != $this->getAssociatedFolderTitle()) {
 81                 $folder->Title = $this->getAssociatedFolderTitle();
 82                 $folder->write();
 83             }
 84         }
 85     }
 86 
 87     function onBeforeDuplicate($page) {
 88         $page->AssociatedFolderID = 0;
 89     }
 90 
 91     function getAssociatedFolderName() {
 92         $hash = ceil($this->owner->ID / 100); // sprintf('%03d', ceil(..))
 93         return $this->getDefaultRootFolderName() . '/' . $hash . '/' . $this->owner->ID;
 94     }
 95 
 96     function getAssociatedFolderTitle() {
 97         return $this->owner->ID . ' - ' . $this->owner->Title;
 98     }
 99 
100     function getAssociatedFolderParentName() {
101         $hash = ceil($this->owner->ID / 100); // sprintf('%03d', ceil(..))
102         return $this->getDefaultRootFolderName() . '/' . $hash ;
103     }
104 
105     function getAssociatedFolderParentTitle() {
106         $hash = ceil($this->owner->ID / 100); // sprintf('%03d', ceil(..))
107         return sprintf('%d01-%d00', $hash-1, $hash);
108     }
109 
110     /**
111      * Create the associated folder
112      *
113      * @return Folder
114      */
115     function createAssociatedFolder() {
116         if (!self::$createFolders) {
117             return false;
118         }
119         //если страница не сохранена, то не нужно создавать AssociatedFolder
120         if (!$this->owner->ID || (!$this->owner->ExistsOnLive && $this->owner->IsDeletedFromStage)) {
121             return false;
122         }
123         $hashFolder = Folder::findOrMake($this->getAssociatedFolderParentName());
124         $hashTitle = $this->getAssociatedFolderParentTitle();
125         if ($hashFolder->Title != $hashTitle) {
126             $hashFolder->Title = $hashTitle;
127             $hashFolder->write();
128         }
129 
130         $associatedFolder = Folder::findOrMake($this->getAssociatedFolderName());
131         $associatedFolder->Title = $this->getAssociatedFolderTitle();
132         $associatedFolder->write();
133 
134         $this->owner->AssociatedFolderID = $associatedFolder->ID;
135         $this->owner->writeWithoutVersion();
136         return $associatedFolder;
137     }
138     
139     /**
140      * Return the associated folder
141      *
142      * @return Folder
143      */
144     function getAssociatedFolder() {
145         if ($this->owner->AssociatedFolderID && $this->owner->AssociatedFolder()->ID) {
146             $folder = $this->owner->AssociatedFolder();
147         } else {
148             $folder = $this->owner->createAssociatedFolder();
149         }
150         return $folder;
151     }
152 
153     function onAfterDelete() {      
154         parent::onAfterDelete();
155         // Total delete from site
156         if ($this->owner->IsDeletedFromStage && !$this->owner->ExistsOnLive) {
157             if ($folder = $this->owner->AssociatedFolder()) {
158                 $folder->delete();
159             }
160         }
161     }
162 
163 }
164 
[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