private function getData() {
    $this->rawData = [];

    $class = !empty($this->parameters['class']) ? $this->parameters['class'] : '';
    $category = !empty($this->parameters['category']) ? $this->parameters['category'] : '';

    // One of the 3 search parameters should be provided:
    // 1. Location.
    // 2. Class name.
    // 3. Category.
    if (
      !isset($this->parameters['location']) &&
      $class == 'any' &&
      $category == 'any') {
      return;
    }

    $options = [
      'query' => [
        'schedule' => TRUE,
        'desc' => 'true',
      ],
    ];

    // Location is optional.
    if (!empty($this->parameters['location'])) {
      $options['query']['location'] = array_filter([$this->parameters['location']]);
    }

    // Category is optional.
    if ($category !== 'any') {
      $options['query']['category'] = $category;
    }

    // Class is optional.
    if ($class !== 'any') {
      $options['query']['class'] = self::$idStrip . $class;
    }

    // Filter by date.
    $interval = 'P1D';
    if ($this->parameters['filter_length'] == 'week') {
      $interval = 'P1W';
    }
    $date = DrupalDateTime::createFromTimestamp($this->parameters['filter_timestamp'], $this->timezone);

    $options['query']['start'] = $date->getTimestamp();
    $options['query']['end'] = $date->add(new \DateInterval($interval))->modify('-1 day')->getTimestamp();

    $data = $this->request($options);

    // Classes IDs has some garbage withing the IDs.
    $class_name_options = $this->getOptions($this->request(['query' => ['classes' => TRUE]]), 'id', 'title');
    $dirty_keys = array_keys($class_name_options);
    $refined_keys = array_map(function ($item) {
      return str_replace(GroupexRequestTrait::$idStrip, '', $item);
    }, $dirty_keys);
    $refined_options = array_combine(array_values($class_name_options), $refined_keys);

    $raw_data = [];

    if (!empty($data) && is_array($data)) {
      foreach ($data as $item) {
        $raw_data[$item->id] = $item;
        if (isset($refined_options[$item->title])) {
          $raw_data[$item->id]->class_id = $refined_options[$item->title];
        }
      }
    }
    $this->rawData = $raw_data;
  }
private function getData() {
    $this->rawData = [];

    $class = !empty($this->parameters['class']) ? $this->parameters['class'] : '';
    $category = !empty($this->parameters['category']) ? $this->parameters['category'] : '';

    // One of the 3 search parameters should be provided:
    // 1. Location.
    // 2. Class name.
    // 3. Category.
    if (
      !isset($this->parameters['location']) &&
      $class == 'any' &&
      $category == 'any') {
      return;
    }

    $options = [
      'query' => [
        'schedule' => TRUE,
        'desc' => 'true',
      ],
    ];

    // Location is optional.
    if (!empty($this->parameters['location'])) {
      $options['query']['location'] = array_filter([$this->parameters['location']]);
    }

    // Category is optional.
    if ($category !== 'any') {
      $options['query']['category'] = $category;
    }

    // Class is optional.
    if ($class !== 'any') {
      $options['query']['class'] = self::$idStrip . $class;
    }

    // Filter by date.
    $interval = 'P1D';
    if ($this->parameters['filter_length'] == 'week') {
      $interval = 'P1W';
    }
    $date = DrupalDateTime::createFromTimestamp($this->parameters['filter_timestamp'], $this->timezone);

    $options['query']['start'] = $date->getTimestamp();
    $options['query']['end'] = $date->add(new \DateInterval($interval))->modify('-1 day')->getTimestamp();

    $data = $this->request($options);

    // Classes IDs has some garbage withing the IDs.
    $class_name_options = $this->getOptions($this->request(['query' => ['classes' => TRUE]]), 'id', 'title');
    $dirty_keys = array_keys($class_name_options);
    $refined_keys = array_map(function ($item) {
      return str_replace(GroupexRequestTrait::$idStrip, '', $item);
    }, $dirty_keys);
    $refined_options = array_combine(array_values($class_name_options), $refined_keys);

    $raw_data = [];

    if (!empty($data) && is_array($data)) {
      foreach ($data as $item) {
        $raw_data[$item->id] = $item;
        if (isset($refined_options[$item->title])) {
          $raw_data[$item->id]->class_id = $refined_options[$item->title];
        }
      }
    }
    $this->rawData = $raw_data;
  }
private function getData ( ) { $ this -> rawData = [ ] ; $ class = ! empty ( $ this -> parameters [ 'class' ] ) ? $ this -> parameters [ 'class' ] : '' ; $ category = ! empty ( $ this -> parameters [ 'category' ] ) ? $ this -> parameters [ 'category' ] : '' ; // One of the 3 search parameters should be provided: // 1. Location. // 2. Class name. // 3. Category. if ( ! isset ( $ this -> parameters [ 'location' ] ) && $ class == 'any' && $ category == 'any' ) { return ; } $ options = [ 'query' => [ 'schedule' => TRUE , 'desc' => 'true' , ] , ] ; // Location is optional. if ( ! empty ( $ this -> parameters [ 'location' ] ) ) { $ options [ 'query' ] [ 'location' ] = array_filter ( [ $ this -> parameters [ 'location' ] ] ) ; } // Category is optional. if ( $ category !== 'any' ) { $ options [ 'query' ] [ 'category' ] = $ category ; } // Class is optional. if ( $ class !== 'any' ) { $ options [ 'query' ] [ 'class' ] = self :: $ idStrip . $ class ; } // Filter by date. $ interval = 'P1D' ; if ( $ this -> parameters [ 'filter_length' ] == 'week' ) { $ interval = 'P1W' ; } $ date = DrupalDateTime :: createFromTimestamp ( $ this -> parameters [ 'filter_timestamp' ] , $ this -> timezone ) ; $ options [ 'query' ] [ 'start' ] = $ date -> getTimestamp ( ) ; $ options [ 'query' ] [ 'end' ] = $ date -> add ( new \ DateInterval ( $ interval ) ) -> modify ( '-1 day' ) -> getTimestamp ( ) ; $ data = $ this -> request ( $ options ) ; // Classes IDs has some garbage withing the IDs. $ class_name_options = $ this -> getOptions ( $ this -> request ( [ 'query' => [ 'classes' => TRUE ] ] ) , 'id' , 'title' ) ; $ dirty_keys = array_keys ( $ class_name_options ) ; $ refined_keys = array_map ( function ( $ item ) { return str_replace ( GroupexRequestTrait :: $ idStrip , '' , $ item ) ; } , $ dirty_keys ) ; $ refined_options = array_combine ( array_values ( $ class_name_options ) , $ refined_keys ) ; $ raw_data = [ ] ; if ( ! empty ( $ data ) && is_array ( $ data ) ) { foreach ( $ data as $ item ) { $ raw_data [ $ item -> id ] = $ item ; if ( isset ( $ refined_options [ $ item -> title ] ) ) { $ raw_data [ $ item -> id ] -> class_id = $ refined_options [ $ item -> title ] ; } } } $ this -> rawData = $ raw_data ; }
Fetch data from the server.
Fetch data from the server .