Преглед на файлове

Merge branch 'master' of ssh://gogs.vipe.re:6022/KarmaSolutions/KarmaFW

Max F преди 5 години
родител
ревизия
84dd11f7e6
променени са 4 файла, в които са добавени 51 реда и са изтрити 2 реда
  1. 3 1
      helpers/helpers_array.php
  2. 4 0
      helpers/helpers_default.php
  3. 25 1
      src/Database/Sql/SqlTable.php
  4. 19 0
      src/Database/Sql/SqlTableModel.php

+ 3 - 1
helpers/helpers_array.php

@@ -120,6 +120,8 @@ if (! function_exists('get_csv')) {
 
 if (! function_exists('exportToCsvFile')) {
 	function exportToCsvFile($rows, $export_filename=null, $fields=null) {
+		$csv_content = get_csv($rows, $fields);
+		
 		if (! empty($export_filename)) {
 			// download file
 			header('Content-Type: text/csv');
@@ -131,7 +133,7 @@ if (! function_exists('exportToCsvFile')) {
 			header('Content-Type: text/plain');
 		}
 
-		echo get_csv($rows, $fields);
+		echo $csv_content;
 		exit;
 	}
 }

+ 4 - 0
helpers/helpers_default.php

@@ -49,6 +49,10 @@ if (! function_exists('errorHttp')) {
 
 if (! function_exists('redirect')) {
 	function redirect($url, $http_code=302) {
+		if ($http_code == 'link' || $http_code == 'debug') {
+			echo 'continue to <a href="' . $url . '">' . $url . '</a>';
+			exit;
+		}
 		header('Location: ' . $url, true, $http_code);
 		exit;
 	}

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

@@ -71,6 +71,29 @@ class SqlTable
 			return null;
 		}
 
+		if (! empty($options['on duplicate key updates'])) {
+			$options['on_duplicate_key_updates'] = $options['on duplicate key updates'];
+		}
+		if (! empty($options['on_duplicate_key_update'])) {
+			$options['on_duplicate_key_updates'] = $options['on_duplicate_key_update'];
+		}
+		if (! empty($options['on duplicate key update'])) {
+			$options['on_duplicate_key_updates'] = $options['on duplicate key update'];
+		}
+		if (! empty($options['on duplicate key'])) {
+			$options['on_duplicate_key_updates'] = $options['on duplicate key'];
+		}
+		if (! empty($options['on_duplicate_key'])) {
+			$options['on_duplicate_key_updates'] = $options['on_duplicate_key'];
+		}
+		if (! empty($options['on_duplicate'])) {
+			$options['on_duplicate_key_updates'] = $options['on_duplicate'];
+		}
+		if (! empty($options['on duplicate'])) {
+			$options['on_duplicate_key_updates'] = $options['on duplicate'];
+		}
+
+
 		$inserts_sql = implode(', ', $values_array);
 
 		$ignore_sql = empty($options['ignore']) ? '' : 'ignore';
@@ -202,6 +225,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 +292,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);
+	}
+
 }