Browse Source

dev 2020-03

Max F 5 năm trước cách đây
mục cha
commit
657998b014
2 tập tin đã thay đổi với 21 bổ sung1 xóa
  1. 2 1
      src/Database/Sql/SqlTable.php
  2. 19 0
      src/Database/Sql/SqlTableModel.php

+ 2 - 1
src/Database/Sql/SqlTable.php

@@ -202,6 +202,7 @@ class SqlTable
 
 	public function getAllWithFoundRows($where=null, $options=[]) /* : array */
 	{
+		$options['CALC_FOUND_ROWS'] = true;
 		$query = $this->buildQuery($where, $options);
 
 		if (! empty($options['dry'])) {
@@ -268,7 +269,7 @@ class SqlTable
 			$options['select'] = is_array($options['select']) ? $options['select'] : [$options['select']];
 			$select_sql = implode(', ', $options['select']);
 		}
-		if (! empty($options['CALC_FOUND_ROWS'])) {
+		if (! empty($options['CALC_FOUND_ROWS']) && stripos($select_sql, 'SQL_CALC_FOUND_ROWS') === false) {
 			$select_sql = 'SQL_CALC_FOUND_ROWS ' . $select_sql;
 		}
 		if (! empty($options['where'])) {

+ 19 - 0
src/Database/Sql/SqlTableModel.php

@@ -9,6 +9,7 @@ class SqlTableModel
 {
 	public static $table_name = '';
 	public static $primary_key = [];
+	protected static $default_item = [];
 
 
 	public static function getDb()
@@ -67,6 +68,17 @@ class SqlTableModel
 	}
 
 
+	public static function getAllPagination($where=null, $options=[])
+	{
+		$db = static::getDb();
+		static::checkTable();
+		
+		$tuple = $db->getTable(static::$table_name)->getAllWithFoundRows($where, $options);
+		//list($found_rows, $data) = $tuple;
+		return $tuple;
+	}
+
+
 
 	public static function one($where=[], $options=[])
 	{
@@ -158,4 +170,11 @@ class SqlTableModel
 
 	}
 
+
+
+	public static function getDefaultItem()
+	{
+		return array_slice(static::$default_item, 0);
+	}
+
 }