In the distance learning system, the collection of statistical data on the passing of tests by users. Statistics, at the moment, is displayed in one common table.
/** Π€ΠΎΡΠΌΠΈΡΠΎΠ²Π°Π½ΠΈΠ΅ ΡΡΠ°ΡΠΈΡΡΠΈΠΊΠΈ **/ $data = []; foreach($users as $user) { $id = $user->id; $data[$id] = [ 'fio' => $user->last_name.' '.$user->first_name.' '.$user->second_name, ]; /** ΠΡ
ΠΎΠ΄Π½Π°Ρ ΡΡΠ°ΡΠΈΡΡΠΈΠΊΠ° */ $stat = Result::whereRaw('user_id = '.$id.' and exam_id = '.$enter_exam->id)->latest()->first(); $data = $this->addStat($stat, $data, $id, 'course', 'enter'); /** ΠΠ°ΠΊΠ»ΡΡΠΈΡΠ΅Π»ΡΠ½Π°Ρ ΡΡΠ°ΡΠΈΡΡΠΈΠΊΠ° */ $stat = Result::whereRaw('user_id = '.$id.' and exam_id = '.$finish_exam->id)->latest()->first(); $data = $this->addStat($stat, $data, $id, 'course', 'finish'); /** Π‘ΡΠ°ΡΠΈΡΡΠΈΠΊΠ° ΠΏΠΎ ΠΠ΅ΠΊΡΠΈΡΠΌ */ if(count($lectures)) { foreach($lectures as $lecture) { $exam = $lecture->exam()->firstOrFail(); $stat = Result::whereRaw('user_id = '.$id.' and exam_id = '.$exam->id)->latest()->first(); $data = $this->addStat($stat, $data, $id, 'lectures', $lecture->slug); } } else { $data[$id]['lectures'] = null; } At the end of the course, it is required to save the statistics data to a file and place it on the server, for further downloading by the administrator if necessary.