You are here

function bat_fullcalendar_configure in Booking and Availability Management Tools for Drupal 8

Same name and namespace in other branches
  1. 7 modules/bat_fullcalendar/bat_fullcalendar.module \bat_fullcalendar_configure()

Fullcalendar settings.

Parameters

$user_settings:

Return value

array

1 call to bat_fullcalendar_configure()
template_preprocess_bat_fullcalendar in modules/bat_fullcalendar/bat_fullcalendar.module
Theme function for FullCalendar

File

modules/bat_fullcalendar/bat_fullcalendar.module, line 57
Manages the display of FullCalendar and provides ways for other modules to easily modify it.

Code

function bat_fullcalendar_configure($user_settings) {
  $settings = [];
  $config = \Drupal::config('bat_fullcalendar.settings');
  foreach ($user_settings['batCalendar'] as $id => $user_setting) {

    // Set the scheduler license.
    $schedulerlicense = $config
      ->get('bat_fullcalendar_scheduler_key');
    switch ($schedulerlicense) {
      case 'gpl':
        $schedulerlicensekey = 'GPL-My-Project-Is-Open-Source';
        break;
      case 'non-commercial':
        $schedulerlicensekey = 'CC-Attribution-NonCommercial-NoDerivatives';
        break;
      case 'commercial':
        $schedulerlicensekey = $config
          ->get('bat_fullcalendar_scheduler_commercial_key');
        break;
      case 'none':
        $schedulerlicensekey = '';
        break;
      default:
        $schedulerlicensekey = '';
        break;
    }
    $calendar_views = 'timelineDay, timelineTenDay, timelineMonth, timelineYear';
    $default_view = 'timelineDay';
    $default_date = (new DateTime())
      ->format('Y-m-d');
    if ($user_setting['eventGranularity'] == 'bat_daily') {
      $calendar_views = 'timelineThirtyDay, timelineYear';
      $default_view = 'timelineThirtyDay';
      $default_date = (new DateTime())
        ->modify('-5 days')
        ->format('Y-m-d');
    }
    elseif ($user_setting['eventGranularity']) {
      $calendar_views = 'timelineDay, timelineTenDay, timelineMonth';
      $default_view = 'timelineDay';
    }
    if (isset($user_setting['views']) && !empty($user_setting['views'])) {
      $calendar_views = $user_setting['views'];
    }
    if (isset($user_setting['defaultView']) && !empty($user_setting['defaultView'])) {
      $default_view = $user_setting['defaultView'];
    }
    if (!isset($user_setting['businessHours'])) {
      $business_hours = [
        'start' => '00:00',
        'end' => '24:00',
        'dow' => [
          0,
          1,
          2,
          3,
          4,
          5,
          6,
        ],
      ];
    }
    else {
      $business_hours = $user_setting['businessHours'];
    }
    $user_timezone = new DateTimeZone(date_default_timezone_get());
    $gmt_timezone = new DateTimeZone('GMT');
    $timezone_offset = $user_timezone
      ->getOffset(new DateTime('now', $gmt_timezone));
    $config = [
      'schedulerLicenseKey' => $schedulerlicensekey,
      'themeSystem' => 'standard',
      'unitType' => '',
      'unitIds' => '',
      'eventType' => '',
      'grouping_entity_type' => '',
      'grouping_ids' => '',
      'collapse_childrens' => 0,
      'eventGranularity' => $user_setting['eventGranularity'],
      'locale' => \Drupal::languageManager()
        ->getCurrentLanguage()
        ->getId(),
      'slotWidth' => FALSE,
      'calendarHeight' => 500,
      'editable' => TRUE,
      'selectable' => TRUE,
      'eventStartEditable' => TRUE,
      'eventDurationEditable' => TRUE,
      'headerLeft' => 'today, prev, next',
      'headerCenter' => 'title',
      'headerRight' => $calendar_views,
      'views' => $calendar_views,
      'defaultView' => $default_view,
      'viewsTimelineDayButtonText' => ':15 slots',
      'viewsTimelineDaySlotDuration' => '00:15',
      'viewsTimelineDaySlotLabelFormat' => FALSE,
      'viewsTimelineDayTitleFormat' => '',
      'viewsTimelineSevenDayButtonText' => '7 days',
      'viewsTimelineSevenDayDuration' => [
        'days' => 7,
      ],
      'viewsTimelineSevenDaySlotDuration' => '01:00',
      'viewsTimelineSevenDayTitleFormat' => '',
      'viewsTimelineSevenDaySlotLabelFormat' => FALSE,
      'viewsTimelineTenDayButtonText' => '10 days',
      'viewsTimelineTenDayDuration' => [
        'days' => 10,
      ],
      'viewsTimelineTenDaySlotDuration' => '01:00',
      'viewsTimelineTenDaySlotLabelFormat' => FALSE,
      'viewsTimelineTenDayTitleFormat' => '',
      'viewsTimelineThirtyDayButtonText' => '30 days',
      'viewsTimelineThirtyDayDuration' => [
        'days' => 30,
      ],
      'viewsTimelineThirtyDaySlotDuration' => '01:00',
      'viewsTimelineThirtyDaySlotLabelFormat' => FALSE,
      'viewsTimelineThirtyDayTitleFormat' => '',
      'viewsTimeline365DayButtonText' => '1 year',
      'viewsTimeline365DayDuration' => [
        'days' => 365,
      ],
      'viewsTimeline365DaySlotLabelFormat' => FALSE,
      'viewsTimeline365DayTitleFormat' => '',
      'viewsAgendaOneDayButtonText' => 'day',
      'viewsAgendaOneDayDuration' => [
        'days' => 1,
      ],
      'viewsAgendaSevenDayButtonText' => 'week',
      'viewsAgendaSevenDayDuration' => [
        'days' => 7,
      ],
      'resourceAreaWidth' => '25%',
      'resourceLabelText' => t('Types'),
      'errorMessage' => t('Action not allowed. User may not have the right permissions.'),
      'businessHours' => $business_hours,
      'selectConstraint' => NULL,
      'scrollTime' => '06:00:00',
      'minTime' => '00:00:00',
      'maxTime' => '24:00:00',
      'hiddenDays' => [],
      'validRange' => NULL,
      'defaultDate' => $default_date,
      'repeatEventTitle' => TRUE,
      'showBackgroundEventTitle' => FALSE,
      'enableModal' => TRUE,
      'customButtons' => [],
      'eventOrder' => 'title',
      'titleFormat' => '',
      'slotLabelFormat' => FALSE,
      'defaultTimedEventDuration' => '00:00:00',
      'selectAllowBusinessHours' => FALSE,
      'groupByResource' => FALSE,
      'groupByDateAndResource' => FALSE,
      'allDaySlot' => TRUE,
      'hideResourceTypes' => FALSE,
      'firstDay' => 0,
      'viewsAgendaButtonText' => '',
      'viewsWeekButtonText' => '',
      'viewsDayButtonText' => '',
      'allDayDefault' => NULL,
      'dialogOptions' => bat_fullcalendar_modal_style('default'),
    ];
    $settings['batCalendar'][$id] = array_replace_recursive($config, $user_setting);

    // Allow other modules to alter further.
    \Drupal::moduleHandler()
      ->alter('bat_calendar_settings', $settings);
  }
  return $settings;
}