Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added consultation_user_terms table #116

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions database/factories/ConsultationUserTermFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace EscolaLms\Consultations\Database\Factories;

use EscolaLms\Consultations\Enum\ConsultationTermStatusEnum;
use EscolaLms\Consultations\Models\ConsultationUserTerm;
use Illuminate\Database\Eloquent\Factories\Factory;

class ConsultationUserTermFactory extends Factory
{
protected $model = ConsultationUserTerm::class;

public function definition(): array
{
$now = now()->modify('+2 hours');
return [
'executed_at' => $now->format('Y-m-d H:i:s'),
'executed_status' => $this->faker->randomElement(ConsultationTermStatusEnum::getValues()),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up()
{
Schema::create('consultation_user_terms', function (Blueprint $table) {
$table->id();

$table->dateTime('executed_at')->nullable();
$table->dateTime('finished_at')->nullable();

$table->string('executed_status')->nullable();
$table->string('reminder_status', 30)->nullable();

$table->foreignId('consultation_user_id')->references('id')->on('consultation_user')->onDelete('cascade');

$table->timestamps();
});
}

public function down()
{
Schema::dropIfExists('consultation_user_terms');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use EscolaLms\Consultations\Models\ConsultationUserPivot;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration
{
public function up()
{
ConsultationUserPivot::query()->whereNotNull('executed_at')->chunk(100, function ($consultationUsers) {
/** @var ConsultationUserPivot $consultationUser */
foreach ($consultationUsers as $consultationUser) {
$consultationUser->userTerms()->create([
'executed_status' => $consultationUser->executed_status,
'executed_at' => $consultationUser->executed_at,
'reminder_status' => $consultationUser->reminder_status,
]);
}
});
}

public function down()
{
//
}
};
40 changes: 40 additions & 0 deletions src/Dto/ChangeTermConsultationDto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace EscolaLms\Consultations\Dto;

class ChangeTermConsultationDto extends BaseDto
{
protected string $executedAt;
protected string $term;
protected bool $forAllUsers = false;

protected function setExecutedAt(string $executedAt): void
{
$this->executedAt = $executedAt;
}

public function getExecutedAt(): string
{
return $this->executedAt;
}

protected function setTerm(string $term): void
{
$this->term = $term;
}

public function getTerm(): string
{
return $this->term;
}

protected function setForAllUsers(bool $forAllUsers): void
{
$this->forAllUsers = $forAllUsers;
}

public function getForAllUsers(): bool
{
return $this->forAllUsers;
}
}
6 changes: 6 additions & 0 deletions src/Dto/ConsultationSaveScreenDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ConsultationSaveScreenDto extends BaseDto
protected string $userEmail;
protected UploadedFile|string $file;
protected string $timestamp;
protected string $executedAt;

public function getConsultationId(): int
{
Expand All @@ -36,4 +37,9 @@ public function getTimestamp(): string
{
return $this->timestamp;
}

public function getExecutedAt(): string
{
return $this->executedAt;
}
}
29 changes: 29 additions & 0 deletions src/Dto/ConsultationUserTermDto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace EscolaLms\Consultations\Dto;

class ConsultationUserTermDto extends BaseDto
{
protected string $term;
protected bool $forAllUsers = false;

protected function setTerm(string $term): void
{
$this->term = $term;
}

public function getTerm(): string
{
return $this->term;
}

protected function setForAllUsers(bool $forAllUsers): void
{
$this->forAllUsers = $forAllUsers;
}

public function getForAllUsers(): bool
{
return $this->forAllUsers;
}
}
31 changes: 31 additions & 0 deletions src/Dto/ConsultationUserTermResourceDto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace EscolaLms\Consultations\Dto;

use EscolaLms\Consultations\Models\User;
use Illuminate\Support\Collection;

class ConsultationUserTermResourceDto
{
public int $consultation_user_id;
public int $consultation_id;
public string $executed_at;
public string $executed_status;
public string $duration;
public Collection $users;
public ?User $author;
public ?string $finished_at;

public function __construct(int $consultation_user_id, int $consultation_id, string $executed_at, string $status, string $duration, ?User $author, ?string $finished_at = null, ?Collection $users = null)
{
$this->consultation_user_id = $consultation_user_id;
$this->consultation_id = $consultation_id;
$this->executed_at = $executed_at;
$this->executed_status = $status;
$this->duration = $duration;
$this->users = $users instanceof Collection ? $users : collect();
$this->author = $author;
$this->finished_at = $finished_at;
}

}
11 changes: 7 additions & 4 deletions src/Dto/FilterConsultationTermsListDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

use EscolaLms\Consultations\Dto\Contracts\ModelDtoContract;
use EscolaLms\Consultations\Models\ConsultationUserPivot;
use EscolaLms\Consultations\Models\ConsultationUserTerm;
use EscolaLms\Consultations\Repositories\Criteria\UserExistsCriterion;
use EscolaLms\Consultations\Repositories\Criteria\UserTermConsultationCriterion;
use EscolaLms\Consultations\Repositories\Criteria\UserTermUserExistsCriterion;
use EscolaLms\Core\Repositories\Criteria\Primitives\NotNullCriterion;
use EscolaLms\Core\Repositories\Criteria\Primitives\WhereCriterion;
use EscolaLms\Core\Repositories\Criteria\Primitives\WhereNotInOrIsNullCriterion;
Expand Down Expand Up @@ -44,19 +47,19 @@ public static function prepareFilters(array $search): self
$dto->addToCriteria(new WhereCriterion($dto->model()->getTable() . '.executed_at', $dto->getDateTimeTo(), '<='));
}
if ($dto->getConsultationId()) {
$dto->addToCriteria(new EqualCriterion($dto->model()->getTable() . '.consultation_id', $dto->getConsultationId()));
$dto->addToCriteria(new UserTermConsultationCriterion($dto->getConsultationId()));
}
if ($dto->getReminderStatus()) {
$dto->addToCriteria(new WhereNotInOrIsNullCriterion($dto->model()->getTable() . '.reminder_status', $dto->getReminderStatus()));
}
$dto->addToCriteria(new UserExistsCriterion());
$dto->addToCriteria(new UserTermUserExistsCriterion());
return $dto;
}

public function model(): ConsultationUserPivot
public function model(): ConsultationUserTerm
{
// @phpstan-ignore-next-line
return ConsultationUserPivot::newModelInstance();
return ConsultationUserTerm::newModelInstance();
}

public function toArray($filters = false): array
Expand Down
29 changes: 29 additions & 0 deletions src/Dto/FinishTermDto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace EscolaLms\Consultations\Dto;

class FinishTermDto extends BaseDto
{
protected string $term;
protected ?string $finishedAt;

protected function setTerm(string $term): void
{
$this->term = $term;
}

public function getTerm(): string
{
return $this->term;
}

protected function setFinishedAt(?string $finishedAt): void
{
$this->finishedAt = $finishedAt;
}

public function getFinishedAt(): ?string
{
return $this->finishedAt;
}
}
5 changes: 4 additions & 1 deletion src/EscolaLmsConsultationsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
use EscolaLms\Consultations\Providers\EventServiceProvider;
use EscolaLms\Consultations\Repositories\ConsultationRepository;
use EscolaLms\Consultations\Repositories\ConsultationUserRepository;
use EscolaLms\Consultations\Repositories\ConsultationUserTermRepository;
use EscolaLms\Consultations\Repositories\Contracts\ConsultationRepositoryContract;
use EscolaLms\Consultations\Repositories\Contracts\ConsultationUserRepositoryContract;
use EscolaLms\Consultations\Repositories\Contracts\ConsultationUserTermRepositoryContract;
use EscolaLms\Consultations\Services\ConsultationService;
use EscolaLms\Consultations\Services\Contracts\ConsultationServiceContract;
use EscolaLms\Jitsi\EscolaLmsJitsiServiceProvider;
Expand All @@ -26,7 +28,8 @@ class EscolaLmsConsultationsServiceProvider extends ServiceProvider
];
public const REPOSITORIES = [
ConsultationRepositoryContract::class => ConsultationRepository::class,
ConsultationUserRepositoryContract::class => ConsultationUserRepository::class
ConsultationUserRepositoryContract::class => ConsultationUserRepository::class,
ConsultationUserTermRepositoryContract::class => ConsultationUserTermRepository::class,
];

public $singletons = self::SERVICES + self::REPOSITORIES;
Expand Down
10 changes: 9 additions & 1 deletion src/Events/ConsultationTerm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace EscolaLms\Consultations\Events;

use EscolaLms\Consultations\Models\ConsultationUserTerm;
use EscolaLms\Core\Models\User;
use EscolaLms\Consultations\Models\ConsultationUserPivot;
use Illuminate\Foundation\Events\Dispatchable;
Expand All @@ -13,11 +14,13 @@ abstract class ConsultationTerm

private User $user;
private ConsultationUserPivot $consultationTerm;
private ?ConsultationUserTerm $consultationUserTerm;

public function __construct(User $user, ConsultationUserPivot $consultationTerm)
public function __construct(User $user, ConsultationUserPivot $consultationTerm, ?ConsultationUserTerm $consultationUserTerm = null)
{
$this->user = $user;
$this->consultationTerm = $consultationTerm;
$this->consultationUserTerm = $consultationUserTerm;
}

public function getUser(): User
Expand All @@ -29,4 +32,9 @@ public function getConsultationTerm(): ConsultationUserPivot
{
return $this->consultationTerm;
}

public function getConsultationUserTerm(): ConsultationUserTerm
{
return $this->consultationUserTerm;
}
}
5 changes: 3 additions & 2 deletions src/Events/ReminderAboutTerm.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
namespace EscolaLms\Consultations\Events;

