You are here

class PricingEvent in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

@file contains PricingEvent.

Hierarchy

Expanded class hierarchy of PricingEvent

File

modules/rooms_pricing/includes/rooms_pricing.pricing_event.inc, line 8
contains PricingEvent.

View source
class PricingEvent extends RoomsEvent implements PricingEventInterface {

  /**
   * The amount for this period.
   *
   * @var int
   */
  public $amount;

  /**
   * The operation to perform.
   *
   * @var string
   */
  public $operation;

  /**
   * Constructs a BookingPrice item.
   *
   * @param int $unit_id
   *   The unit ID.
   * @param int $amount
   *   The booking amount.
   * @param DateTime $start_date
   *   The start date of the event.
   * @param DateTime $end_date
   *   The start date of the event.
   * @param string $operation
   *   The operation to perform.
   */
  public function __construct($unit_id, $amount, $start_date, $end_date, $operation = '') {
    $this->unit_id = $unit_id;
    $this->amount = $amount;
    $this->start_date = $start_date;
    $this->end_date = $end_date;
    $this->operation = $operation;
  }

  /**
   * {@inheritdoc}
   */
  protected function createEvent(DateTime $start_date, DateTime $end_date) {
    return new PricingEvent($this->unit_id, $this->amount, $start_date, $end_date, $this->operation);
  }

  /**
   * {@inheritdoc}
   */
  public function applyOperation($amount, $operation) {
    switch ($operation) {
      case ROOMS_REPLACE:
        $this->amount = $amount;
        break;
      case ROOMS_ADD:
        $this->amount = $this->amount + $amount;
        break;
      case ROOMS_SUB:
        $this->amount = $this->amount - $amount;
        break;
      case ROOMS_INCREASE:
        $this->amount = $this->amount + $this->amount * ($amount / 100);
        break;
      case ROOMS_DECREASE:
        $this->amount = $this->amount - $this->amount * ($amount / 100);
        break;
      default:
        break;
    }
  }

  /**
   * {@inheritdoc}
   */
  public function formatJson() {
    $amount = $this->amount;
    $event = array(
      "id" => $amount,
      "start" => $this
        ->startYear() . '-' . $this
        ->startMonth('m') . '-' . $this
        ->startDay('d') . 'T13:00:00',
      "end" => $this
        ->endYear() . '-' . $this
        ->endMonth('m') . '-' . $this
        ->endDay('d') . 'T13:00:00',
    );

    // Set the color.
    if ($amount < 100) {
      $event['color'] = variable_get('rooms_price_low_value_color', '#F3C776');
      $event['title'] = $amount;
    }
    elseif ($amount >= 100) {
      $event['color'] = variable_get('rooms_price_high_value_color', '#9DDC9D');
      $event['title'] = $amount;
    }
    return $event;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PricingEvent::$amount public property The amount for this period.
PricingEvent::$operation public property The operation to perform.
PricingEvent::applyOperation public function Applies an operation against a Price event. Overrides PricingEventInterface::applyOperation
PricingEvent::createEvent protected function Creates a new event Overrides RoomsEvent::createEvent
PricingEvent::formatJson public function Returns event in a format amenable to FullCalendar display or generally sensible json. Overrides PricingEventInterface::formatJson
PricingEvent::__construct public function Constructs a BookingPrice item.
RoomsEvent::$end_date public property The end date for the event.
RoomsEvent::$start_date public property The default state for the room if it has no specific booking.
RoomsEvent::$unit_id public property The booking unit the event is relevant to
RoomsEvent::diff public function Returns the date interval between end and start date. Overrides RoomsEventInterface::diff
RoomsEvent::endDay public function Returns the booking end day. Overrides RoomsEventInterface::endDay
RoomsEvent::endMonth public function Returns the booking end month. Overrides RoomsEventInterface::endMonth
RoomsEvent::endYear public function Returns the booking end year. Overrides RoomsEventInterface::endYear
RoomsEvent::sameMonth public function Checks if the event starts and ends in the same month. Overrides RoomsEventInterface::sameMonth
RoomsEvent::sameYear public function Checks if the event starts and ends in the same year. Overrides RoomsEventInterface::sameYear
RoomsEvent::startDay public function Returns the booking start day. Overrides RoomsEventInterface::startDay
RoomsEvent::startMonth public function Returns the booking start month. Overrides RoomsEventInterface::startMonth
RoomsEvent::startYear public function Returns the booking start year. Overrides RoomsEventInterface::startYear
RoomsEvent::transformToMonthlyEvents public function Takes a single event that spans several months and transforms it to monthly events - this assumes that the event is contained within a year Overrides RoomsEventInterface::transformToMonthlyEvents
RoomsEvent::transformToYearlyEvents public function Takes an event that spans several years and transforms it to yearly events Overrides RoomsEventInterface::transformToYearlyEvents