From 8098c3b695024294cc9da746f9dd2bea59922a8b Mon Sep 17 00:00:00 2001 From: Derick Turner Date: Wed, 3 May 2023 12:29:49 +0100 Subject: [PATCH] IOMAD: /blocks/iomad_commerce/orderslist is throwing errors when trying to filter by name #1827 --- .../classes/tables/orders_table.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/blocks/iomad_commerce/classes/tables/orders_table.php b/blocks/iomad_commerce/classes/tables/orders_table.php index 5840523a0dd..1f367887468 100644 --- a/blocks/iomad_commerce/classes/tables/orders_table.php +++ b/blocks/iomad_commerce/classes/tables/orders_table.php @@ -143,4 +143,36 @@ public function col_actions($row) { } return $editbutton; } + + /** + * @return string sql to add to where statement. + */ + function get_sql_where() { + global $DB, $SESSION; + + $uniqueid = 'block_iomad_commerce_orders_table'; + + if (isset($SESSION->flextable[$uniqueid])) { + $prefs = $SESSION->flextable[$uniqueid]; + } else if (!$prefs = json_decode(get_user_preferences("flextable_{$uniqueid}", ''), true)) { + return ''; + } + + $conditions = array(); + $params = array(); + + static $i = 0; + $i++; + + if (!empty($prefs['i_first'])) { + $conditions[] = $DB->sql_like('u.firstname', ':ifirstc'.$i, false, false); + $params['ifirstc'.$i] = $prefs['i_first'].'%'; + } + if (!empty($prefs['i_last'])) { + $conditions[] = $DB->sql_like('u.lastname', ':ilastc'.$i, false, false); + $params['ilastc'.$i] = $prefs['i_last'].'%'; + } + + return array(implode(" AND ", $conditions), $params); + } }