From 7f16a3ef1b294a9a7a06c9e8b694ef0bbcb73993 Mon Sep 17 00:00:00 2001 From: InsaneTrash Date: Thu, 20 Mar 2025 08:08:52 +0000 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20=C2=AB?= =?UTF-8?q?/=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AppServiceProvider.php | 24 ++++++++++++++++++ Controller.php | 8 ++++++ Course.php | 42 +++++++++++++++++++++++++++++++ Exercise.php | 25 ++++++++++++++++++ User.php | 57 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 156 insertions(+) create mode 100644 AppServiceProvider.php create mode 100644 Controller.php create mode 100644 Course.php create mode 100644 Exercise.php create mode 100644 User.php 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; // Все упражнения завершены + } + +}