You are here

protected function AvailabilityCalendarsCssGenerator::createStatesCss in Availability Calendars 6.2

Same name and namespace in other branches
  1. 7.2 availability_calendars.styles.inc \AvailabilityCalendarsCssGenerator::createStatesCss()

Return value

string The CSS for the states

1 call to AvailabilityCalendarsCssGenerator::createStatesCss()
AvailabilityCalendarsCssGenerator::createCss in ./availability_calendars.styles.inc
Creates the css.

File

./availability_calendars.styles.inc, line 580

Class

AvailabilityCalendarsCssGenerator

Code

protected function createStatesCss() {
  $category = 'states';
  $splitDay = $this
    ->getStyle($category, 'split-day');
  $states = availability_calendars_get_states();
  $css = empty($splitDay) ? "/* Whole days only*/\n" : "/* Whole days, -pm states are IE6 fallback: IE6 does not display split states: show PM state as whole day state */\n";
  foreach ($states as $class => $stateRecord) {
    $state = $stateRecord['class'];

    // Whole day state
    $css .= $this
      ->cssSelector(empty($splitDay) ? ".{$state} > span" : ".{$state} > span, .{$state}-pm > span");
    $css .= $this
      ->addCssColorDeclaration($category, array(
      $class => 'background-color',
    ));
    $css .= $this
      ->cssSelectorEnd();
  }
  $splitDay = $this
    ->getStyle($category, 'split-day');
  if (!empty($splitDay)) {
    $pattern = '/^([0-9.]+)([a-zA-Z%]*)$/';
    $value = $this
      ->getStyle('days', 'width');
    $parts = array();
    preg_match($pattern, $value, $parts);
    $cellWidth = $parts[1];
    $cellWidthUnit = count($parts) > 2 ? $parts[2] : 'px';
    $value = $this
      ->getStyle('days', 'height');
    $parts = array();
    preg_match($pattern, $value, $parts);
    $cellHeight = $parts[1];
    $cellHeightUnit = count($parts) > 2 ? $parts[2] : 'px';
    $css .= "/* Split days */\n";

    // Styles for the outer span within the td that contains the day number and an absolutle positioned span
    $css .= $this
      ->cssSelector('.cal td > span');
    $css .= $this
      ->cssDeclaration('display', 'block');
    $css .= $this
      ->cssDeclaration('position', 'relative');
    $css .= $this
      ->cssDeclaration('width', $cellWidth . $cellWidthUnit);
    $css .= $this
      ->cssDeclaration('height', $cellHeight . $cellHeightUnit);
    $css .= $this
      ->cssDeclaration('line-height', $cellHeight . $cellHeightUnit);
    $css .= $this
      ->addCssDeclaration('days', 'text-align');
    $css .= $this
      ->addCssDeclaration('days', 'vertical-align');
    $css .= $this
      ->cssDeclaration('z-index', 1);
    $css .= $this
      ->cssSelectorEnd();

    // Styles for the inner span that takes care of the background coloring of split days
    $css .= $this
      ->cssSelector('.cal td > span > span');
    $css .= $this
      ->cssDeclaration('position', 'absolute');
    $css .= $this
      ->cssDeclaration('top', '0');
    $css .= $this
      ->cssDeclaration('left', '0');
    $css .= $this
      ->cssDeclaration('z-index', -1);
    $css .= $this
      ->cssDeclaration('border-style', 'solid');
    switch ($splitDay) {
      case '/':
        $css .= $this
          ->cssDeclaration('width', '0');
        $css .= $this
          ->cssDeclaration('height', '0');
        $css .= $this
          ->cssDeclaration('border-left-width', floor($cellWidth / 2) . $cellWidthUnit);
        $css .= $this
          ->cssDeclaration('border-top-width', floor($cellHeight / 2) . $cellHeightUnit);
        $css .= $this
          ->cssDeclaration('border-right-width', ceil($cellWidth / 2) . $cellWidthUnit);
        $css .= $this
          ->cssDeclaration('border-bottom-width', ceil($cellHeight / 2) . $cellHeightUnit);
        break;
      case '\\':
        $css .= $this
          ->cssDeclaration('width', '0');
        $css .= $this
          ->cssDeclaration('height', '0');
        $css .= $this
          ->cssDeclaration('border-left-width', floor($cellWidth / 2) . $cellWidthUnit);
        $css .= $this
          ->cssDeclaration('border-bottom-width', floor($cellHeight / 2) . $cellHeightUnit);
        $css .= $this
          ->cssDeclaration('border-right-width', ceil($cellWidth / 2) . $cellWidthUnit);
        $css .= $this
          ->cssDeclaration('border-top-width', ceil($cellHeight / 2) . $cellHeightUnit);
        break;
      case '|':
        $css .= $this
          ->cssDeclaration('width', '0');
        $css .= $this
          ->addCssLengthDeclaration('days', 'height');
        $css .= $this
          ->cssDeclaration('border-left-width', floor($cellWidth / 2) . $cellWidthUnit);
        $css .= $this
          ->cssDeclaration('border-right-width', ceil($cellWidth / 2) . $cellWidthUnit);
        break;
      case '―':
        $css .= $this
          ->addCssLengthDeclaration('days', 'width');
        $css .= $this
          ->cssDeclaration('height', '0');
        $css .= $this
          ->cssDeclaration('border-top-width', floor($cellHeight / 2) . $cellHeightUnit);
        $css .= $this
          ->cssDeclaration('border-bottom-width', ceil($cellHeight / 2) . $cellHeightUnit);
        break;
    }
    $css .= $this
      ->cssSelectorEnd();
    foreach ($states as $class => $stateRecord) {
      $state = $stateRecord['class'];
      $cssAm = $this
        ->cssSelector(".{$state}-am > span > span, .{$state} > span > span");
      $cssPm = $this
        ->cssSelector(".{$state}-pm > span > span, .{$state} > span > span");
      switch ($splitDay) {
        case '/':
          $cssAm .= $this
            ->addCssColorDeclaration($category, array(
            $state => 'border-left-color',
          ));
          $cssAm .= $this
            ->addCssColorDeclaration($category, array(
            $state => 'border-top-color',
          ));
          $cssPm .= $this
            ->addCssColorDeclaration($category, array(
            $state => 'border-right-color',
          ));
          $cssPm .= $this
            ->addCssColorDeclaration($category, array(
            $state => 'border-bottom-color',
          ));
          break;
        case '\\':
          $cssAm .= $this
            ->addCssColorDeclaration($category, array(
            $state => 'border-left-color',
          ));
          $cssAm .= $this
            ->addCssColorDeclaration($category, array(
            $state => 'border-bottom-color',
          ));
          $cssPm .= $this
            ->addCssColorDeclaration($category, array(
            $state => 'border-right-color',
          ));
          $cssPm .= $this
            ->addCssColorDeclaration($category, array(
            $state => 'border-top-color',
          ));
          break;
        case '|':
          $cssAm .= $this
            ->addCssColorDeclaration($category, array(
            $state => 'border-left-color',
          ));
          $cssPm .= $this
            ->addCssColorDeclaration($category, array(
            $state => 'border-right-color',
          ));
          break;
        case '―':
          $cssAm .= $this
            ->addCssColorDeclaration($category, array(
            $state => 'border-top-color',
          ));
          $cssPm .= $this
            ->addCssColorDeclaration($category, array(
            $state => 'border-bottom-color',
          ));
          break;
      }
      $cssAm .= $this
        ->cssSelectorEnd();
      $cssPm .= $this
        ->cssSelectorEnd();
      $css .= $cssAm;
      $css .= $cssPm;
    }
  }
  return $css;
}