42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\Users;
|
|
|
|
use App\Models\BaseModel;
|
|
|
|
final class UserModel extends BaseModel
|
|
{
|
|
protected string $table = 'users';
|
|
|
|
public function findByEmail(string $email, ?string $tenantId = null): ?array
|
|
{
|
|
$sql = "SELECT * FROM {$this->table} WHERE email = ? AND deleted_at IS NULL";
|
|
$params = [$email];
|
|
|
|
if ($tenantId) {
|
|
$sql .= " AND tenant_id = ?";
|
|
$params[] = $tenantId;
|
|
}
|
|
|
|
$stmt = $this->db()->prepare($sql);
|
|
$stmt->execute($params);
|
|
return $stmt->fetch() ?: null;
|
|
}
|
|
|
|
public function findAllByTenant(string $tenantId): array
|
|
{
|
|
$stmt = $this->db()->prepare("SELECT id, name, email, role, is_active, created_at FROM {$this->table} WHERE tenant_id = ? AND deleted_at IS NULL");
|
|
$stmt->execute([$tenantId]);
|
|
return $stmt->fetchAll();
|
|
}
|
|
|
|
public function findById(string $id, string $tenantId): ?array
|
|
{
|
|
$stmt = $this->db()->prepare("SELECT id, name, email, role, is_active, created_at FROM {$this->table} WHERE id = ? AND tenant_id = ? AND deleted_at IS NULL LIMIT 1");
|
|
$stmt->execute([$id, $tenantId]);
|
|
return $stmt->fetch() ?: null;
|
|
}
|
|
}
|