Get schedule.

@return array
A schedule. It could be of 2 types:
- day: all classes within classes key
- week: all classes grouped by day within days key
5941
public function getSchedule() {
    // Use cached schedule if already processed.
    if ($this->schedule) {
      return $this->schedule;
    }

    $conf = $this->configFactory->get('openy_group_schedules.settings');
    $days_range = is_numeric($conf->get('days_range')) ? $conf->get('days_range') : 14;

    $filter_date = DrupalDateTime::createFromTimestamp($this->parameters['filter_timestamp'], $this->timezone);
    $current_date = DrupalDateTime::createFromTimestamp(REQUEST_TIME, $this->timezone)->format(GroupexRequestTrait::$dateFilterFormat);
    // Define end date of shown items as 2 weeks.
    $end_date = DrupalDateTime::createFromTimestamp(REQUEST_TIME + 86400 * $days_range, $this->timezone);

    // Prepare classes items.
    $items = [];

    foreach ($this->processedData as $item) {
      // If item date more than 1 week in future skip it.
      $item_date = DrupalDateTime::createFromTimestamp($item->timestamp, $this->timezone);
      if ($item_date > $end_date) {
        continue;
      }
      $class_url_options = $this->parameters;
      // $class_url_options['class'] = $item->class_id; //doesn't exist in API, needs to be added through processData().
      $class_url_options['filter_date'] = $current_date;
      $class_url_options['filter_length'] = 'week';
      $class_url_options['groupex_class'] = 'groupex_table_class_individual';
      $class_url_options['view_mode'] = 'class';
      unset($class_url_options['instructor']);

      $instructor_url_options = $this->parameters;
      $instructor_url_options['filter_date'] = $current_date;
      $instructor_url_options['filter_length'] = 'week';

      $instructor_url_options['instructor'] = $item->instructor;
      // Here we need to remove redundant HTML if exists.
      // Example: Melissa T.<br><span class="fa fa-refresh" aria-hidden="true"></span><span class="sub">Lucy T.</span>
      $pos = strpos($item->instructor, '<span class="sub">');
      if (FALSE !== $pos) {
        $original_instructor = substr_replace($item->instructor, '', 0, $pos);
        $original_instructor = str_replace('<span class="sub">', '', $original_instructor);
        $original_instructor = str_replace('</span>', '', $original_instructor);
        $instructor_url_options['instructor'] = $original_instructor;
      }

      $instructor_url_options['class'] = 'any';
      $instructor_url_options['groupex_class'] = 'groupex_table_instructor_individual';
      unset($instructor_url_options['view_mode']);

      $date_url_options = $this->parameters;
      $date_url_options['filter_date'] = date('m/d/y', strtotime($item->date));
      $date_url_options['filter_length'] = 'day';
      $date_url_options['class'] = 'any';
      $date_url_options['groupex_class'] = 'groupex_table_class';
      unset($date_url_options['instructor']);
      unset($date_url_options['view_mode']);

      $items[$item->id] = [
        '#theme' => isset($this->parameters['groupex_class']) ? $this->parameters['groupex_class'] : 'groupex_class',
        '#class' => [
          'id' => trim($item->id),
          'name' => trim($item->title),
          'group' => trim($item->category),
          'description' => $item->desc,
          'address_1' => $item->address_1,
          'address_2' => trim($item->location),
          'date' => $item->date,
          'studio' => $item->studio,
          'date_short' => date('F, d', strtotime($item->date)),
          'time' => $item->start,
          'duration' => sprintf('%d min', trim($item->length)),
          'instructor' => $item->instructor,
//          'class_id' => $item->class_id, //doesn't exist in API, needs to be added through processData().
          'class_link' => Url::fromRoute('openy_group_schedules.all_schedules_search_results', [], ['query' => $class_url_options]),
          'instructor_link' => Url::fromRoute('openy_group_schedules.all_schedules_search_results', [], ['query' => $instructor_url_options]),
          'date_link' => Url::fromRoute('openy_group_schedules.all_schedules_search_results', [], ['query' => $date_url_options]),
          'calendar' => $item->calendar,
        ],
      ];
    }

    // Pack classes into the schedule.
    $schedule = [];

    // There 3 types of schedules.
    // Day: show classes for single day.
    // Week: show classes for week grouped by day.
    // Location: show classes for 1 day grouped by location.
    $schedule['type'] = isset($this->parameters['filter_length']) ? $this->parameters['filter_length'] : 'day';
    if (!empty($this->parameters['location']) && count($this->parameters['location']) > 1) {
      $schedule['type'] = 'location';
    }
    if (!empty($this->parameters['class']) && is_numeric($this->parameters['class'])) {
      $schedule['type'] = 'week';
    }
    if (!empty($this->parameters['instructor'])) {
      $schedule['type'] = 'instructor';
    }
    switch ($schedule['type']) {
      case 'day':
        $schedule['classes'] = [];
        foreach ($items as $id => $class) {
          $schedule['classes'][] = $class;
          $schedule['title'] = trim($this->enrichedData[$id]->location);
        }
        // Pass 'View This Week’s PDF' href if some location selected.
        if (!empty($this->parameters['location'])) {
          $location_id = $this->parameters['location'];
          $category = $this->parameters['category'] == 'any' ? NULL : $this->parameters['category'];
          $schedule['pdf_href'] = $this->groupexHelper->getPdfLink($location_id, $this->parameters['filter_timestamp'], $category);
        }

        // If no location selected show date instead of title.
        if (empty($this->parameters['location'])) {
          $schedule['title'] = $filter_date->format(GroupexRequestTrait::$dateFullFormat);
        }
        break;

      case 'week':
        $schedule['days'] = [];
        foreach ($items as $id => $class) {
          $schedule['days'][$this->enrichedData[$id]->day]['classes'][] = $class;
          $schedule['days'][$this->enrichedData[$id]->day]['day_short'] = DrupalDateTime::createFromFormat(GroupexRequestTrait::$dateFullFormat, $this->enrichedData[$id]->day, $this->timezone)->format('l, F j');
          $schedule['days'][$this->enrichedData[$id]->day]['date_link'] = $class['#class']['date_link'];
        }
        // Pass 'View This Week’s PDF' href if some location selected.
        if (!empty($this->parameters['location'])) {
          $location = $this->parameters['location'];
          $category = $this->parameters['category'] == 'any' ? NULL : $this->parameters['category'];
          $schedule['pdf_href'] = $this->groupexHelper->getPdfLink($location, $this->parameters['filter_timestamp'], $category);
        }

        // If no location selected show date instead of title.
        if (empty($this->parameters['location'])) {
          $schedule['day'] = $filter_date->format(GroupexRequestTrait::$dateFullFormat);
        }
        break;

      case 'location':
        $schedule['locations'] = [];
        $location_id = NULL;
        $locations_ids = \Drupal::entityQuery('mapping')
          ->condition('type', 'location')
          ->execute();
        $locations = \Drupal::entityManager()->getStorage('mapping')->loadMultiple($locations_ids);
        foreach ($items as $id => $class) {
          $short_location_name = trim($this->enrichedData[$id]->location);
          foreach ($locations as $location) {
            if ($location->get('name')->value == $short_location_name) {
              $field_groupex_id = $location->field_groupex_id->getValue();
              $location_id = isset($field_groupex_id[0]['value']) ? $field_groupex_id[0]['value'] : FALSE;
            }
          }
          $category = $this->parameters['category'] == 'any' ? NULL : $this->parameters['category'];
          $pdf_href = $this->groupexHelper->getPdfLink($location_id, $this->parameters['filter_timestamp'], $category);
          $schedule['locations'][$short_location_name]['classes'][] = $class;
          $schedule['locations'][$short_location_name]['pdf_href'] = $pdf_href;
        }
        $schedule['filter_date'] = date(GroupexRequestTrait::$dateFullFormat, $this->parameters['filter_timestamp']);
        break;

      case 'instructor':
        // Filter classes by instructor.
        $schedule['days'] = [];

        foreach ($items as $id => $class) {
          if ($class['#class']['instructor'] == $this->parameters['instructor']) {
            $class_date = DrupalDateTime::createFromFormat(
              GroupexRequestTrait::$dateFullFormat,
              $this->enrichedData[$id]->day,
              $this->timezone
            );

            $schedule['days'][$this->enrichedData[$id]->day]['classes'][] = $class;
            $schedule['days'][$this->enrichedData[$id]->day]['day_short'] = $class_date->format('l, F j');

            // Adjust query options to fit class date.
            $date_url_options['filter_date'] = $class_date->format(GroupexRequestTrait::$dateFilterFormat);
            $date_url_options['filter_timestamp'] = $class_date->format('U');

            $url = Url::fromRoute('openy_group_schedules.all_schedules_search_results', [], ['query' => $date_url_options]);
            $schedule['days'][$this->enrichedData[$id]->day]['date_link'] = $url;
          }
        }

        $schedule['instructor_location'] = t('Schedule for <span class="name"><span class="icon icon-user"></span>@name</span>', [
          '@name' => reset($schedule['days'])['classes'][0]['#class']['instructor'],
        ]);

        // Pass 'View This Week’s PDF' href if some location selected.
        if (!empty($this->parameters['location'])) {
          $location = $this->parameters['location'];
          $category = $this->parameters['category'] == 'any' ? NULL : $this->parameters['category'];
          $schedule['pdf_href'] = $this->groupexHelper->getPdfLink($location, $this->parameters['filter_timestamp'], $category);
        }

        // If no location selected show date instead of title.
        if (empty($this->parameters['location'])) {
          $schedule['day'] = $filter_date->format(GroupexRequestTrait::$dateFullFormat);
        }
        break;
    }

    $this->schedule = $schedule;
    return $this->schedule;
  }
