public function generateSummaryActivitiesCsv($node) {
    $summary = $this->getSummary($node);

    $header = [
      $this->t('Category'),
      $this->t('Subcategory'),
      $this->t('Category Amount'),
      $this->t('Subcategory Amount'),
    ];

    $records = [];

    foreach ($summary['activities']['categories'] as $activity) {
      /** @var \Drupal\taxonomy\Entity\Term $term */
      $term = $activity['term'];

      $records[] = [$term->getName(), '', $activity['amount'], ''];

      foreach ($activity['subcategories'] as $subcategory) {
        /** @var \Drupal\taxonomy\Entity\Term $subTerm */
        $subTerm = $subcategory['term'];

        $records[] = ['', $subTerm->getName(), '', $subcategory['amount']];
      }
    }

    $records[] = ['', '', '', ''];
    $records[] = [$this->t('Total'), '', '', $summary['activities']['totalActivities']];

    $fileName = 'summary_activities_' . date('Y-m-d') . '.csv';

    return $this->createCsvResponse($fileName, $header, $records);
  }
public function generateSummaryActivitiesCsv($node) {
    $summary = $this->getSummary($node);

    $header = [
      $this->t('Category'),
      $this->t('Subcategory'),
      $this->t('Category Amount'),
      $this->t('Subcategory Amount'),
    ];

    $records = [];

    foreach ($summary['activities']['categories'] as $activity) {
      /** @var \Drupal\taxonomy\Entity\Term $term */
      $term = $activity['term'];

      $records[] = [$term->getName(), '', $activity['amount'], ''];

      foreach ($activity['subcategories'] as $subcategory) {
        /** @var \Drupal\taxonomy\Entity\Term $subTerm */
        $subTerm = $subcategory['term'];

        $records[] = ['', $subTerm->getName(), '', $subcategory['amount']];
      }
    }

    $records[] = ['', '', '', ''];
    $records[] = [$this->t('Total'), '', '', $summary['activities']['totalActivities']];

    $fileName = 'summary_activities_' . date('Y-m-d') . '.csv';

    return $this->createCsvResponse($fileName, $header, $records);
  }
public function generateSummaryActivitiesCsv ( $ node ) { $ summary = $ this -> getSummary ( $ node ) ; $ header = [ $ this -> t ( 'Category' ) , $ this -> t ( 'Subcategory' ) , $ this -> t ( 'Category Amount' ) , $ this -> t ( 'Subcategory Amount' ) , ] ; $ records = [ ] ; foreach ( $ summary [ 'activities' ] [ 'categories' ] as $ activity ) { /** @var \Drupal\taxonomy\Entity\Term $term */ $ term = $ activity [ 'term' ] ; $ records [ ] = [ $ term -> getName ( ) , '' , $ activity [ 'amount' ] , '' ] ; foreach ( $ activity [ 'subcategories' ] as $ subcategory ) { /** @var \Drupal\taxonomy\Entity\Term $subTerm */ $ subTerm = $ subcategory [ 'term' ] ; $ records [ ] = [ '' , $ subTerm -> getName ( ) , '' , $ subcategory [ 'amount' ] ] ; } } $ records [ ] = [ '' , '' , '' , '' ] ; $ records [ ] = [ $ this -> t ( 'Total' ) , '' , '' , $ summary [ 'activities' ] [ 'totalActivities' ] ] ; $ fileName = 'summary_activities_' . date ( 'Y-m-d' ) . '.csv' ; return $ this -> createCsvResponse ( $ fileName , $ header , $ records ) ; }
Generate Summary Activities CSV.

@param \Drupal\node\NodeInterface|int $node

@return \Symfony\Component\HttpFoundation\Response
Generate Summary Activities CSV .