feat: Complete Woles Framework v1.0 with enterprise-grade UI

- Add comprehensive error handling system with custom error pages
- Implement professional enterprise-style design with Tailwind CSS
- Create modular HMVC architecture with clean separation of concerns
- Add security features: CSRF protection, XSS filtering, Argon2ID hashing
- Include CLI tools for development workflow
- Add error reporting dashboard with system monitoring
- Implement responsive design with consistent slate color scheme
- Replace all emoji icons with professional SVG icons
- Add comprehensive test suite with PHPUnit
- Include database migrations and seeders
- Add proper exception handling with fallback pages
- Implement template engine with custom syntax support
- Add helper functions and facades for clean code
- Include proper logging and debugging capabilities
This commit is contained in:
mwpn
2025-10-11 07:08:23 +07:00
commit 0b42271bfe
90 changed files with 8315 additions and 0 deletions

184
app/Modules/User/Model.php Normal file
View File

@@ -0,0 +1,184 @@
<?php
namespace App\Modules\User;
/**
* User Model
* User management model
*/
class Model
{
private \PDO $pdo;
public function __construct()
{
$this->pdo = $this->getConnection();
}
/**
* Get database connection
*/
private function getConnection(): \PDO
{
$config = include __DIR__ . '/../../Config/database.php';
$connection = $config['connections'][$config['default']];
$dsn = "mysql:host={$connection['host']};port={$connection['port']};dbname={$connection['database']};charset={$connection['charset']}";
return new \PDO($dsn, $connection['username'], $connection['password'], $connection['options']);
}
/**
* Find user by ID
*/
public function findById(int $id): ?array
{
$stmt = $this->pdo->prepare("SELECT * FROM users WHERE id = ?");
$stmt->execute([$id]);
$user = $stmt->fetch();
return $user ?: null;
}
/**
* Find user by email
*/
public function findByEmail(string $email): ?array
{
$stmt = $this->pdo->prepare("SELECT * FROM users WHERE email = ?");
$stmt->execute([$email]);
$user = $stmt->fetch();
return $user ?: null;
}
/**
* Get all users
*/
public function all(): array
{
$stmt = $this->pdo->query("SELECT id, name, email, created_at, updated_at FROM users ORDER BY created_at DESC");
return $stmt->fetchAll();
}
/**
* Create new user
*/
public function create(array $data): int
{
$stmt = $this->pdo->prepare("
INSERT INTO users (name, email, password, created_at, updated_at)
VALUES (?, ?, ?, NOW(), NOW())
");
$stmt->execute([
$data['name'],
$data['email'],
password_hash($data['password'], PASSWORD_ARGON2ID)
]);
return $this->pdo->lastInsertId();
}
/**
* Update user
*/
public function update(int $id, array $data): bool
{
$fields = [];
$values = [];
foreach ($data as $key => $value) {
if ($key !== 'id') {
$fields[] = "{$key} = ?";
$values[] = $value;
}
}
if (empty($fields)) {
return false;
}
$values[] = $id;
$sql = "UPDATE users SET " . implode(', ', $fields) . ", updated_at = NOW() WHERE id = ?";
$stmt = $this->pdo->prepare($sql);
return $stmt->execute($values);
}
/**
* Delete user
*/
public function delete(int $id): bool
{
$stmt = $this->pdo->prepare("DELETE FROM users WHERE id = ?");
return $stmt->execute([$id]);
}
/**
* Check if email exists
*/
public function emailExists(string $email, ?int $excludeId = null): bool
{
$sql = "SELECT COUNT(*) FROM users WHERE email = ?";
$params = [$email];
if ($excludeId) {
$sql .= " AND id != ?";
$params[] = $excludeId;
}
$stmt = $this->pdo->prepare($sql);
$stmt->execute($params);
return $stmt->fetchColumn() > 0;
}
/**
* Get users with pagination
*/
public function paginate(int $page = 1, int $perPage = 10): array
{
$offset = ($page - 1) * $perPage;
$stmt = $this->pdo->prepare("
SELECT id, name, email, created_at, updated_at
FROM users
ORDER BY created_at DESC
LIMIT ? OFFSET ?
");
$stmt->execute([$perPage, $offset]);
$users = $stmt->fetchAll();
// Get total count
$countStmt = $this->pdo->query("SELECT COUNT(*) FROM users");
$total = $countStmt->fetchColumn();
return [
'data' => $users,
'total' => $total,
'per_page' => $perPage,
'current_page' => $page,
'last_page' => ceil($total / $perPage)
];
}
/**
* Search users
*/
public function search(string $query): array
{
$stmt = $this->pdo->prepare("
SELECT id, name, email, created_at, updated_at
FROM users
WHERE name LIKE ? OR email LIKE ?
ORDER BY created_at DESC
");
$searchTerm = "%{$query}%";
$stmt->execute([$searchTerm, $searchTerm]);
return $stmt->fetchAll();
}
}