Init
This commit is contained in:
75
Todo.php
Normal file
75
Todo.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?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
|
||||
];
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user