芝麻web文件管理V1.00
编辑当前文件:/home/forge/stage.sksb.smartcon-survey.com/app/Livewire/Dashboard/SpecialTopicDetail.php
topicId)->with('interviews')->first(); $sh = new SurveyJSHelper($topic); $questions = $sh->getQuestions(); $index = $this->getResults($topic->interviews); foreach ($questions as $key => $question) { $qname = $question['name']; $questions[$key]['results'] = $this->getResults($topic->interviews, $qname); } return view('livewire.dashboard.special-topic-detail', [ 'index' => $index, 'questions' => $questions, 'topicId' => $this->topicId, ]); } public function getResults(Collection $interviews, ?string $question = null): array { $total = $this->getAllAnswers($interviews, $question)->count(); $absolute = array_count_values($this->getAllAnswers($interviews, $question)->toArray()); ksort($absolute); foreach ($absolute as $key => $value) { $absolute[$key] = round($value / $total * 100, 1); } return $absolute; } public function getAllAnswers(Collection $interviews, ?string $question = null): Collection { return $interviews ->map(fn ($interview) => $interview->answers) ->map(fn ($answers) => $question === null ? $answers : array_filter($answers, fn ($key) => $key === $question, ARRAY_FILTER_USE_KEY)) ->flatten() ->filter(fn ($answer) => is_numeric($answer)); } }