$this->translator->trans('export.social_action_list.'.$tr), array_keys($this->formatRow(new SocialAction())) ); $csv = Writer::from('php://temp', 'w+'); $csv->insertOne($headers); foreach ($actions as $action) { if ($action->getGoals()->isEmpty() && $action->getResults()->isEmpty() && $action->getEvaluations()->isEmpty()) { $csv->insertOne($this->formatRow($action)); } foreach ($action->getGoals() as $goal) { if ($goal->getResults()->isEmpty()) { $csv->insertOne($this->formatRow($action, $goal)); } foreach ($goal->getResults() as $goalResult) { $csv->insertOne($this->formatRow($action, $goal, $goalResult)); } } foreach ($action->getResults() as $result) { if ($result->getGoals()->isEmpty()) { $csv->insertOne($this->formatRow($action, null, null, $result)); } } foreach ($action->getEvaluations() as $evaluation) { $csv->insertOne($this->formatRow($action, evaluation: $evaluation)); } } return $csv; } private function formatRow( SocialAction $action, ?Goal $goal = null, ?Result $goalResult = null, ?Result $resultWithoutGoal = null, ?Evaluation $evaluation = null, ): array { return [ 'action_id' => $action->getId(), 'social_issue_id' => $action->getIssue()?->getId(), 'problematique_label' => null !== $action->getIssue() ? $this->socialIssueRender->renderString($action->getIssue(), []) : null, 'desactivation_date' => $action->getDesactivationDate()?->format('Y-m-d'), 'social_issue_ordering' => $action->getIssue()?->getOrdering(), 'action_label' => $this->socialActionRender->renderString($action, []), 'action_ordering' => $action->getOrdering(), 'goal_label' => null !== $goal ? $this->stringHelper->localize($goal->getTitle()) : null, 'goal_id' => $goal?->getId(), 'goal_result_label' => null !== $goalResult ? $this->stringHelper->localize($goalResult->getTitle()) : null, 'goal_result_id' => $goalResult?->getId(), 'result_without_goal_label' => null !== $resultWithoutGoal ? $this->stringHelper->localize($resultWithoutGoal->getTitle()) : null, 'result_without_goal_id' => $resultWithoutGoal?->getId(), 'evaluation_title' => null !== $evaluation ? $this->stringHelper->localize($evaluation->getTitle()) : null, 'evaluation_id' => $evaluation?->getId(), 'evaluation_url' => $evaluation?->getUrl(), 'evaluation_delay_month' => $evaluation?->getDelay()?->format('%m'), 'evaluation_delay_week' => $evaluation?->getDelay()?->format('%w'), 'evaluation_delay_day' => $evaluation?->getDelay()?->format('%d'), ]; } }