/** * * Perform an 'item' request for the package item with 'packages' option set on. * * @param $checkfrontID * @param null|string $startDate * @param null|string $endDate * @param array $filters * @return CheckfrontAPIPackageResponse */ public function fetchPackage($checkfrontID, $startDate = null, $endDate = null, array $filters = array()) { static $cache = array(); $cacheKey = md5(implode('|', array($checkfrontID, $startDate, $endDate, implode('|', $filters)))); if (!isset($cache[$cacheKey])) { $params = self::request_params(__FUNCTION__, array('packages' => true, 'product_group_type' => 'N'), $this->buildDates($startDate, $endDate), $filters); $cache[$cacheKey] = CheckfrontAPIPackageResponse::create($this()->api(new CheckfrontAPIRequest("item/{$checkfrontID}", $params))); } return $cache[$cacheKey]; }
public static function factory($controller, CheckfrontAPIPackageResponse $packageResponse, array $info, array $data) { list($packageID, $startDate, $endDate, $linkType, $userType, $paymentType) = $info; // now build the form $fields = new FieldList(); // add a hidden accessKey field if set $accessKey = isset($data[CheckfrontForm::AccessKeyFieldName]) ? $data[CheckfrontForm::AccessKeyFieldName] : null; $fields->push(new HiddenField(CheckfrontForm::AccessKeyFieldName, '', $accessKey)); if ($userType === CheckfrontModule::UserTypeOrganiser) { // if organiser then add hidden start and end date fields for the actual booking $fields->merge(array(new HiddenField(CheckfrontForm::StartDateFieldName, '', $startDate), new HiddenField(CheckfrontForm::EndDateFieldName, '', $endDate))); } else { // if not organiser then let user specify their start and end dates $fields->merge(array(CheckfrontForm::make_date_field(CheckfrontForm::StartDateFieldName, 'Start Date', $startDate, $startDate, $endDate), CheckfrontForm::make_date_field(CheckfrontForm::EndDateFieldName, 'End Date', $endDate, $startDate, $endDate))); } // add the package items to the field list which will make the form as fields /** @var CheckfrontModel $item */ foreach ($packageResponse->getPackageItems() as $item) { if ($controller->shouldShowItem($item, $userType, $linkType)) { $fields->merge($item->fieldsForForm('form')); } } $fields->merge(new FieldList(array(new HiddenField(CheckfrontAccessKeyForm::AccessKeyFieldName, '', $accessKey)))); $actions = new FieldList(); $required = array(); // add the standard 'booking' fields (name etc) if ($response = CheckfrontModule::api()->fetchBookingForm()) { if ($response->isValid()) { // now add the booking fields to the fieldlist for the form $bookingFields = $response->getFormFields($required); $fields->merge($bookingFields); } $actions->push(new FormAction(static::SubmitButtonName, _t(__CLASS__ . ".SubmitButtonText"))); } $validator = new RequiredFields($required); $form = new CheckfrontPackageBookingForm($controller, static::FormName, $fields, $actions, $validator); return $form; }