public function groupByActivity($result, $rooms, $classnames = []) {
    if (empty($result)) {
      return FALSE;
    }
    $date_keys = $formatted_result = [];

    // Create weekdays array.
    foreach ($result as $day => $data) {
      $date_keys[$day] = [];
    }
    $arr_date_keys = array_keys($date_keys);
    $first = reset($arr_date_keys);
    $last = end($arr_date_keys);
    $first = DrupalDateTime::createFromFormat('Y-m-d', $first)->format('F jS');
    $last = DrupalDateTime::createFromFormat('Y-m-d', $last)->format('F jS');
    $formatted_result['header'] = [
      'dates' => $first . ' - ' . $last,
    ];

    // Create activities array pass weekdays array to each.
    foreach ($result as $day => $data) {
      foreach ($data as $key => $session) {
        // Additionally filter by room.
        if (!empty($rooms) && !in_array($session->location . '||' . $session->room, $rooms)) {
          $location_found = FALSE;
          foreach ($rooms as $room) {
            // Keep locations with no selected rooms (means all are selected).
            if (strpos($room, $session->location) !== FALSE) {
              $location_found = TRUE;
            }
          }
          if ($location_found) {
            unset($result[$day][$key]);
            continue;
          }
        }
        if ($classnames && !in_array($session->name, $classnames)) {
          unset($result[$day][$key]);
          continue;
        }

        $formatted_result['content'][$session->location][$session->name] = [
          'room' => $session->room,
          'dates' => $date_keys
        ];
      }
    }
    foreach ($result as $day => $data) {
      foreach ($data as $session) {
        $formatted_result['content'][$session->location][$session->name]['dates'][$day][] = [
          'time' => $session->time_start . '-' . $session->time_end,
          'category' => $session->category,
        ];
      }
    }
    return $formatted_result;
  }
public function groupByActivity($result, $rooms, $classnames = []) {
    if (empty($result)) {
      return FALSE;
    }
    $date_keys = $formatted_result = [];

    // Create weekdays array.
    foreach ($result as $day => $data) {
      $date_keys[$day] = [];
    }
    $arr_date_keys = array_keys($date_keys);
    $first = reset($arr_date_keys);
    $last = end($arr_date_keys);
    $first = DrupalDateTime::createFromFormat('Y-m-d', $first)->format('F jS');
    $last = DrupalDateTime::createFromFormat('Y-m-d', $last)->format('F jS');
    $formatted_result['header'] = [
      'dates' => $first . ' - ' . $last,
    ];

    // Create activities array pass weekdays array to each.
    foreach ($result as $day => $data) {
      foreach ($data as $key => $session) {
        // Additionally filter by room.
        if (!empty($rooms) && !in_array($session->location . '||' . $session->room, $rooms)) {
          $location_found = FALSE;
          foreach ($rooms as $room) {
            // Keep locations with no selected rooms (means all are selected).
            if (strpos($room, $session->location) !== FALSE) {
              $location_found = TRUE;
            }
          }
          if ($location_found) {
            unset($result[$day][$key]);
            continue;
          }
        }
        if ($classnames && !in_array($session->name, $classnames)) {
          unset($result[$day][$key]);
          continue;
        }

        $formatted_result['content'][$session->location][$session->name] = [
          'room' => $session->room,
          'dates' => $date_keys
        ];
      }
    }
    foreach ($result as $day => $data) {
      foreach ($data as $session) {
        $formatted_result['content'][$session->location][$session->name]['dates'][$day][] = [
          'time' => $session->time_start . '-' . $session->time_end,
          'category' => $session->category,
        ];
      }
    }
    return $formatted_result;
  }
public function groupByActivity ( $ result , $ rooms , $ classnames = [ ] ) { if ( empty ( $ result ) ) { return FALSE ; } $ date_keys = $ formatted_result = [ ] ; // Create weekdays array. foreach ( $ result as $ day => $ data ) { $ date_keys [ $ day ] = [ ] ; } $ arr_date_keys = array_keys ( $ date_keys ) ; $ first = reset ( $ arr_date_keys ) ; $ last = end ( $ arr_date_keys ) ; $ first = DrupalDateTime :: createFromFormat ( 'Y-m-d' , $ first ) -> format ( 'F jS' ) ; $ last = DrupalDateTime :: createFromFormat ( 'Y-m-d' , $ last ) -> format ( 'F jS' ) ; $ formatted_result [ 'header' ] = [ 'dates' => $ first . ' - ' . $ last , ] ; // Create activities array pass weekdays array to each. foreach ( $ result as $ day => $ data ) { foreach ( $ data as $ key => $ session ) { // Additionally filter by room. if ( ! empty ( $ rooms ) && ! in_array ( $ session -> location . '||' . $ session -> room , $ rooms ) ) { $ location_found = FALSE ; foreach ( $ rooms as $ room ) { // Keep locations with no selected rooms (means all are selected). if ( strpos ( $ room , $ session -> location ) !== FALSE ) { $ location_found = TRUE ; } } if ( $ location_found ) { unset ( $ result [ $ day ] [ $ key ] ) ; continue ; } } if ( $ classnames && ! in_array ( $ session -> name , $ classnames ) ) { unset ( $ result [ $ day ] [ $ key ] ) ; continue ; } $ formatted_result [ 'content' ] [ $ session -> location ] [ $ session -> name ] = [ 'room' => $ session -> room , 'dates' => $ date_keys ] ; } } foreach ( $ result as $ day => $ data ) { foreach ( $ data as $ session ) { $ formatted_result [ 'content' ] [ $ session -> location ] [ $ session -> name ] [ 'dates' ] [ $ day ] [ ] = [ 'time' => $ session -> time_start . '-' . $ session -> time_end , 'category' => $ session -> category , ] ; } } return $ formatted_result ; }
Group results by Activity & Location.
Group results by Activity & Location .