496457
public static function getSlots()
    {
        $slots = array();

        foreach (array_keys(WindowMaker::getStartTimeChoices()) as $hour)
        {
            for ($i=0; $i<14; $i++)
            {
                $date = new \DateTime('+'.$i.' days');

                $slots[$hour.':00'][$date->format('Y-m-d')] = null;
            }
        }

        return $slots;
    }
45637
private function getScheduleHours()
    {
        if (!$this->scheduleHours) {
            $jsonHelper          = new JSONHelper();
            $hoursString         = $this->contactClient->getScheduleHours();
            $this->scheduleHours = $jsonHelper->decodeArray($hoursString, 'ScheduleHours');
        }

        return $this->scheduleHours;
    }
1243932
protected function getDays() {
        if (!$this->_days) {
            $this->_days = new DayList($this->version, $this->solution['resourceType']);
        }

        return $this->_days;
    }
50703
public function getDates()
    {
        static $dates = [];

        $class = get_class($this);

        if (! isset($dates[$class])) {
            static::$dispatcher->dispatch(
                new ConfigureModelDates($this, $this->dates)
            );

            $dates[$class] = $this->dates;
        }

        return $dates[$class];
    }
430902
public function getStatuses()
    {
        $schedules = clone $this->getCollection()
            ->setOrder('status', Zend_Db_Select::SQL_ASC);
        $schedules->getSelect()
            ->group('status')
            ->reset(Zend_Db_Select::COLUMNS)
            ->columns('status');
        $statuses = $schedules->getConnection()
            ->fetchCol($schedules->getSelect());
        $statusArray = array();
        foreach ($statuses as $status) {
            $statusArray[$status] = $status;
        }
        return $statusArray;
    }
