# HG changeset patch # User Michiel Broek # Date 1559659078 -7200 # Node ID ccd85f0ed96c1c395bc06f4c51d7e4e738f4bca7 # Parent 5020feba78ecfa39268cfc781fb630858dd75d15 Added ingredient sorting to the database write functions. diff -r 5020feba78ec -r ccd85f0ed96c www/includes/db_product.php --- a/www/includes/db_product.php Sun Jun 02 19:56:44 2019 +0200 +++ b/www/includes/db_product.php Tue Jun 04 16:37:58 2019 +0200 @@ -258,12 +258,23 @@ $sql .= "', prop4_type='" . $_POST['prop4_type']; $sql .= "', prop4_volume='" . $_POST['prop4_volume']; } - syslog(LOG_NOTICE, $sql); +// syslog(LOG_NOTICE, $sql); $fermentables = '['; $comma = FALSE; if (isset($_POST['fermentables'])) { $array = $_POST['fermentables']; + // Sort the array + $added = array(); + $amount = array(); + for ($i = 0; $i < count($array); $i++) { + $added[] = $array[$i]['f_added']; + $amount[] = $array[$i]['f_amount']; + } + array_multisort($added, SORT_ASC, SORT_NUMERIC, + $amount, SORT_DESC, SORT_NUMERIC, + $array); + // Write the sorted array. foreach($array as $key => $item){ /* * Manual encode to json. @@ -304,6 +315,20 @@ $comma = FALSE; if (isset($_POST['hops'])) { $array = $_POST['hops']; + // Sort the array + $useat = array(); + $time = array(); + $amount = array(); + for ($i = 0; $i < count($array); $i++) { + $useat[] = $array[$i]['h_useat']; + $time[] = $array[$i]['h_time']; + $amount[] = $array[$i]['h_amount']; + } + array_multisort($useat, SORT_ASC, SORT_NUMERIC, + $time, SORT_DESC, SORT_NUMERIC, + $amount, SORT_DESC, SORT_NUMERIC, + $array); + // Write the sorted array. foreach($array as $key => $item){ if ($comma) $hops .= ','; @@ -335,6 +360,20 @@ $comma = FALSE; if (isset($_POST['miscs'])) { $array = $_POST['miscs']; + // Sort the array + $use = array(); + $type = array(); + $amount = array(); + for ($i = 0; $i < count($array); $i++) { + $use[] = $array[$i]['m_use_use']; + $type[] = $array[$i]['m_type']; + $amount[] = $array[$i]['m_amount']; + } + array_multisort($use, SORT_ASC, SORT_NUMERIC, + $type, SORT_ASC, SORT_NUMERIC, + $amount, SORT_DESC, SORT_NUMERIC, + $array); + // Write the sorted array. foreach($array as $key => $item){ if ($comma) $miscs .= ','; @@ -357,6 +396,17 @@ $comma = FALSE; if (isset($_POST['yeasts'])) { $array = $_POST['yeasts']; + // Sort the array + $use = array(); + $amount = array(); + for ($i = 0; $i < count($array); $i++) { + $use[] = $array[$i]['y_use']; + $amount[] = $array[$i]['y_amount']; + } + array_multisort($use, SORT_ASC, SORT_NUMERIC, + $amount, SORT_DESC, SORT_NUMERIC, + $array); + // Write the sorted array. foreach($array as $key => $item){ if ($comma) $yeasts .= ','; @@ -387,6 +437,13 @@ $comma = FALSE; if (isset($_POST['mashs'])) { $array = $_POST['mashs']; + // Sort the array + $temp = array(); + for ($i = 0; $i < count($array); $i++) { + $temp[] = $array[$i]['step_temp']; + } + array_multisort($temp, SORT_ASC, SORT_NUMERIC, $array); + // Write the sorted array. foreach($array as $key => $item){ if ($comma) $mashs .= ','; diff -r 5020feba78ec -r ccd85f0ed96c www/includes/db_recipes.php --- a/www/includes/db_recipes.php Sun Jun 02 19:56:44 2019 +0200 +++ b/www/includes/db_recipes.php Tue Jun 04 16:37:58 2019 +0200 @@ -124,6 +124,17 @@ $comma = FALSE; if (isset($_POST['fermentables'])) { $array = $_POST['fermentables']; + // Sort the array + $added = array(); + $amount = array(); + for ($i = 0; $i < count($array); $i++) { + $added[] = $array[$i]['f_added']; + $amount[] = $array[$i]['f_amount']; + } + array_multisort($added, SORT_ASC, SORT_NUMERIC, + $amount, SORT_DESC, SORT_NUMERIC, + $array); + // Write the sorted array. foreach($array as $key => $item){ /* * Manual encode to json. @@ -164,6 +175,20 @@ $comma = FALSE; if (isset($_POST['hops'])) { $array = $_POST['hops']; + // Sort the array + $useat = array(); + $time = array(); + $amount = array(); + for ($i = 0; $i < count($array); $i++) { + $useat[] = $array[$i]['h_useat']; + $time[] = $array[$i]['h_time']; + $amount[] = $array[$i]['h_amount']; + } + array_multisort($useat, SORT_ASC, SORT_NUMERIC, + $time, SORT_DESC, SORT_NUMERIC, + $amount, SORT_DESC, SORT_NUMERIC, + $array); + // Write the sorted array. foreach($array as $key => $item){ if ($comma) $hops .= ','; @@ -195,6 +220,20 @@ $comma = FALSE; if (isset($_POST['miscs'])) { $array = $_POST['miscs']; + // Sort the array + $use = array(); + $type = array(); + $amount = array(); + for ($i = 0; $i < count($array); $i++) { + $use[] = $array[$i]['m_use_use']; + $type[] = $array[$i]['m_type']; + $amount[] = $array[$i]['m_amount']; + } + array_multisort($use, SORT_ASC, SORT_NUMERIC, + $type, SORT_ASC, SORT_NUMERIC, + $amount, SORT_DESC, SORT_NUMERIC, + $array); + // Write the sorted array. foreach($array as $key => $item) { if ($comma) $miscs .= ','; @@ -217,7 +256,17 @@ $comma = FALSE; if (isset($_POST['yeasts'])) { $array = $_POST['yeasts']; -syslog(LOG_NOTICE, $_POST['yeasts']); + // Sort the array + $use = array(); + $amount = array(); + for ($i = 0; $i < count($array); $i++) { + $use[] = $array[$i]['y_use']; + $amount[] = $array[$i]['y_amount']; + } + array_multisort($use, SORT_ASC, SORT_NUMERIC, + $amount, SORT_DESC, SORT_NUMERIC, + $array); + // Write the sorted array. foreach($array as $key => $item) { if ($comma) $yeasts .= ','; @@ -248,6 +297,13 @@ $comma = FALSE; if (isset($_POST['mashs'])) { $array = $_POST['mashs']; + // Sort the array + $temp = array(); + for ($i = 0; $i < count($array); $i++) { + $temp[] = $array[$i]['step_temp']; + } + array_multisort($temp, SORT_ASC, SORT_NUMERIC, $array); + // Write the sorted array. foreach($array as $key => $item) { if ($comma) $mashs .= ',';