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

Packages

  • 1c
    • exchange
      • catalog
  • auth
  • Booking
  • building
    • company
  • cart
    • shipping
    • steppedcheckout
  • Catalog
    • monument
  • 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
  • FavoritePage_Controller
  • FileDataObjectManager_Controller
  • FindCyrillic_Controller
  • HomePage_Controller
  • Import1C_Controller
  • ImportCatalog1C_Controller
  • LastDoc_Controller
  • LiveCalendarWidget_Controller
  • MapObject_Controller
  • MapObjectGroup_Controller
  • MapPage_Controller
  • MediawebPage_Controller
  • ModelAsController
  • Monument_Controller
  • MonumentCatalog_Controller
  • MonumentForm_Controller
  • MultiUploadControls
  • NewsArchive_Controller
  • NewsEntry_Controller
  • NewsHolder_Controller
  • 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
  • Socle_Controller
  • SocleSize_Controller
  • SpecialCatalog_Controller
  • SS_HTTPRequest
  • SS_HTTPResponse
  • StartCatalog_Controller
  • SubsitesSelectorPage_Controller
  • VideoBankPage_Controller

Interfaces

  • NestedController

Exceptions

  • SS_HTTPResponse_Exception
  1 <?php
  2 // страница Вид комплекта памятников
  3 class MonumentForm extends Catalog {
  4     
  5     static $allowed_children = array('Monument');
  6     
  7     static $subpage_children = 'Monument';
  8     
  9     static $defaults = array(
 10         'ShowInMenus' => 0,
 11     );
 12 
 13     static $simple_order = false;
 14 
 15     static function set_simple_order($val = true) {
 16         self::$simple_order = ($val) ? true : false;
 17     }
 18     
 19     static function calc_grav_price($type, $text) {
 20         $sc = SiteConfig::current_site_config();
 21         $price = 0;
 22         if ($type == 'person') {
 23             if ($sc->FIOPriceType == 'fixed') {
 24                 $price = $sc->FIOTotalGravPrice;
 25             } else {
 26                 $charsCount = mb_strlen(trim(preg_replace('/\s+/', '', trim($text))));
 27                 $price = ($charsCount * $sc->FIOLetterGravPrice);
 28             }
 29         }
 30         
 31         if ($type == 'epitaph') {
 32             if ($sc->EpitaphPriceType == 'fixed') {
 33                 $price = $sc->EpitaphTotalGravPrice;
 34             } else {
 35                 $charsCount = mb_strlen(trim(preg_replace('/\s+/', '', trim($text))));
 36                 $price = ($charsCount * $sc->EpitaphLetterGravPrice);
 37             }
 38         }
 39         return $price;
 40     }
 41         
 42     function MinPrice() {
 43         if (($products = $this->filteredProducts()) && $products->Count()) {
 44             $products->sort('Price');
 45             return (float)$products->First()->Price;
 46         }
 47     }
 48     
 49     function PersonsDataLink($count) {
 50         return $this->Link("persons_data/{$count}");
 51     }
 52     
 53     function PhotoCategoryItemsLink() {
 54         return $this->Link("photo_category_items");
 55     }
 56         
 57     function MonumentPersons($count=false) {
 58         $sc = SiteConfig::current_site_config();
 59         if (!$count) {
 60             $count = $sc->MaxFIOCount;
 61         }
 62         $persons = new DataObjectSet();
 63         for($i = 1; $i <= $count; $i++) {
 64             $persons->push(new ArrayData(array(
 65                 'Count' => $i,
 66                 'Title' => _t("MonumentPersons.Count_{$i}"),
 67                 'Link' => $this->PersonsDataLink($i),
 68             )));
 69         }
 70         return $persons;
 71     }
 72     
 73     function PortraitTypes() {      
 74         if ($portraitTypes = DataObject::get('PortraitType')) {
 75             return $portraitTypes;
 76         }
 77         return false;
 78     }
 79     
 80     function MonumentEpitaphs() {   
 81         if ($epitaphs = DataObject::get('Epitaph')) {
 82             return $epitaphs;
 83         }
 84         return false;
 85     }
 86     
 87     function MonumentPhotoCategories() {    
 88         if ($monumentPhotoCategories = DataObject::get('MonumentPhotoGallery')) {
 89             return $monumentPhotoCategories;
 90         }
 91         return false;
 92     }
 93 }
 94 
 95 class MonumentForm_Controller extends Catalog_Controller {
 96     
 97     function persons_data($request) {
 98         if ($count = (int)$request->param('ID')) {
 99             $sc = SiteConfig::current_site_config();
100             if ($count > $sc->MaxFIOCount) {
101                 $count = $sc->MaxFIOCount;
102             }
103             
104             $fields = new FieldSet();
105             for($i = 1; $i <= $count; $i++) {
106                 $fields->push(new LiteralField('PersonData', '<div class="monument_personsInput" data-num="'.$i.'" data-price="0">'));
107                 $fields->push(new LiteralField('PersonNumber', '<p class="monument_optionsTitle">' . sprintf(_t("MonumentForm.PersonNumber"), $i). '</p>'));
108                 $fields->push(new TextField('FIO['.($i-1).']', _t('MonumentForm.FIO')));
109                 $fields->push($df = new TextField('Date1['.($i-1).']', _t('MonumentForm.Date1')));
110                 $df->setHTML5Attribute('pattern', '\d\d\.\d\d\.\d\d\d\d');
111                 $df->addExtraAttribute('data-mask', '\d\d\.\d\d\.\d\d\d\d');
112                 $fields->push($df = new TextField('Date2['.($i-1).']', _t('MonumentForm.Date2')));
113                 $df->setHTML5Attribute('pattern', '\d\d\.\d\d\.\d\d\d\d');
114                 $df->addExtraAttribute('data-mask', '\d\d\.\d\d\.\d\d\d\d');
115                 $fields->push(new SimpleImageField('PortraitImage['.($i-1).']', _t('MonumentForm.PortraitImage')));
116                 $fields->push(new LiteralField('PersonData', '</div>'));
117             }
118             $portraitTypes = DataObject::get('PortraitType', "MaxPersonsCount <= {$count}");
119             return $this->customise(array(
120                 'Fields' => $fields,
121                 'PortraitTypes' => $portraitTypes,
122                 'MonumentPersons' => $this->MonumentPersons($count),
123             ))->renderWith('PersonsMonumentData');
124         }
125     }
126     
127     function photo_category_items($request) {
128         if ($category = DataObject::get_by_id('MonumentPhotoGallery', (int)$request->param('ID'))) {
129             if ($category->Items() && $category->Items()->Count()) {
130                 return $this->customise(array('Items' => $category->Items()))->renderWith('PhotoCategoryItems');
131             }
132         }
133     }
134     
135     function grav_price() {
136         $rs = 0;
137         $price = 0;
138         if (isset($_GET['type']) && in_array($_GET['type'], array('person', 'epitaph'))) {
139             $text = isset($_GET['text']) ? trim($_GET['text']) : '';
140             $price = MonumentForm::calc_grav_price($_GET['type'], $text);
141         }
142         return json_encode(array('rs' => $rs, 'price' => $price));
143     }
144     
145     function AddMonumentToBasketForm() {
146         $fields = new FieldSet();
147         $sc = SiteConfig::current_site_config();
148         
149         $fields->push(new HiddenField('MonumentID'));
150         $fields->push(new HiddenField('PolishingID'));
151         $fields->push(new HiddenField('PersonCount'));
152         
153         $fields->push(new HiddenField('PortraitTypeID'));       
154         $fields->push(new HiddenField('FlowerGardenSizeID'));
155         
156         $fields->push($ef = new TextAreaField('Epitaph', 'Общая для всех персон эпитафия'));
157         $ef->addExtraAttribute("data-price", "0");
158         if ($epitaphs = DataObject::get('Epitaph')) {
159             $fields->push(new DropdownField('Epitaphs', _t('MonumentForm.Epitaphs'), $epitaphs->map('ID', 'Text', 'не выбрано')));
160         }
161         
162         // поля для сохранения выбранных изображений для гравировки
163         if ($sc->MaxImageCount) {
164             for($i = 1; $i <= $sc->MaxImageCount; $i++) {
165                 $fields->push(new HiddenField("GalleryImage{$i}ID"));
166             }
167         }       
168 
169         // Шаг 2Б - эпитафия и фото из галереи для плиты (если цветник с плитой)        
170         if ($epitaphs) {
171             $fields->push(new DropdownField('TileEpitaphs', _t('MonumentForm.TileEpitaphs'), $epitaphs->map('ID', 'Text', 'не выбрано')));
172         }
173         $fields->push($ef = new TextAreaField('TileEpitaph', 'Общая для всех персон эпитафия'));
174         $ef->addExtraAttribute("data-price", "0");
175         
176         if ($sc->MaxTileImageCount) {
177             for($i = 1; $i <= $sc->MaxTileImageCount; $i++) {
178                 $fields->push(new HiddenField("TileGalleryImage{$i}ID"));
179             }
180         }
181 
182         $fields->push(new HiddenField('FIOPriceType', 'FIOPriceType', $sc->FIOPriceType));  // тип цены гравировки ФИО(фиксированная/за символ)
183         $fields->push(new HiddenField('FIOLetterGravPrice', 'FIOLetterGravPrice', $sc->FIOLetterGravPrice));    // цена графировки ФИО, за символ 
184         $fields->push(new HiddenField('FIOTotalGravPrice', 'FIOTotalGravPrice', $sc->FIOTotalGravPrice));   // цена графировки ФИО фиксированная
185         
186         $fields->push(new HiddenField('EpitaphPriceType', 'EpitaphPriceType', $sc->EpitaphPriceType));  // тип цены гравировки эпитафии (фиксированная/за символ)
187         $fields->push(new HiddenField('EpitaphLetterGravPrice', 'EpitaphLetterGravPrice', $sc->EpitaphLetterGravPrice));    // цена графировки эпитафии, за символ 
188         $fields->push(new HiddenField('EpitaphTotalGravPrice', 'EpitaphTotalGravPrice', $sc->EpitaphTotalGravPrice));   // цена графировки эпитафии фиксированная
189         
190         $fields->push(new HiddenField('MaxFIOCount', 'MaxFIOCount', $sc->MaxFIOCount)); // Максимальное кол-во ФИО
191         $fields->push(new HiddenField('MaxImageCount', 'MaxImageCount', $sc->MaxImageCount)); // Максимальное кол-во изображений
192         $fields->push(new HiddenField('MaxTileImageCount', 'MaxTileImageCount', $sc->MaxTileImageCount)); // Максимальное кол-во изображений на плите
193         
194         $form = new Form(
195             $this,
196             'AddMonumentToBasketForm',
197             $fields,
198             new FieldSet(new FormAction('addToCart', _t('MonumentForm.AddToCart')))
199         );
200         $form->disableSecurityToken();
201         
202         return $form;
203     }
204     
205     function addToCart($data, $form) {
206 
207         if (MonumentForm::$simple_order) {
208             Cart::clear();
209         }
210 
211         if (isset($data['MonumentID']) && is_numeric($data['MonumentID'])) {
212             $product = DataObject::get_by_id('Monument', $data['MonumentID']);
213             $itemData = array();
214             $itemData['ID'] = 0;
215             $itemData['Title'] = $product->FullTitle();
216             $itemData['LinkedID'] = $product->ID;
217             $itemData['ItemPrice'] = 0;
218             $itemData['OrderID'] = 0;
219             $itemData['Quantity'] = 1;
220 
221             $itemData['NeedMonumentLayout'] = (isset($data['NeedMonumentLayout'])) ? (int)$data['NeedMonumentLayout'] : 0;
222             $itemData['FlowerGardenSizeID'] = (isset($data['FlowerGardenSizeID'])) ? (int)$data['FlowerGardenSizeID'] : 0;
223             $itemData['PolishingID'] = (isset($data['PolishingID'])) ? (int)$data['PolishingID'] : 0;
224 
225             $item = Object::create('OrderItem', $itemData);
226             $item->write();         
227             $item->RealItemID = $item->ID;
228             
229             if (isset($data['FIO'])) {
230                 $persons = new DataObjectSet();
231                 $images = array();
232                 foreach($data['FIO'] as $key=>$fio) {
233                     if ($fio) {
234                         $person = new Person();
235                         $person->OrderItemID = $item->ID;
236                         $person->FIO = Convert::raw2sql(trim($fio));
237                         $person->Date1 = Convert::raw2sql(trim($data['Date1'][$key]));
238                         $person->Date2 = Convert::raw2sql(trim($data['Date2'][$key]));
239                         $person->write();
240                         $item->PersonCount++;
241                         
242                         if ($data['PortraitImage']['size'][$key]) {
243                             $images[$person->ID] = array(
244                                 'name' => $data['PortraitImage']['name'][$key],
245                                 'type' => $data['PortraitImage']['type'][$key],
246                                 'tmp_name' => $data['PortraitImage']['tmp_name'][$key],
247                                 'size' => $data['PortraitImage']['size'][$key],
248                             );
249                         }
250                     }
251                 }
252                 
253                 if (count($images)) {
254                     $folder = Folder::findOrMake('portraits');
255                     foreach($images as $personID=>$photosData) {
256                         $person = DataObject::get_by_id('Person', $personID);
257                         $fileID = $folder->addUploadToFolder($photosData);
258                         $person->PhotoID = $fileID;
259                         $person->write();
260                     }
261                 }
262             }
263             
264             $item->Epitaph = (isset($data['Epitaph'])) ? Convert::raw2sql(trim($data['Epitaph'])) : '';
265             $item->TileEpitaph = (isset($data['TileEpitaph'])) ? Convert::raw2sql(trim($data['TileEpitaph'])) : '';
266             
267             if (isset($data['PortraitTypeID']) && ($type = DataObject::get_by_id('PortraitType', (int)$data['PortraitTypeID']))) {
268                 $item->PortraitTypeID = $type->ID;
269                 $item->PortraitCount = (int)$data['PortraitCount'];
270             }
271             
272             for($i = 1; $i < 4; $i++) {
273                 if (isset($data["GalleryImage{$i}ID"]) && ($image = DataObject::get_by_id('MonumentGalleryItem', (int)$data["GalleryImage{$i}ID"]))) {
274                     $item->{"GalleryImage{$i}ID"} = $image->ID;
275                 }
276                 if (isset($data["TileGalleryImage{$i}ID"]) && ($image = DataObject::get_by_id('MonumentGalleryItem', (int)$data["TileGalleryImage{$i}ID"]))) {
277                     $item->{"TileGalleryImage{$i}ID"} = $image->ID;
278                 }
279             }
280             
281             $item->ItemPrice = $item->calculateItemPrice();
282             $item->write();
283 
284             Cart::add_new_item($item);
285             Session::clear('Cart.Process');
286             
287             // FIXME редиректы по self::$simple_order
288             if (!$this->isAjax())
289                 Director::redirectBack();
290             return $this->CartBlock();
291             
292         }
293     }
294 }
295 
296 
[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.2 API Docs API documentation generated by ApiGen 2.8.0