1236524
public function makeSchedule()
    {
        // Pull out the first page to distribute it; then delete.
        $items = $this->getRows();
        $id = $this->getCurrentPageId();
        $this->deletePage($id);

        $this->date = clone $this->getStartDate();
        $this->avoidHolidaysAndWeekdaysOff();
        $this->stats['start date'] = $this->date->format($this->getPageIdFormat());
        $this->stats['hours per day'] = $this->getHoursPerDay();
        $this->stats['total items'] = count($items);
        $this->stats['dates off'] = array();
        $this->setDatePage($this->date);

        $dayTotal = 0;
        $this->stats['total hours'] = 0;
        while (($item = array_shift($items))) {
            $this->stats['total hours'] += $item[$this->getHoursKey()];
            $this->processItem($item, $item[$this->getHoursKey()], $dayTotal);
        }
        $this->stats['end date'] = $this->date->format($this->getPageIdFormat());

        if ($this->todoStatsPage) {
            $this->addStatsPage($this->todoStatsPage);
        }

        return $this;
    }
1124305
public function get()
    {
        // Pre-populating the 'calendardata' is optional, if we don't have it
        // already we fetch it from the backend.
        if (!isset($this->objectData['calendardata'])) {
            $this->objectData = $this->caldavBackend->getSchedulingObject($this->objectData['principaluri'], $this->objectData['uri']);
        }

        return $this->objectData['calendardata'];
    }
