private function calculateTrackedActivities(NodeInterface $node) {
    // Fetch all members from the current campaign.
    /** @var \Drupal\Core\Database\Query\Select $query */
    $query = $this->connection->select('openy_campaign_memb_camp_actv', 'mca');
    $query->addField('mca', 'id', 'mca_id');
    $query->addField('mca', 'activity', 'mca_activity');
    $query->join('openy_campaign_member_campaign', 'mc', 'mc.id = mca.member_campaign');
    $query->addField('mc', 'id');
    $query->condition('mc.campaign', $node->id());

    $activities = $query->execute()->fetchAll();
    $data = [];

    $data['totalActivities'] = count($activities);
    /** @var \Drupal\taxonomy\TermStorageInterface $termStorage */
    $termStorage = $this->entityTypeManager->getStorage('taxonomy_term');

    foreach ($activities as $activity) {
      // Fetch subcategory.
      $subcategory = $termStorage->load($activity->mca_activity);
      // In case if some categories have been removed during the challenge, we need to skip it from the calculation.
      if (empty($subcategory)) {
        --$data['totalActivities'];
        continue;
      }

      // Fetch category.
      $ancestors = $termStorage->loadAllParents($subcategory->id());
      $ancestors = array_reverse($ancestors);
      /** @var \Drupal\taxonomy\Entity\Term $category */
      $category = reset($ancestors);

      // Calculate amount of activities in the category.
      $categories = &$data['categories'][$category->id()];
      if (!isset($categories['amount'])) {
        $categories['amount'] = 1;
      }
      else {
        ++$categories['amount'];
      }

      $categories['term'] = $category;

      // Calculate amount of activities in the subcategory.
      $subcategories = &$data['categories'][$category->id()]['subcategories'];
      if (!isset($subcategories[$subcategory->id()]['amount'])) {
        $subcategories[$subcategory->id()]['amount'] = 1;
      }
      else {
        ++$subcategories[$subcategory->id()]['amount'];
      }
      $subcategories[$subcategory->id()]['term'] = $subcategory;

    }

    return $data;
  }
private function calculateTrackedActivities(NodeInterface $node) {
    // Fetch all members from the current campaign.
    /** @var \Drupal\Core\Database\Query\Select $query */
    $query = $this->connection->select('openy_campaign_memb_camp_actv', 'mca');
    $query->addField('mca', 'id', 'mca_id');
    $query->addField('mca', 'activity', 'mca_activity');
    $query->join('openy_campaign_member_campaign', 'mc', 'mc.id = mca.member_campaign');
    $query->addField('mc', 'id');
    $query->condition('mc.campaign', $node->id());

    $activities = $query->execute()->fetchAll();
    $data = [];

    $data['totalActivities'] = count($activities);
    /** @var \Drupal\taxonomy\TermStorageInterface $termStorage */
    $termStorage = $this->entityTypeManager->getStorage('taxonomy_term');

    foreach ($activities as $activity) {
      // Fetch subcategory.
      $subcategory = $termStorage->load($activity->mca_activity);
      // In case if some categories have been removed during the challenge, we need to skip it from the calculation.
      if (empty($subcategory)) {
        --$data['totalActivities'];
        continue;
      }

      // Fetch category.
      $ancestors = $termStorage->loadAllParents($subcategory->id());
      $ancestors = array_reverse($ancestors);
      /** @var \Drupal\taxonomy\Entity\Term $category */
      $category = reset($ancestors);

      // Calculate amount of activities in the category.
      $categories = &$data['categories'][$category->id()];
      if (!isset($categories['amount'])) {
        $categories['amount'] = 1;
      }
      else {
        ++$categories['amount'];
      }

      $categories['term'] = $category;

      // Calculate amount of activities in the subcategory.
      $subcategories = &$data['categories'][$category->id()]['subcategories'];
      if (!isset($subcategories[$subcategory->id()]['amount'])) {
        $subcategories[$subcategory->id()]['amount'] = 1;
      }
      else {
        ++$subcategories[$subcategory->id()]['amount'];
      }
      $subcategories[$subcategory->id()]['term'] = $subcategory;

    }

    return $data;
  }
private function calculateTrackedActivities ( NodeInterface $ node ) { // Fetch all members from the current campaign. /** @var \Drupal\Core\Database\Query\Select $query */ $ query = $ this -> connection -> select ( 'openy_campaign_memb_camp_actv' , 'mca' ) ; $ query -> addField ( 'mca' , 'id' , 'mca_id' ) ; $ query -> addField ( 'mca' , 'activity' , 'mca_activity' ) ; $ query -> join ( 'openy_campaign_member_campaign' , 'mc' , 'mc.id = mca.member_campaign' ) ; $ query -> addField ( 'mc' , 'id' ) ; $ query -> condition ( 'mc.campaign' , $ node -> id ( ) ) ; $ activities = $ query -> execute ( ) -> fetchAll ( ) ; $ data = [ ] ; $ data [ 'totalActivities' ] = count ( $ activities ) ; /** @var \Drupal\taxonomy\TermStorageInterface $termStorage */ $ termStorage = $ this -> entityTypeManager -> getStorage ( 'taxonomy_term' ) ; foreach ( $ activities as $ activity ) { // Fetch subcategory. $ subcategory = $ termStorage -> load ( $ activity -> mca_activity ) ; // In case if some categories have been removed during the challenge, we need to skip it from the calculation. if ( empty ( $ subcategory ) ) { -- $ data [ 'totalActivities' ] ; continue ; } // Fetch category. $ ancestors = $ termStorage -> loadAllParents ( $ subcategory -> id ( ) ) ; $ ancestors = array_reverse ( $ ancestors ) ; /** @var \Drupal\taxonomy\Entity\Term $category */ $ category = reset ( $ ancestors ) ; // Calculate amount of activities in the category. $ categories = & $ data [ 'categories' ] [ $ category -> id ( ) ] ; if ( ! isset ( $ categories [ 'amount' ] ) ) { $ categories [ 'amount' ] = 1 ; } else { ++ $ categories [ 'amount' ] ; } $ categories [ 'term' ] = $ category ; // Calculate amount of activities in the subcategory. $ subcategories = & $ data [ 'categories' ] [ $ category -> id ( ) ] [ 'subcategories' ] ; if ( ! isset ( $ subcategories [ $ subcategory -> id ( ) ] [ 'amount' ] ) ) { $ subcategories [ $ subcategory -> id ( ) ] [ 'amount' ] = 1 ; } else { ++ $ subcategories [ $ subcategory -> id ( ) ] [ 'amount' ] ; } $ subcategories [ $ subcategory -> id ( ) ] [ 'term' ] = $ subcategory ; } return $ data ; }
Get information about the tracked activities.

@param \Drupal\node\NodeInterface $node

@return array Full information about the activities.
Get information about the tracked activities .