summaryrefslogtreecommitdiff
path: root/app/helpers.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-10-12 14:28:08 -0400
committerFrédéric Guillot <fred@kanboard.net>2014-10-12 14:28:08 -0400
commitb7060b33ef317eeac576c504b1fb840d4471e411 (patch)
tree8acf657eda4df76285905fc5e774aacecb02f488 /app/helpers.php
parentdeeebd8e72a13fcbe6d357aefed9130671ee5161 (diff)
Add pagination/column sorting for search and completed tasks
Diffstat (limited to 'app/helpers.php')
-rw-r--r--app/helpers.php62
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('&larr; '.t('Previous'), $controller, $action, $params + compact('offset', 'order', 'direction'));
+ }
+ else {
+ $html .= '&larr; '.t('Previous');
+ }
+
+ $html .= '</span>';
+ $html .= '<span id="pagination-next">';
+
+ if (($total - $pagination['offset']) > $limit) {
+ $offset = $pagination['offset'] + $limit;
+ $html .= a(t('Next').' &rarr;', $controller, $action, $params + compact('offset', 'order', 'direction'));
+ }
+ else {
+ $html .= t('Next').' &rarr;';
+ }
+
+ $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' ? '&#9660; ' : '&#9650; ';
+ $direction = $direction === 'DESC' ? 'ASC' : 'DESC';
+ }
+
+ $order = $column;
+
+ return $prefix.a($label, $controller, $action, $params + compact('offset', 'order', 'direction'));
+}