芝麻web文件管理V1.00
编辑当前文件:/home/forge/stage.sksb.smartcon-survey.com/app/Livewire/Topics.php
topics = Topic::with(['interviews' => function ($query) { $query->where('is_test', '0'); return $query; }])->where('id', '!=', 24)->get(); $this->quarters = (new QuarterFilter)->quarters(); $this->departments = Department::all(); $sh = new SurveyJSHelper; $this->topics = $this->topics->map(function ($topic) use ($sh) { $topic['results'] = $sh->getResults($topic, $topic->interviews); return $topic; }); } public function clearFilter() { $this->selectedDepartments = []; $this->selectedAges = []; $this->leadingPosition = null; $this->selectedGender = null; $this->selectedQuarters = []; } public function filter() { $this->topics = $this->topics->map(function ($topic) { $interviews = $topic->interviews; // department if (count($this->selectedDepartments) > 0) { $departments = []; foreach ($this->selectedDepartments as $dep) { $index = array_search($dep, array_column($this->departments, 'id')); $departments = array_merge($departments, $this->departments[$index]['filters']); } $interviews = $interviews->filter(function ($int) use ($departments) { return in_array($int->department, $departments); }); } if ($this->leadingPosition != null) { $interviews = $interviews->filter(function ($int) { return $int->leading_pos == $this->leadingPosition; }); } if ($this->selectedGender != null) { $interviews = $interviews->filter(function ($int) { return $int->gender == $this->selectedGender; }); } if (count($this->selectedAges) > 0) { $ages = []; foreach ($this->selectedAges as $ageFilter) { // Split string (e.g. 18_25) and add all ages to the list $ageGroup = range(explode('_', $ageFilter)[0], explode('_', $ageFilter)[1]); $ages = array_merge($ages, $ageGroup); } sort($ages); // [18, 19, ..., 55] $interviews = $interviews->filter(function ($int) use ($ages) { return in_array($int->age, $ages); }); } if (count($this->selectedQuarters) > 0) { $interviews = $interviews->filter(function ($interview) { $quarters = array_map(function ($date) { return (int) explode('-', $date)[0]; }, $this->selectedQuarters); $years = array_map(function ($date) { return (int) explode('-', $date)[1]; }, $this->selectedQuarters); $interviewTime = $interview->created_at; return in_array($interviewTime->quarter, $quarters) && in_array($interviewTime->year, $years); }); } $topic->interviews = $interviews; return $topic; }); } public function render() { $sh = new SurveyJSHelper; $this->topics = $this->topics->map(function ($topic) use ($sh) { $topic['results'] = $sh->getResults($topic, $topic->interviews); return $topic; }); return view('livewire.topics'); } }