1314056
public function getRescheduledTime()
    {
        $currentTime = $this->getTime();

        // Add one day
        $rescheduledTime = mktime(date('H', $currentTime),
            date('i', $currentTime),
            date('s', $currentTime),
            date('n', $currentTime),
            date('j', $currentTime) + 1,
            date('Y', $currentTime)
        );

        // Adjusts the scheduled hour
        $rescheduledTime = $this->adjustHour($rescheduledTime);
        $rescheduledTime = $this->adjustTimezone($rescheduledTime);

        return $rescheduledTime;
    }
554179
public function get($schedule)
    {
        $id = null;
        if ($schedule instanceof HpsPayPlanSchedule) {
            $id = $schedule->scheduleKey;
        } else {
            $id = $schedule;
        }
        $result = $this->doRequest(null, array(
            'verb'     => 'GET',
            'endpoint' => 'schedules/'.$id,
        ));
        return $this->hydrateObject($result, 'HpsPayPlanSchedule');
    }
1294897
public function schedule()
    {
        $createdAtTime = $this->getCronTimestamp();
        $scheduledAtTime = $createdAtTime;

        /* @var $schedule Schedule */
        $schedule = $this->scheduleCollection->getNewEmptyItem();
        $schedule->setJobCode(Export::JOB_CODE)
            ->setStatus(Schedule::STATUS_PENDING)
            ->setCreatedAt(strftime('%Y-%m-%d %H:%M:%S', $createdAtTime))
            ->setScheduledAt(strftime('%Y-%m-%d %H:%M', $scheduledAtTime));

        $schedule->save();

        return $schedule;
    }
1023001
public function get()
    {
        // Pre-populating the 'calendardata' is optional, if we don't have it
        // already we fetch it from the backend.
        if (!isset($this->objectData['calendardata'])) {
            $this->objectData = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $this->objectData['uri']);
        }

        return $this->objectData['calendardata'];
    }
279980
public function get_columns() {

		// Lowercase day, for column key
		$day = strtolower( date( 'l', $this->day_start ) );

		// Return Week & Day
		return array(
			'hour' => sprintf( esc_html__( 'Wk. %s', 'wp-event-calendar' ), date_i18n( 'W', $this->today ) ),
			$day   => date_i18n( 'l, F j, Y', $this->day_start ),
		);
	}
942615
public function getCalendar() : ?string 
    {
        if ( ! $this->hasCalendar()) {
            $this->setCalendar($this->getDefaultCalendar());
        }
        return $this->calendar;
    }
1358953
public function build()
    {
        if(null == $this->scheduleBuilder) {
            $this->scheduleBuilder = SimpleScheduleBuilder::simpleSchedule();
        }

        if (null == $this->startTime) {
            $this->startTime = new \DateTime();
        }

        $trigger = $this->scheduleBuilder->build();

        $trigger->setCalendarName($this->calendarName);
        $trigger->setDescription($this->description);
        $trigger->setStartTime($this->startTime);
        $trigger->setEndTime($this->endTime);

        if(null == $this->key) {
            $this->key = new Key(Key::createUniqueName(null), null);
        }

        $trigger->setKey($this->key);

        if($this->jobKey) {
            $trigger->setJobKey($this->jobKey);
        }

        $trigger->setPriority($this->priority);

        if($this->jobDataMap) {
            $trigger->setJobDataMap($this->jobDataMap);
        }

        return $trigger;
    }
106994
protected function defineConsoleSchedule()
    {
        $this->app->singleton(Schedule::class, function ($app) {
            return new Schedule();
        });

        $schedule = $this->app->make(Schedule::class);

        $this->schedule($schedule);
    }
690523
public static ScheduledEventService getScheduleService() {
        CHFWBundle c = instance.get().get();
        if (null != c) {
            return c.scheduler;
        }
        return null;
    }