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 class BookingAdminPage extends Page {
  4     
  5     static $months = array(
  6         1 => 'Январь',
  7         2 => 'Февраль',
  8         3 => 'Март',
  9         4 => 'Апрель',
 10         5 => 'Май',
 11         6 => 'Июнь',
 12         7 => 'Июль',
 13         8 => 'Август',
 14         9 => 'Сентябрь',
 15         10 => 'Октябрь',
 16         11 => 'Ноябрь',
 17         12 => 'Декабрь',
 18     );
 19     
 20     static $week_days = array(
 21         1 => 'пн',
 22         2 => 'вт',
 23         3 => 'ср',
 24         4 => 'чт',
 25         5 => 'пт',
 26         6 => 'сб',
 27         7 => 'вс',
 28     );
 29     
 30     static function get_default_dates() {
 31         return array(
 32             'StartDate' => date('d.m.Y'),
 33             'EndDate' => date('d.m.Y', strtotime('+30 day')),
 34         );
 35     }
 36     
 37     static function find_links($action="") {
 38         if ($page = DataObject::get_one('BookingAdminPage')) {
 39             return $page->Link($action);
 40         }
 41         return false;
 42     }
 43     
 44     function MonthData($date=false) {
 45         if (!$date) {
 46             $date = self::get_default_dates();
 47         }
 48         $rs = new DataObjectSet();
 49         if ($rooms = DataObject::get('Room')) {
 50             foreach($rooms as $room) {
 51                 $daysData = self::room_calendar($date, $room);
 52                 $roomsData = new DataObjectSet();
 53                 foreach($daysData->Days as $day) {                  
 54                     $count = RoomOrder::available_rooms_count($room->ID, $day->{'Date'}, $day->{'Date'});                   
 55                     $day->FreeCount = $count;
 56                     $roomsData->push($day);
 57                 }
 58                 
 59                 $rates = new DataObjectSet();
 60                 foreach($room->Rates() as $rate) {                  
 61                     $days = new DataObjectSet();
 62                     foreach($daysData->Days as $day) {
 63                         $dday = clone $day;
 64                         $dday->RatePrice = $rate->getOneDayRoomPrice(strtotime($day->{'Date'}));
 65                         $dday->OrderLink = $this->OrderRoomLink() . "?StartDate=" . $day->{'Date'} . "&RateID={$rate->ID}";
 66                         $dday->Rate = $rate;
 67                         $days->push($dday);
 68                     }
 69                     $rate->Days = $days;
 70                     $rates->push($rate);
 71                 }
 72                 $daysData->Days = $roomsData;
 73                 $room->RoomUseData = $daysData;
 74                 $room->RatesData = $rates;
 75                 $rs->push($room);
 76             }
 77         }
 78         return $rs;
 79     }
 80     
 81     static function room_calendar($date, $room) {
 82         if (is_array($date) && isset($date['StartDate']) && isset($date['EndDate'])) {
 83             $startDate = date('Y-m-d', strtotime($date['StartDate']));
 84             $endDate = date('Y-m-d', strtotime($date['EndDate']));
 85         } else {
 86             list($year, $month) = explode('_', $date);
 87             $year = (int)$year;
 88             $month = (int)$month;
 89             $startDate = "{$year}-{$month}-01";
 90             $endDate = "{$year}-{$month}-" . date("t", strtotime($startDate));
 91         }
 92         
 93         $days = new DataObjectSet();
 94         // формируем календарь на текущий месяц понедельно        
 95         $startDay = 0;
 96         $monthDay = 1;
 97         $f = true;
 98         $first = true;
 99         while ($f) {
100             $currDate = date("Y-m-d", strtotime("{$startDay} days", strtotime($startDate)));
101             $days_of_month = date("t", strtotime($currDate));
102             $nextDate = date("Y-m-d", strtotime(($startDay+1) . " days", strtotime($startDate)));
103             $days->push(new ArrayData(array(
104                 'Date' => $currDate,
105                 'NextDate' => $nextDate,
106                 'Day' => date('d', strtotime($currDate)),
107                 'FirstDay' => ((date('j', strtotime($currDate)) == 1) || $first) ? true : false,
108                 'LastDay' => (date('j', strtotime($currDate)) == $days_of_month) ? true : false,
109                 'MonthDays' => ((date('j', strtotime($currDate)) == 1) || $first) ? ($days_of_month - date('j', strtotime($currDate)) + 1) : false,
110                 'DayOfWeek' => self::$week_days[date('N', strtotime($currDate))],
111                 'Month' => self::$months[date('n', strtotime($currDate))],
112                 'Year' => date('Y', strtotime($currDate)),
113                 'IsWeekend' => (date('N', strtotime($currDate)) > 5) ? true : false,                
114                 'IsCurrentMonth' => (date('m', strtotime($currDate)) == $month) ? true : false,
115                 'DayActivityLink' => self::find_links('date_activity') . "?Date={$currDate}",
116             )));
117             
118             $monthDay++;
119             if ((date('j', strtotime($currDate)) == 1)) {
120                 $monthDay = 0;
121             }
122             $startDay++;
123             if ($nextDate > $endDate) { // если последняя неделя - выходим
124                 $f = false;
125             }
126             $first = false;
127         }
128         $nextDate = date('Y_m', strtotime("+1 month", strtotime($startDate)));
129         $prevDate = date('Y_m', strtotime("-1 month", strtotime($startDate)));
130         return new ArrayData(array(
131             'Days' => $days,
132             'Month' => self::$months[$month],
133             'Year' => $year,
134             'PrevDate' => $prevDate,
135             'NextDate' => $nextDate,
136         ));
137     }
138     
139     function CalendarLink() {
140         return $this->Link('calendar');
141     }
142     
143     function OrderRoomLink() {
144         return $this->Link('order_room');
145     }
146         
147     function OrderStatuses() {
148         $statuses = BookingOrder::LocalStatuses();
149         unset($statuses['Basket']);
150         $rs = new DataObjectSet();
151         foreach($statuses as $status => $title) {
152             $rs->push(new ArrayData(array(
153                 'Status' => $status,
154                 'Title' => $title,
155             )));
156         }
157         return $rs;
158     }
159 }
160 
161 class BookingAdminPage_Controller extends Page_Controller {
162     
163     function calendar($request) {       
164         $data = false;
165         if (isset($_GET['StartDate']) && trim($_GET['StartDate']) && ($startDate = date('Y-m-d', strtotime($_GET['StartDate'])))) {
166             if (isset($_GET['EndDate']) && trim($_GET['EndDate']) && ($endDate = date('Y-m-d', strtotime($_GET['EndDate'])))) {
167                 $data = $this->MonthData(array('StartDate' => $startDate, 'EndDate' => $endDate));      
168             }
169         }
170         if (!$data) {
171             $data = $this->MonthData();
172         }
173         return $this->customise(array('MonthData' => $data));
174     }
175     
176     function DateFilterForm() {
177         $fields = new FieldSet();
178         $fields->push(new DateField('StartDate', _t("DateFilterForm.StartDate")));
179         $fields->push(new DateField('EndDate', _t("DateFilterForm.EndDate")));
180         
181         $form = new Form(
182             $this,
183             'DateFilterForm',
184             $fields,
185             new FieldSet(new FormAction('doFilterDates', _t("DateFilterForm.FilterDates")))
186         );
187         if (isset($_GET['StartDate']) || isset($_GET['EndDate'])) {
188             $form->loadDataFrom($_GET);
189         } else {
190             $dates = BookingAdminPage::get_default_dates();
191             $form->loadDataFrom($dates);
192         }
193         return $form;
194     }
195 
196     function doFilterDates($data, $form) {
197         $url = $this->Link('calendar') . "?";
198         if (isset($data['StartDate']) && trim($data['StartDate']) && ($startDate = date('Y-m-d', strtotime($data['StartDate'])))) {
199             $url .= "StartDate={$startDate}&";
200         }
201         if (isset($data['EndDate']) && trim($data['EndDate']) && ($endDate = date('Y-m-d', strtotime($data['EndDate'])))) {
202             $url .= "EndDate={$endDate}";
203         }
204         return $this->redirect($url);
205     }
206 
207     function order_room() {
208         if (!isset($_GET['StartDate']) || !isset($_GET['RateID'])) {
209             return $this->redirectBack();
210         }
211         $startDate = date('Y-m-d', strtotime($_GET['StartDate']));
212         
213         $rate = DataObject::get_by_id('RoomRate', (int)$_GET['RateID']);
214         if (!$rate) {
215             return $this->redirectBack();
216         }
217         
218         if (isset($_GET['EndDate'])) {
219             $endDate = date('Y-m-d', strtotime($_GET['EndDate']));
220         } else {                    
221             $endDate = date('Y-m-d', strtotime("+1 day", strtotime($startDate)));
222         }
223         
224         $currDate = $startDate;
225         $hasEmptyDays = false;
226         while(strtotime($currDate) < strtotime($endDate)) {
227             $count = RoomOrder::available_rooms_count($rate->RoomID, $currDate, $currDate);
228             if (!$count) {
229                 $hasEmptyDays = true;
230                 break;
231             }
232             $currDate = date('Y-m-d', strtotime("+1 day", strtotime($currDate)));
233         }
234         if ($hasEmptyDays) {
235             return $this->redirect($this->Link());
236         }
237         
238         Session::set('BookingFilter', array(
239             'FilterStartDate' => date('d.m.Y', strtotime($startDate)),
240             'FilterEndDate' => date('d.m.Y', strtotime($endDate))
241         ));
242         
243         $data = array();
244         $data['dateArrival'] = $startDate;
245         $data['dateDeparture'] = $endDate;
246         $data['roomsList'] = array();
247         
248         $data['roomsList'][0]['rate-id'] = $rate->ID;
249         $data['roomsList'][0]['room-id'] = $rate->RoomID;
250         if ($rate->AdditionalPlaceCount) {
251             $data['roomsList'][0]['additional-count'] = $rate->AdditionalPlaceCount;
252         }
253         
254         $order = new BookingOrder();
255         $order->Status = 'Basket';
256         $order->write();
257         $order->saveOrderData($data);
258         
259         if ($bookingLink = BookingPage::find_links('services?RateID=' . $rate->ID)) {
260             $this->redirect($bookingLink);
261             return;
262         }
263         return $this->redirectBack();
264     }
265     
266     function ActivityMenu() {
267         $menu = new DataObjectSet();
268         
269         $date = '';
270         if (isset($_GET['Date']) && strtotime($_GET['Date'])) {
271             $date = "&Date=" . date('d.m.Y', strtotime($_GET['Date']));
272         }
273         
274         $item = new ArrayData(array(
275             'Type' => 'InOrders',
276             'Link' => $this->Link('date_activity') . "?Type=InOrders{$date}",
277             'Title' => _t('ActivityMenu.InOrdersTitle'),
278             'Current' => (!isset($_GET['Type']) || ($_GET['Type'] == 'InOrders')) ? 1 : 0,
279         ));
280         $menu->push($item);
281                 
282         $item = new ArrayData(array(
283             'Type' => 'OutOrders',
284             'Link' => $this->Link('date_activity') . "?Type=OutOrders{$date}",
285             'Title' => _t('ActivityMenu.OutOrdersTitle'),
286             'Current' => (isset($_GET['Type']) && ($_GET['Type'] == 'OutOrders')) ? 1 : 0,
287         ));
288         $menu->push($item);
289         
290         $item = new ArrayData(array(
291             'Type' => 'CurrentOrders',
292             'Link' => $this->Link('date_activity') . "?Type=CurrentOrders{$date}",
293             'Title' => _t('ActivityMenu.CurrentOrdersTitle'),
294             'Current' => (isset($_GET['Type']) && ($_GET['Type'] == 'CurrentOrders')) ? 1 : 0,
295         ));
296         $menu->push($item);
297         
298         return $menu;
299     }
300     
301     function date_activity() {
302         if (isset($_GET['Date'])) {
303             $date = date('Y-m-d', strtotime($_GET['Date']));
304         } else {
305             $date = date('Y-m-d');
306         }
307         
308         if (isset($_GET['Type']) && in_array($_GET['Type'], array('InOrders', 'OutOrders', 'CurrentOrders'))) {
309             $type = $_GET['Type'];
310         } else {
311             $type = 'InOrders';
312         }
313         
314         switch($type) {
315             case 'InOrders':
316                 $orders = DataObject::get('BookingOrder', "StartDate = '{$date}' AND Status IN('".implode("', '", BookingOrder::$accounted_statuses)."')");
317                 break;
318             case 'OutOrders':
319                 $orders = DataObject::get('BookingOrder', "EndDate = '{$date}' AND Status IN('".implode("', '", BookingOrder::$accounted_statuses)."')");
320                 break;
321             case 'CurrentOrders':
322                 $orders = DataObject::get('BookingOrder', "StartDate < '{$date}' AND EndDate > '{$date}' AND Status IN('".implode("', '", BookingOrder::$accounted_statuses)."')");
323                 break;
324         }
325         
326         return $this->customise(array(
327             'Date' => $date,
328             'OrdersList' => $orders,
329         ));
330     }
331     
332     function ActivityFilterForm() {
333         $fields = new FieldSet();
334         $fields->push(new DateField('Date', _t('ActivityFilterForm.Date')));
335         $fields->push(new HiddenField('Type'));
336         $form = new Form(
337             $this,
338             'ActivityFilterForm',
339             $fields,
340             new FieldSet(new FormAction('doFilterActivities', _t('ActivityFilterForm.FilterActivities')))
341         );
342         $form->loadDataFrom($_GET);
343         if (!isset($_GET['Date'])) {
344             $form->loadDataFrom(array('Date' => date('d.m.Y')));
345         }
346         if (!isset($_GET['Type'])) {
347             $form->loadDataFrom(array('Type' => 'InOrders'));
348         }
349         return $form;
350     }
351     
352     function doFilterActivities($data, $form) {
353         if (!isset($data['Date']) || !($date = date('d.m.Y', strtotime($data['Date'])))) {
354             $date = date('d.m.Y');
355         }
356         if (isset($data['Type']) && in_array($data['Type'], array('InOrders', 'OutOrders', 'CurrentOrders'))) {
357             $type = $data['Type'];
358         } else {
359             $type = 'InOrders';
360         }
361         return $this->redirect($this->Link('date_activity') . "?Date={$date}&Type={$type}");
362     }
363     
364     function OrdersMenu() {
365         $menu = new DataObjectSet();    
366         
367         $item = new ArrayData(array(
368             'Type' => 'NewOrders',
369             'Link' => $this->Link('orders') . "?Type=NewOrders",
370             'Title' => _t('OrdersMenu.NewOrdersTitle'),
371             'Current' => (!isset($_GET['Type']) || ($_GET['Type'] == 'NewOrders')) ? 1 : 0,
372         ));
373         $menu->push($item);
374                 
375         $item = new ArrayData(array(
376             'Type' => 'QueryOrders',
377             'Link' => $this->Link('orders') . "?Type=QueryOrders",
378             'Title' => _t('OrdersMenu.QueryOrdersTitle'),
379             'Current' => (isset($_GET['Type']) && ($_GET['Type'] == 'QueryOrders')) ? 1 : 0,
380         ));
381         $menu->push($item);
382         
383         $item = new ArrayData(array(
384             'Type' => 'PayedOrders',
385             'Link' => $this->Link('orders') . "?Type=PayedOrders",
386             'Title' => _t('OrdersMenu.PayedOrdersTitle'),
387             'Current' => (isset($_GET['Type']) && ($_GET['Type'] == 'PayedOrders')) ? 1 : 0,
388         ));
389         $menu->push($item);
390         
391         return $menu;
392     }
393     
394     function orders() {
395         if (isset($_GET['Type']) && in_array($_GET['Type'], array('NewOrders', 'QueryOrders', 'PayedOrders'))) {
396             $type = $_GET['Type'];
397         } else {
398             $type = 'NewOrders';
399         }
400         
401         $start = 0;
402         if (isset($_GET['start'])) {
403             $start = (int)$_GET['start'];
404         }
405         $count = 20;
406         switch($type) {
407             case 'NewOrders':
408                 $orders = DataObject::get('BookingOrder', "Status = 'New'", 'ID DESC', '', "{$start},{$count}");
409                 break;
410             case 'QueryOrders':
411                 $orders = DataObject::get('BookingOrder', "Status = 'Query'", 'ID DESC', '', "{$start},{$count}");
412                 break;
413             case 'PayedOrders':
414                 $orders = DataObject::get('BookingOrder', "Status = 'Paid'", 'ID DESC', '', "{$start},{$count}");
415                 break;
416         }       
417         return $this->customise(array(          
418             'OrdersList' => $orders,
419         ));
420     }
421         
422     function change_order_status() {
423         $rs = 0;
424         if (isset($_GET['OrderID']) && ($order = DataObject::get_by_id('BookingOrder', (int)$_GET['OrderID']))) {
425             if (isset($_GET['Status']) && in_array($_GET['Status'], $order->dbObject('Status')->enumValues())) {
426                 $order->Status = $_GET['Status'];
427                 $order->write();
428                 $rs = 1;
429             }
430         }
431         if ($this->isAjax()) {
432             return json_encode(array('rs' => $rs));
433         }
434         return $this->redirectBack();
435     }
436 }
437 
[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