Przeglądaj źródła

DBG::table to UI::table

Piotr Labudda 9 lat temu
rodzic
commit
810c8f3055
3 zmienionych plików z 59 dodań i 44 usunięć
  1. 5 41
      SE/se-lib/DBG.php
  2. 1 3
      SE/se-lib/Route/Storage.php
  3. 53 0
      SE/se-lib/UI.php

+ 5 - 41
SE/se-lib/DBG.php

@@ -82,47 +82,11 @@ class DBG {
 		}
 		}
 	}
 	}
 
 
-	public static function table($label, $table, $className, $functionName, $lineNumber) {
-		$cols = array();
-		if (is_array($table) && !empty($table)) {
-			$firstRow = array();
-			foreach ($table as $row) {
-				$firstRow = $row;
-				break;
-			}
-			if (is_array($firstRow)) {
-				$cols = array_keys($firstRow);
-			}
-			else if (is_object($firstRow)) {
-				$cols = array_keys((array)$firstRow);
-			}
-			else {
-				return;// bad table item type
-			}
-		}
-?>
-<table class="table table-bordered table-hover">
-	<caption><?php echo "{$label} ({$className}::{$functionName}:{$lineNumber}):"; ?></caption>
-	<thead>
-		<tr>
-			<th style="padding:2px">Lp.</th>
-		<?php foreach ($cols as $colName) : ?>
-			<th style="padding:2px"><?php echo $colName; ?></th>
-		<?php endforeach; ?>
-		</tr>
-	</thead>
-	<tbody>
-	<?php $i = 0; foreach ($table as $row) : $i++; ?>
-		<tr>
-			<td style="padding:2px; color:#ccc"><?php echo $i; ?></td>
-		<?php foreach ($cols as $colName) : ?>
-			<td style="padding:2px"><?php echo V::get($colName, '', $row); ?></td>
-		<?php endforeach; ?>
-		</tr>
-	<?php endforeach; ?>
-	</tbody>
-</table>
-<?php
+	public static function table($label, $rows, $className, $functionName, $lineNumber) {
+		$params = array();
+		$params['caption'] = "{$label} ({$className}::{$functionName}:{$lineNumber}):";
+		$params['rows'] = $rows;
+		UI::table($params);
 	}
 	}
 
 
 	public static function nicePrint($variable, $varName) {
 	public static function nicePrint($variable, $varName) {

+ 1 - 3
SE/se-lib/Route/Storage.php

@@ -160,8 +160,6 @@ class Route_Storage extends RouteBase {
 		$mainTable = OBJ::getMainTableName($json);
 		$mainTable = OBJ::getMainTableName($json);
 		$sqlFields = OBJ::getTableFields($json);
 		$sqlFields = OBJ::getTableFields($json);
 		$this->showTableWidet($mainTable, $sqlFields);
 		$this->showTableWidet($mainTable, $sqlFields);
-
-		echo 'DBG exec "'."select count(*) from {$mainTable}".'"(' . DB::getPDO()->exec("select count(*) from {$mainTable}") . ')';// TODO: TEST
 	?>
 	?>
 </div>
 </div>
 <script>
 <script>
@@ -196,7 +194,7 @@ jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', fun
 			where 1=1
 			where 1=1
 			limit 10
 			limit 10
 		");
 		");
-		DBG::table("table({$tblName})", $rows, __CLASS__, __FUNCTION__, __LINE__);
+		UI::table(array('caption' => "table({$tblName})", 'rows' => $rows));
 	}
 	}
 
 
 	public function coreObjectParseAllAction() {
 	public function coreObjectParseAllAction() {

+ 53 - 0
SE/se-lib/UI.php

@@ -96,4 +96,57 @@ class UI {
 <?php
 <?php
 	}
 	}
 
 
+	/**
+	 * $params - Array
+	 *   $params['caption'] (optional) -> <caption>...</caption>
+	 *   $params['cols'] (optional) -> cols, if not set read from first row
+	 *   $params['rows'] -> rows, if not set - empty table
+	 *   $params['rows'] -> rows, if not set - empty table
+	 *   $params['disable_lp'] -> disable lp. col
+	 */
+	public static function table($params) {
+		$cols = V::get('cols', array(), $params);
+		$rows = V::get('rows', array(), $params);
+		$caption = V::get('caption', '', $params);
+		$showLp = (!V::get('disable_lp', false, $params));
+		if (empty($cols) && !empty($rows)) {
+			$firstRow = array();
+			foreach ($rows as $row) {
+				$firstRow = $row;
+				break;
+			}
+			$cols = array_keys((array)$firstRow);
+		}
+		// if (empty($cols)) return;
+?>
+	<table class="table table-bordered table-hover">
+	<?php if ($caption) : ?>
+		<caption><?php echo $caption; ?></caption>
+	<?php endif; ?>
+		<thead>
+			<tr>
+			<?php if ($showLp) : ?>
+				<th style="padding:2px">Lp.</th>
+			<?php endif; ?>
+			<?php foreach ($cols as $colName) : ?>
+				<th style="padding:2px"><?php echo $colName; ?></th>
+			<?php endforeach; ?>
+			</tr>
+		</thead>
+		<tbody>
+		<?php $i = 0; foreach ($rows as $row) : $i++; ?>
+			<tr>
+			<?php if ($showLp) : ?>
+				<td style="padding:2px; color:#ccc"><?php echo $i; ?></td>
+			<?php endif; ?>
+			<?php foreach ($cols as $colName) : ?>
+				<td style="padding:2px"><?php echo V::get($colName, '', $row); ?></td>
+			<?php endforeach; ?>
+			</tr>
+		<?php endforeach; ?>
+		</tbody>
+	</table>
+<?php
+	}
+
 }
 }