use EscolaLms\Consultations\Models\ConsultationUserPivot;
use EscolaLms\Consultations\Models\ConsultationUserTerm;
use EscolaLms\Core\Models\User;

class ReminderAboutTerm extends ConsultationTerm
{
private string $status;

public function __construct(User $user, ConsultationUserPivot $consultationTerm, string $status)
public function __construct(User $user, ConsultationUserPivot $consultationTerm, string $status, ?ConsultationUserTerm $consultationUserTerm = null)
{
parent::__construct($user, $consultationTerm);
parent::__construct($user, $consultationTerm, $consultationUserTerm);
$this->status = $status;
}

Expand Down
5 changes: 3 additions & 2 deletions src/Events/ReminderTrainerAboutTerm.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
namespace EscolaLms\Consultations\Events;

use EscolaLms\Consultations\Models\ConsultationUserPivot;
use EscolaLms\Consultations\Models\ConsultationUserTerm;
use EscolaLms\Core\Models\User;

class ReminderTrainerAboutTerm extends ConsultationTerm
{
private string $status;

public function __construct(User $user, ConsultationUserPivot $consultationTerm, string $status)
public function __construct(User $user, ConsultationUserPivot $consultationTerm, string $status, ?ConsultationUserTerm $consultationUserTerm = null)
{
parent::__construct($user, $consultationTerm);
parent::__construct($user, $consultationTerm, $consultationUserTerm);
$this->status = $status;
}

Expand Down
Loading
Loading