]> git.nbdom.net Git - nb.git/commitdiff
lib/php/db/table.php
authorDevops <sys@15gifts.com>
Sat, 13 May 2017 16:03:06 +0000 (17:03 +0100)
committerDevops <sys@15gifts.com>
Sat, 13 May 2017 16:03:06 +0000 (17:03 +0100)
lib/php/db/field.php
lib/php/db/table.php

index 0e0ef35c7cbbaba1fc539bdab532757744d1837d..ad62ca3c774ae97b87142cccc3c75d6c32097310 100644 (file)
@@ -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 = '';
index 61bfe5865cfde8ae2d4d6406063a78c50f8cded9..7c7a8bad9a1817f5efb359efc5fcf7c5e1640762 100644 (file)
@@ -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 .= '<table class="rows wp-list-table widefat striped">'.NB_EOL;
-    #if (!empty($opt)) $html .= '<caption>' . $this->nav($opt['count'],$opt['tot'],$opt['limit']) . '</caption>' .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 .= '<thead>'.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 = '<tr class="row'.$id.'">'.NB_EOL;
     $html = '<tr class="row">'.NB_EOL;
 
     if ($this->buttons() and !empty($buttons[0])) $html .= '<td class="action">'.$buttons[0].'</td>'.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 .= '<td'.$this->__rows_table_attr[$k].'>'.$v.'</td>'.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 .= '</tbody>'.NB_EOL;
     $html .= '</table>'.NB_EOL;