Загрузить файлы в «/»

This commit is contained in:
InsaneTrash 2025-03-20 08:08:52 +00:00
commit 7f16a3ef1b
5 changed files with 156 additions and 0 deletions

24
AppServiceProvider.php Normal file
View File

@ -0,0 +1,24 @@
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
//
}
}

8
Controller.php Normal file
View File

@ -0,0 +1,8 @@
<?php
namespace App\Http\Controllers;
abstract class Controller
{
//
}

42
Course.php Normal file
View File

@ -0,0 +1,42 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Course extends Model
{
use HasFactory;
protected $fillable = ['title', 'description'];
public function exercises()
{
return $this->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; // Все упражнения завершены
}
}

25
Exercise.php Normal file
View File

@ -0,0 +1,25 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Exercise extends Model
{
use HasFactory;
protected $fillable = ['title', 'description', 'gif_path'];
public function courses()
{
return $this->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);
}
}

57
User.php Normal file
View File

@ -0,0 +1,57 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Sanctum\HasApiTokens;
use Illuminate\Database\Eloquent\Model;
use Spatie\Permission\Traits\HasRoles; // Использование правильного трейта для работы с токенами
class User extends Authenticatable
{
use HasApiTokens, HasFactory, HasRoles;
protected $fillable = ['name', 'email', 'password','doctor_id','role_type'];
public function patients()
{
return $this->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; // Все упражнения завершены
}
}