Files
phpapi-template/Todo.php
2025-06-09 12:36:58 -06:00

75 lines
1.8 KiB
PHP

<?php
class Todo {
private $id;
private $title;
private $description;
private $completed;
private $createdAt;
private $updatedAt;
public function __construct($id, $title, $description = '', $completed = false) {
$this->id = $id;
$this->title = $title;
$this->description = $description;
$this->completed = $completed;
$this->createdAt = date('Y-m-d H:i:s');
$this->updatedAt = date('Y-m-d H:i:s');
}
// Getters
public function getId() {
return $this->id;
}
public function getTitle() {
return $this->title;
}
public function getDescription() {
return $this->description;
}
public function isCompleted() {
return $this->completed;
}
public function getCreatedAt() {
return $this->createdAt;
}
public function getUpdatedAt() {
return $this->updatedAt;
}
// Setters
public function setTitle($title) {
$this->title = $title;
$this->updateTimestamp();
}
public function setDescription($description) {
$this->description = $description;
$this->updateTimestamp();
}
public function setCompleted($completed) {
$this->completed = $completed;
$this->updateTimestamp();
}
private function updateTimestamp() {
$this->updatedAt = date('Y-m-d H:i:s');
}
public function toArray() {
return [
'id' => $this->id,
'title' => $this->title,
'description' => $this->description,
'completed' => $this->completed,
'created_at' => $this->createdAt,
'updated_at' => $this->updatedAt
];
}
}
?>