From 69cb44aa7570e2ce26f540014cd682bc21c2ad1c Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Wed, 12 Nov 2008 10:16:25 +0000 Subject: [PATCH] Chenaged api for inserted columns --- includes/db_pager.inc | 15 +++++++-------- includes/ui/db_pager_view.inc | 30 +++++++++++++++++------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/includes/db_pager.inc b/includes/db_pager.inc index 474fed7a..c407675d 100644 --- a/includes/db_pager.inc +++ b/includes/db_pager.inc @@ -145,7 +145,7 @@ class db_pager { // add result field names to column defs for // col value retrieve and sort purposes for ($c = $i = 0; $c < count($this->columns); $c++) { - if ($this->columns[$c]['type'] != 'insert') + if (!(isset($this->columns[$c]['insert']) && $this->columns[$c]['insert'])) $this->columns[$c]['name']= mysql_field_name($result, $i++); } @@ -330,16 +330,15 @@ class db_pager { // $sql - base sql for data inquiry. Order of fields implies // pager columns order. // $coldef - array of column definitions. Example definitions -// Text column with title 'User name': +// Column with title 'User name' and default text format: // 'User name' // Skipped field from sql query. Data for the field is not displayed: // 'dummy' => 'skip' -// Column without title, formated with function func(). Field value -// is passed as parameter: -// array('type'=>'spec', 'fun'=>'func') -// Inserted column with title 'Some', formated with function rowfun(). Row -// values are passed as parameter array: -// 'Some' => array('type'=>'insert', 'fun'=>'rowfun') +// Column without title, data retrieved form row data with function func(): +// array('fun'=>'func') +// Inserted column with title 'Some', formated with function rowfun(). +// formated as date: +// 'Some' => array('type'=>'date, 'insert'=>true, 'fun'=>'rowfun') // Column with name 'Another', formatted as date, // sortable with ascending start order (available orders: asc,desc, ''). // 'Another' => array('type'=>'date', 'ord'=>'asc') diff --git a/includes/ui/db_pager_view.inc b/includes/ui/db_pager_view.inc index ee74aca5..e9990815 100644 --- a/includes/ui/db_pager_view.inc +++ b/includes/ui/db_pager_view.inc @@ -62,7 +62,17 @@ function display_db_pager(&$pager) { $coltype = $col['type']; $cell = isset($col['name']) ? $row[$col['name']] : ''; - switch($coltype) { + if (isset($col['fun'])) { // use data input function if defined + $fun = $col['fun']; + if (method_exists($pager, $fun)) { + $cell = $pager->$fun($row, $cell); + } elseif (function_exists($fun)) { + $cell = $fun($row, $cell); + } else + $cell = ''; + } + + switch($coltype) { // format column case 'date': label_cell(sql2date($cell), "align='center'"); break; case 'dstamp': // time stamp displayed as date @@ -73,23 +83,17 @@ function display_db_pager(&$pager) { case 'percent': percent_cell($cell); break; case 'amount': - amount_cell($cell); break; + amount_cell($cell, false); break; case 'qty': qty_cell($cell); break; case 'rate': rate_cell($cell); break; - case 'insert': // extra inserted column - case 'spec': // special formatting function - $fun = $col['fun']; - if (method_exists($pager, $fun)) { - $cell = $pager->$fun($row, $cell); - } elseif (function_exists($fun)) { - $cell = $fun($row, $cell); - } else - $cell = ''; -// case 'text': default: - label_cell($cell); +// case 'text': + if (isset( $col['align'])) + label_cell($cell, "align='" . $col['align'] . "'"); + else + label_cell($cell); case 'skip': // column not displayed } } -- 2.30.2