2025-01-31 18:20:13 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-05-06 17:17:08 +03:00
|
|
|
namespace openvk\Web\Models\Repositories;
|
2025-01-31 18:20:13 +03:00
|
|
|
|
2022-05-06 17:17:08 +03:00
|
|
|
use Chandler\Database\DatabaseConnection;
|
|
|
|
use openvk\Web\Models\Entities\EmailChangeVerification;
|
|
|
|
use openvk\Web\Models\Entities\User;
|
|
|
|
use Nette\Database\Table\ActiveRow;
|
|
|
|
|
|
|
|
class EmailChangeVerifications
|
|
|
|
{
|
|
|
|
private $context;
|
|
|
|
private $verifications;
|
2025-01-31 18:20:13 +03:00
|
|
|
|
|
|
|
public function __construct()
|
2022-05-06 17:17:08 +03:00
|
|
|
{
|
|
|
|
$this->context = DatabaseConnection::i()->getContext();
|
|
|
|
$this->verifications = $this->context->table("email_change_verifications");
|
|
|
|
}
|
|
|
|
|
2025-01-31 18:20:13 +03:00
|
|
|
public function toEmailChangeVerification(?ActiveRow $ar): ?EmailChangeVerification
|
2022-05-06 17:17:08 +03:00
|
|
|
{
|
2025-01-31 18:20:13 +03:00
|
|
|
return is_null($ar) ? null : new EmailChangeVerification($ar);
|
2022-05-06 17:17:08 +03:00
|
|
|
}
|
2025-01-31 18:20:13 +03:00
|
|
|
|
|
|
|
public function getByToken(string $token): ?EmailChangeVerification
|
2022-05-06 17:17:08 +03:00
|
|
|
{
|
|
|
|
return $this->toEmailChangeVerification($this->verifications->where("key", $token)->fetch());
|
|
|
|
}
|
2025-01-31 18:20:13 +03:00
|
|
|
|
|
|
|
public function getLatestByUser(User $user): ?EmailChangeVerification
|
2022-05-06 17:17:08 +03:00
|
|
|
{
|
|
|
|
return $this->toEmailChangeVerification($this->verifications->where("profile", $user->getId())->order("timestamp DESC")->fetch());
|
|
|
|
}
|
|
|
|
}
|