51 lines
1.1 KiB
PHP
51 lines
1.1 KiB
PHP
|
<?php
|
||
|
require 'rb-mysql.php';
|
||
|
|
||
|
class Todo {
|
||
|
public static function findAll() {
|
||
|
return R::findAll('todo');
|
||
|
}
|
||
|
|
||
|
public static function find($id) {
|
||
|
return R::load('todo', $id);
|
||
|
}
|
||
|
|
||
|
public static function findCompleted() {
|
||
|
return R::find('todo', 'done = ?', [true]);
|
||
|
}
|
||
|
|
||
|
public static function findUnCompleted() {
|
||
|
return R::find('todo', 'done = ?', [false]);
|
||
|
}
|
||
|
|
||
|
public static function create($data) {
|
||
|
$todo = R::dispense('todo');
|
||
|
$todo->title = $data['title'];
|
||
|
$todo->done = $data['done'];
|
||
|
$id = R::store($todo);
|
||
|
return $id;
|
||
|
}
|
||
|
|
||
|
public static function update($id, $data) {
|
||
|
$todo = R::load('todo', $id);
|
||
|
if ($todo->id === 0) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
foreach ($data as $key => $value) {
|
||
|
$todo->$key = $value;
|
||
|
}
|
||
|
R::store($todo);
|
||
|
return $todo->export();
|
||
|
}
|
||
|
|
||
|
public static function delete($id) {
|
||
|
$todo = R::load('todo', $id);
|
||
|
if ($todo->id !== 0) {
|
||
|
R::trash($todo);
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
?>
|