diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-10-12 14:28:08 -0400 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-10-12 14:28:08 -0400 |
commit | b7060b33ef317eeac576c504b1fb840d4471e411 (patch) | |
tree | 8acf657eda4df76285905fc5e774aacecb02f488 /app/helpers.php | |
parent | deeebd8e72a13fcbe6d357aefed9130671ee5161 (diff) |
Add pagination/column sorting for search and completed tasks
Diffstat (limited to 'app/helpers.php')
-rw-r--r-- | app/helpers.php | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/app/helpers.php b/app/helpers.php index 622d0ce3..c9f2f8ab 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -590,3 +590,65 @@ function u($controller, $action, array $params = array(), $csrf = false) return $html; } + +/** + * Pagination links + * + * @param array $pagination Pagination information + * @return string + */ +function paginate(array $pagination) +{ + extract($pagination); + + $html = '<div id="pagination">'; + $html .= '<span id="pagination-previous">'; + + if ($pagination['offset'] > 0) { + $offset = $pagination['offset'] - $limit; + $html .= a('← '.t('Previous'), $controller, $action, $params + compact('offset', 'order', 'direction')); + } + else { + $html .= '← '.t('Previous'); + } + + $html .= '</span>'; + $html .= '<span id="pagination-next">'; + + if (($total - $pagination['offset']) > $limit) { + $offset = $pagination['offset'] + $limit; + $html .= a(t('Next').' →', $controller, $action, $params + compact('offset', 'order', 'direction')); + } + else { + $html .= t('Next').' →'; + } + + $html .= '</span>'; + $html .= '</div>'; + + return $html; +} + +/** + * Column sorting (work with pagination) + * + * @param string $label Column title + * @param string $column SQL column name + * @param array $pagination Pagination information + * @return string + */ +function order($label, $column, array $pagination) +{ + extract($pagination); + + $prefix = ''; + + if ($order === $column) { + $prefix = $direction === 'DESC' ? '▼ ' : '▲ '; + $direction = $direction === 'DESC' ? 'ASC' : 'DESC'; + } + + $order = $column; + + return $prefix.a($label, $controller, $action, $params + compact('offset', 'order', 'direction')); +} |