Version: current

     1 <?php
     2 /*
     3  * Услуги заказов
     4  *
     5  * @author menedem
     6  */
     7 class OrderService extends BookingService {
     8     static $db = array(
     9         'HasAdditionalField' => 'Boolean', //флаг есть ли доп. поле
    10         'AdditionalFieldTitle' => 'Varchar(150)', //название дополнительного поля
    11         'SubsiteID' => 'Int', // подсайт услуги - чтоб показывать услуги заказа по подсайтам
    12     );
    13
    14     static function get_active($subsiteID=0) {
    15         $where = "Active = 1 AND SubsiteID = {$subsiteID}";
    16         return DataObject::get('OrderService', $where);
    17     }
    18
    19     function getCMSFields() {
    20         $fields = parent::getCMSFields();
    21         if (class_exists('Subsite') && ($subsites = DataObject::get('Subsite'))) {
    22             $allSubsites = array(0 => _t('Booking.RussianLang'));
    23             foreach($subsites as $subsite) {
    24                 $allSubsites[$subsite->ID] = $subsite->Title;
    25             }
    26             $fields->replaceField('SubsiteID', new DropdownField('SubsiteID', $this->fieldLabel('SubsiteID'), $allSubsites));
    27         } else {
    28             $fields->removeByName('SubsiteID');
    29         }
    30         return $fields;
    31     }
    32
    33     function OrderServiceAdditionalField($count=1, $value=1, $orderServiceAdditionalData=false) {
    34         if ($this->HasAdditionalField) {
    35             $html = '';
    36             for($i = 1; $i <= $count; $i++) {
    37                 $f = new TextField("AdditionalFieldData[$this->ID][$i]", $this->Title . ', ' . $this->AdditionalFieldTitle, (isset($orderServiceAdditionalData[$i-1]) ? $orderServiceAdditionalData[$i-1] : ''));
    38                 $f->addExtraAttribute('data-service_id', $this->ID);
    39                 if ($i > $value) {
    40                     $f->addExtraClass('hidden_field');
    41                 }
    42                 $html .= $f->fieldHolder();
    43             }
    44             return $html;
    45         }
    46         return false;
    47     }
    48
    49     function HTML($personCount, $value=0, $orderServiceAdditionalData=false) {
    50         $count = 1;
    51         $days = BookingPage::getFilterDatesPeriodLength();
    52
    53         switch ($this->MaxCountType) {
    54             case 'person':
    55                 $count = $personCount;
    56                 break;
    57             case 'day':
    58                 $count = $days;
    59                 break;
    60             case 'count':
    61                 $count = $this->MaxCount;
    62                 break;
    63         }
    64
    65         $selector = $this->getServiceSelector('OrderService', $count);
    66         $selector->setValue($value);
    67         $selector->addExtraAttribute('autocomplete', 'off');
    68
    69         return $this->customise(array(
    70             'RoomID' => $this->RoomID,
    71             'Count' => $count,
    72             'Person' => $personCount,
    73             'Day' => $days,
    74             'Service' => $this,
    75             'Selector' => $selector,
    76             'AdditionalField' => $this->OrderServiceAdditionalField($count, $value, $orderServiceAdditionalData),
    77         ))->renderWith('OrderService');
    78     }
    79 }

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