thomas
This commit is contained in:
51
TP5/EX1/model.php
Normal file
51
TP5/EX1/model.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user