Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1 <?php
- 2 class TodoManager {
- 3
- 4 public function findAllTodos($order = NULL, $where = NULL, $offset = NULL, $limit = NULL) {
- 5
- 6 return dibi::query(
- 7 'SELECT * FROM [tasks]',
- 8 '%if', isset($where), 'WHERE %and', isset($where) ? $where : array(), '%end',
- 9 '%if', isset($order), 'ORDER BY %by', $order, '%end',
- 10 '%if', isset($limit), 'LIMIT %i %end', $limit,
- 11 '%if', isset($offset), 'OFFSET %i %end', $offset
- 12 )->setRowClass('Todo');
- 13 }
- 14
- 15 public function findTodo($id) {
- 16
- 17 return dibi::query('SELECT * FROM [tasks] WHERE [id]=%i LIMIT 1', $id)
- 18 ->setRowClass('Todo')
- 19 ->fetch();
- 20 }
- 21
- 22 public function todoCount($where = NULL) {
- 23
- 24 return dibi::fetchSingle('SELECT COUNT([id]) FROM [tasks] %if',
- 25 isset($where), 'WHERE', isset($where) ? $where : array()
- 26 );
- 27 }
- 28
- 29 public function createTodo(Todo $todo) {
- 30
- 31 return dibi::query('INSERT INTO [tasks]', (array) $todo);
- 32 }
- 33 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement