Advertisement
Guest User

Untitled

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