commit 7f16a3ef1b294a9a7a06c9e8b694ef0bbcb73993 Author: InsaneTrash Date: Thu Mar 20 08:08:52 2025 +0000 Загрузить файлы в «/» diff --git a/AppServiceProvider.php b/AppServiceProvider.php new file mode 100644 index 0000000..452e6b6 --- /dev/null +++ b/AppServiceProvider.php @@ -0,0 +1,24 @@ +belongsToMany(Exercise::class, 'course_exercise'); + } + public function patients() + { + return $this->belongsToMany(User::class, 'course_patient'); // Связь с пациентами через промежуточную таблицу + } + public function users() + { + return $this->belongsToMany(User::class)->withTimestamps(); + } + public function isCompleted($userId) +{ + // Получаем все упражнения, связанные с курсом + $exercises = $this->exercises; + + // Проверяем, завершены ли все упражнения для данного пользователя + foreach ($exercises as $exercise) { + // Проверка завершенности упражнения для пользователя через связь с таблицей pivot + $completed = $exercise->users()->wherePivot('user_id', $userId)->wherePivot('completed', true)->exists(); + + if (!$completed) { + return false; // Если хотя бы одно упражнение не завершено + } + } + + return true; // Все упражнения завершены +} +} diff --git a/Exercise.php b/Exercise.php new file mode 100644 index 0000000..239450f --- /dev/null +++ b/Exercise.php @@ -0,0 +1,25 @@ +belongsToMany(Course::class, 'course_exercise'); + } + public function users() + { + return $this->belongsToMany(User::class, 'exercise_user')->withPivot('completed'); + } + public function getGifUrlAttribute() +{ + return Storage::url($this->gif_path); +} +} diff --git a/User.php b/User.php new file mode 100644 index 0000000..0d66728 --- /dev/null +++ b/User.php @@ -0,0 +1,57 @@ +hasMany(User::class, 'doctor_id'); + } + + // Связь с доктором (если это пациент) + public function doctor() + { + return $this->belongsTo(User::class, 'doctor_id'); + } + // Связь с курсами + public function courses() + { + return $this->belongsToMany(Course::class)->withTimestamps(); + } + + // Связь с упражнениями, с учетом их выполнения + public function exercises() + { + return $this->belongsToMany(Exercise::class, 'exercise_user')->withPivot('completed'); + } + + // Метод для проверки, завершены ли все упражнения + public function isCompleted($userId) + { + // Получаем все упражнения, связанные с курсом + $exercises = $this->exercises; + + // Проверяем, завершены ли все упражнения для данного пациента + foreach ($exercises as $exercise) { + // Проверка завершенности каждого упражнения + $completed = $exercise->users()->wherePivot('user_id', $userId)->wherePivot('completed', true)->exists(); + + if (!$completed) { + return false; // Если хотя бы одно упражнение не завершено + } + } + + return true; // Все упражнения завершены + } + +}