openvk/Web/Models/Repositories/Restores.php

38 lines
987 B
PHP
Raw Normal View History

<?php
declare(strict_types=1);
2020-06-07 19:04:43 +03:00
namespace openvk\Web\Models\Repositories;
2020-06-07 19:04:43 +03:00
use Chandler\Database\DatabaseConnection;
use openvk\Web\Models\Entities\PasswordReset;
use openvk\Web\Models\Entities\User;
use Nette\Database\Table\ActiveRow;
class Restores
{
private $context;
private $restores;
public function __construct()
2020-06-07 19:04:43 +03:00
{
$this->context = DatabaseConnection::i()->getContext();
$this->restores = $this->context->table("password_resets");
}
public function toPasswordReset(?ActiveRow $ar): ?PasswordReset
2020-06-07 19:04:43 +03:00
{
return is_null($ar) ? null : new PasswordReset($ar);
2020-06-07 19:04:43 +03:00
}
public function getByToken(string $token): ?PasswordReset
2020-06-07 19:04:43 +03:00
{
return $this->toPasswordReset($this->restores->where("key", $token)->fetch());
}
public function getLatestByUser(User $user): ?PasswordReset
2020-06-07 19:04:43 +03:00
{
return $this->toPasswordReset($this->restores->where("profile", $user->getId())->order("timestamp DESC")->fetch());
}
}