public static function loadSessionSchedule(NodeInterface $node) {
    if (!$node) {
      return FALSE;
    }

    $schedule = [
      'nid' => $node->id(),
      'dates' => [],
      'exclusions' => [],
    ];
    $dates = $node->field_session_time->referencedEntities();
    foreach ($dates as $date) {
      if (empty($date) || empty($date->field_session_time_days->getValue()) || empty($date->field_session_time_date->getValue())) {
        continue;
      }
      $schedule_item = [
        'frequency' => 'weekly',
        'days' => [],
        'period' => [],
        'time' => [],
      ];

      foreach ($date->field_session_time_days->getValue() as $value) {
        $schedule_item['days'][] = $value['value'];
      }

      $_period = $date->field_session_time_date->getValue()[0];
      $_from = DrupalDateTime::createFromTimestamp(strtotime($_period['value'] . 'Z'));
      $_to = DrupalDateTime::createFromTimestamp(strtotime($_period['end_value'] . 'Z'));

      $schedule_item['period']['from'] = $_from->format('Y-m-d');
      $schedule_item['period']['to'] = $_to->format('Y-m-d');

      $schedule_item['time']['from'] = $_from->format('H:i:s');
      $schedule_item['time']['to'] = $_to->format('H:i:s');

      if (!isset($schedule['from']) || $schedule_item['period']['from'] < $schedule['from']) {
        $schedule['from'] = $schedule_item['period']['from'];
      }
      if (!isset($schedule['to']) || $schedule_item['period']['to'] > $schedule['to']) {
        $schedule['to'] = $schedule_item['period']['to'];
      }

      $schedule['dates'][] = $schedule_item;
    }

    $schedule['exclusions'] = $node->field_session_exclusions->getValue();
    foreach ($schedule['exclusions'] as &$exclusion) {
      $exclusion['from'] = DrupalDateTime::createFromTimestamp(strtotime($exclusion['value'] . 'Z'))->format('Y-m-d\TH:i:s');
      $exclusion['to'] = DrupalDateTime::createFromTimestamp(strtotime($exclusion['end_value'] . 'Z'))->format('Y-m-d\TH:i:s');
      unset($exclusion['value'], $exclusion['end_value']);
    }

    return $schedule;
  }
public static function loadSessionSchedule(NodeInterface $node) {
    if (!$node) {
      return FALSE;
    }

    $schedule = [
      'nid' => $node->id(),
      'dates' => [],
      'exclusions' => [],
    ];
    $dates = $node->field_session_time->referencedEntities();
    foreach ($dates as $date) {
      if (empty($date) || empty($date->field_session_time_days->getValue()) || empty($date->field_session_time_date->getValue())) {
        continue;
      }
      $schedule_item = [
        'frequency' => 'weekly',
        'days' => [],
        'period' => [],
        'time' => [],
      ];

      foreach ($date->field_session_time_days->getValue() as $value) {
        $schedule_item['days'][] = $value['value'];
      }

      $_period = $date->field_session_time_date->getValue()[0];
      $_from = DrupalDateTime::createFromTimestamp(strtotime($_period['value'] . 'Z'));
      $_to = DrupalDateTime::createFromTimestamp(strtotime($_period['end_value'] . 'Z'));

      $schedule_item['period']['from'] = $_from->format('Y-m-d');
      $schedule_item['period']['to'] = $_to->format('Y-m-d');

      $schedule_item['time']['from'] = $_from->format('H:i:s');
      $schedule_item['time']['to'] = $_to->format('H:i:s');

      if (!isset($schedule['from']) || $schedule_item['period']['from'] < $schedule['from']) {
        $schedule['from'] = $schedule_item['period']['from'];
      }
      if (!isset($schedule['to']) || $schedule_item['period']['to'] > $schedule['to']) {
        $schedule['to'] = $schedule_item['period']['to'];
      }

      $schedule['dates'][] = $schedule_item;
    }

    $schedule['exclusions'] = $node->field_session_exclusions->getValue();
    foreach ($schedule['exclusions'] as &$exclusion) {
      $exclusion['from'] = DrupalDateTime::createFromTimestamp(strtotime($exclusion['value'] . 'Z'))->format('Y-m-d\TH:i:s');
      $exclusion['to'] = DrupalDateTime::createFromTimestamp(strtotime($exclusion['end_value'] . 'Z'))->format('Y-m-d\TH:i:s');
      unset($exclusion['value'], $exclusion['end_value']);
    }

    return $schedule;
  }
public static function loadSessionSchedule ( NodeInterface $ node ) { if ( ! $ node ) { return FALSE ; } $ schedule = [ 'nid' => $ node -> id ( ) , 'dates' => [ ] , 'exclusions' => [ ] , ] ; $ dates = $ node -> field_session_time -> referencedEntities ( ) ; foreach ( $ dates as $ date ) { if ( empty ( $ date ) || empty ( $ date -> field_session_time_days -> getValue ( ) ) || empty ( $ date -> field_session_time_date -> getValue ( ) ) ) { continue ; } $ schedule_item = [ 'frequency' => 'weekly' , 'days' => [ ] , 'period' => [ ] , 'time' => [ ] , ] ; foreach ( $ date -> field_session_time_days -> getValue ( ) as $ value ) { $ schedule_item [ 'days' ] [ ] = $ value [ 'value' ] ; } $ _period = $ date -> field_session_time_date -> getValue ( ) [ 0 ] ; $ _from = DrupalDateTime :: createFromTimestamp ( strtotime ( $ _period [ 'value' ] . 'Z' ) ) ; $ _to = DrupalDateTime :: createFromTimestamp ( strtotime ( $ _period [ 'end_value' ] . 'Z' ) ) ; $ schedule_item [ 'period' ] [ 'from' ] = $ _from -> format ( 'Y-m-d' ) ; $ schedule_item [ 'period' ] [ 'to' ] = $ _to -> format ( 'Y-m-d' ) ; $ schedule_item [ 'time' ] [ 'from' ] = $ _from -> format ( 'H:i:s' ) ; $ schedule_item [ 'time' ] [ 'to' ] = $ _to -> format ( 'H:i:s' ) ; if ( ! isset ( $ schedule [ 'from' ] ) || $ schedule_item [ 'period' ] [ 'from' ] < $ schedule [ 'from' ] ) { $ schedule [ 'from' ] = $ schedule_item [ 'period' ] [ 'from' ] ; } if ( ! isset ( $ schedule [ 'to' ] ) || $ schedule_item [ 'period' ] [ 'to' ] > $ schedule [ 'to' ] ) { $ schedule [ 'to' ] = $ schedule_item [ 'period' ] [ 'to' ] ; } $ schedule [ 'dates' ] [ ] = $ schedule_item ; } $ schedule [ 'exclusions' ] = $ node -> field_session_exclusions -> getValue ( ) ; foreach ( $ schedule [ 'exclusions' ] as & $ exclusion ) { $ exclusion [ 'from' ] = DrupalDateTime :: createFromTimestamp ( strtotime ( $ exclusion [ 'value' ] . 'Z' ) ) -> format ( 'Y-m-d\TH:i:s' ) ; $ exclusion [ 'to' ] = DrupalDateTime :: createFromTimestamp ( strtotime ( $ exclusion [ 'end_value' ] . 'Z' ) ) -> format ( 'Y-m-d\TH:i:s' ) ; unset ( $ exclusion [ 'value' ] , $ exclusion [ 'end_value' ] ) ; } return $ schedule ; }
Fetches sessions schedule.

@param NodeInterface $node
The session node.

@return array|bool
An array representing schedule.
Fetches sessions schedule .