@@ -935,47 +935,52 @@ public function register_search_fields(Request $request)
935935 // Forget last search
936936 session ()->forget ('search_fields ' );
937937
938+ // Start buildind this search URL
939+ $ search_URL = route (Setting::grab ('main_route ' ) . '.search ' );
940+
938941 // Check all fields
939942 $ a_fields = array_merge ($ this ->a_search_fields_numeric , $ this ->a_search_fields_text , $ this ->a_search_fields_date , $ this ->a_search_fields_text_special , ['department_id ' , 'list ' ]);
940943 foreach ($ a_fields as $ field ){
941944 if ($ request ->filled ($ field )){
942- $ search_fields [$ field ] = $ request ->{$ field };
943- }
944- }
945-
946- // Register date field related types (specified with radio buttons)
947- foreach ($ this ->a_search_fields_date as $ field ){
948- if ($ request ->filled ($ field )){
949- $ search_fields [$ field . '_type ' ] = $ request ->{$ field . '_type ' };
950- }
951- }
945+ // Add field to search
946+ $ search_fields [$ field ] = $ value_URL = is_array ($ request ->{$ field }) ? implode (', ' , $ request ->{$ field }) : $ request ->{$ field };
952947
953- // Check ticket tags
954- if ($ request ->filled ('category_id ' ) and $ request ->filled ('category_ ' . $ request ->category_id . '_tags ' )){
955- $ search_fields ['tags ' ] = $ request ->{'category_ ' . $ request ->category_id . '_tags ' };
956- }
957-
958- if (isset ($ search_fields )){
959- // Store search fields in session to use in datatable
960- session (compact ('search_fields ' ));
961-
962- // Build this search URL
963- $ search_URL = route (Setting::grab ('main_route ' ) . '.search ' );
964- foreach ($ search_fields as $ field => $ value ){
965- if (in_array ($ field , $ this ->a_search_fields_date )){
966- $ carbon_instance = Carbon::createFromFormat (trans ('panichd::lang.datetime-format ' ), $ value );
967- if ($ search_fields [$ field . '_type ' ] == 'exact_year ' ){
948+ // Update date field in certain cases (Requires field type specified with radio buttons)
949+ if (in_array ($ field , $ this ->a_search_fields_date ) and $ request ->filled ($ field . '_type ' )){
950+
951+ $ carbon_instance = Carbon::createFromFormat (trans ('panichd::lang.datetime-format ' ), $ search_fields [$ field ]);
952+ if ($ request ->{$ field . '_type ' } == 'exact_year ' ){
968953 // If a date field type is "exact_year", show only year in URL
969- $ value = $ carbon_instance ->format ('Y ' );
954+ $ value_URL = $ carbon_instance ->format ('Y ' );
970955
971- }elseif ($ search_fields [ $ field . '_type ' ] == 'exact_day ' ){
956+ }elseif ($ request ->{ $ field . '_type ' } == 'exact_day ' ){
972957 // If a date field type is "exact_day", show only locale datetime string in URL
973- $ value = $ carbon_instance ->format (trans ('panichd::lang.date-format ' ));
958+ $ value_URL = $ carbon_instance ->format (trans ('panichd::lang.date-format ' ));
974959 }
975-
976960 }
977- $ search_URL .= '/ ' . $ field . '/ ' . (is_array ($ value ) ? implode (', ' , $ value ) : $ value );
961+
962+ // Add field in search URL
963+ $ search_URL .= '/ ' . $ field . '/ ' . $ value_URL ;
964+
965+ // Register date type and add in URL
966+ if (in_array ($ field , $ this ->a_search_fields_date ) and $ request ->filled ($ field . '_type ' )){
967+ $ search_fields [$ field . '_type ' ] = $ request ->{$ field . '_type ' };
968+
969+ $ search_URL .= '/ ' . $ field . '_type/ ' . $ search_fields [$ field . '_type ' ];
970+ }
971+
972+ // Register ticket tags and add in URL
973+ if ($ field == 'category_id ' and $ request ->filled ('category_ ' . $ request ->category_id . '_tags ' )){
974+ $ search_fields ['tags ' ] = $ request ->{'category_ ' . $ request ->category_id . '_tags ' };
975+
976+ $ search_URL .= '/tags/ ' . implode (', ' , $ search_fields ['tags ' ]);
977+ }
978978 }
979+ }
980+
981+ if (isset ($ search_fields )){
982+ // Store search fields in session to use in datatable
983+ session (compact ('search_fields ' ));
979984
980985 // Success message
981986 $ result = "ok " ;
0 commit comments