From 6e3d4164105a07c6e840d55d05ff90a057222b8e Mon Sep 17 00:00:00 2001 From: Devops Date: Sat, 13 May 2017 17:03:06 +0100 Subject: [PATCH] lib/php/db/table.php --- lib/php/db/field.php | 11 ++++++++++- lib/php/db/table.php | 18 ++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/php/db/field.php b/lib/php/db/field.php index 0e0ef35c..ad62ca3c 100644 --- a/lib/php/db/field.php +++ b/lib/php/db/field.php @@ -73,7 +73,16 @@ class field extends nb { if (strpos($this->type,'date') !== false) return 'date'; } - private function htmlYesNo($checked_value) { + public function htmlValue($value) { + + if (strpos($this->type,'bool') !== false) { + return preg_match('/^(1|yes|on|true)/i',$value) ? 'Yes' : 'No'; + } + + return $value; + } + + public function htmlYesNo($checked_value) { $s_no = $checked = ' checked="checked"'; if ( ( $s_yes = preg_match('/^(1|yes|on|true)/i',$checked_value) ? $checked : '' ) != '' ) $s_no = ''; diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 61bfe586..7c7a8bad 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -963,6 +963,8 @@ Class Table extends nb { } public function rows(&$opt=[],$opt_by_val=null) { + $opt['TABLE'] = $this; + # # Run query # @@ -1414,17 +1416,13 @@ Class Table extends nb { $html = ''; $html .= ''.NB_EOL; - #if (!empty($opt)) $html .= '' .NB_EOL; $this->__rows_table_attr = []; -# NB 27.12.16 $this->__rows_table_keys = []; foreach ($fields as $name => $f) { $this->__rows_table_attr[$name] = '' . ' class="' . $name . ($f->key?' key':'') . (isset($this->extras[$name])?' extra':'') . ' ' . preg_replace('/\W.*$/','',$f->type).'"' ; -# NB 27.12.16 if ($f->key) $this->__rows_table_keys[] = $name; } -# NB 27.12.16 if (empty($this->__rows_table_keys)) $this->__rows_table_keys = array_keys($fields); if ($this->show_header) { $html .= ''.NB_EOL; @@ -1460,21 +1458,18 @@ Class Table extends nb { return $html; } - public function rows_rec_table(&$row) { + public function rows_rec_table(&$row,&$opt) { $buttons = $this->html_row_buttons($row); -# NB 27.12.16 $id = []; -# NB 27.12.16 foreach ($this->__rows_table_keys as $k) { -# NB 27.12.16 $id[] = $row[$k]; -# NB 27.12.16 } -# NB 27.12.16 $id = empty($id) ? '' : ' '.'__'.join('__',$id).'__'; -# NB 27.12.16 $html = ''.NB_EOL; $html = ''.NB_EOL; if ($this->buttons() and !empty($buttons[0])) $html .= ''.NB_EOL; foreach ($row as $k => $v) { + if ( !empty($opt['TABLE']) and !empty($opt['TABLE']->field($k)) ) { + $v = $opt['TABLE']->field($k)->htmlValue($v); + } $html .= '__rows_table_attr[$k].'>'.$v.''.NB_EOL; } @@ -1487,7 +1482,6 @@ Class Table extends nb { public function rows_end_table() { unset($this->__rows_table_attr); -# NB 27.12.16 unset($this->__rows_table_keys); $html = ''; $html .= ''.NB_EOL; $html .= '
' . $this->nav($opt['count'],$opt['tot'],$opt['limit']) . '
'.$buttons[0].'
'.NB_EOL; -- 2.47.3