From 25677ffa5e957f48da382d4facc1075bdf0082ba Mon Sep 17 00:00:00 2001 From: abijah Date: Sun, 14 Jun 2009 03:22:53 +0000 Subject: [PATCH] Got the mulitcolumn search toolbar in place, but it's not working. First I haven't managed to get an autosearch working (searching as you type). Second, and much more critically, I don't have the controller correctly responding to search terms, as it was implemented rather poorly. I'm moving on for now. git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@113 97e9348a-65ac-dc4b-aefc-98561f571b83 --- app_controller.php | 35 +++++++++++++++------- views/elements/customers.ctp | 57 ++++++++++++++++++++++++------------ 2 files changed, 63 insertions(+), 29 deletions(-) diff --git a/app_controller.php b/app_controller.php index 72d6d8f..7f03fd3 100644 --- a/app_controller.php +++ b/app_controller.php @@ -164,15 +164,25 @@ class AppController extends Controller { } function jqGridDataConditions(&$params) { + $searches = array(); + if (isset($params['_search']) && $params['_search'] === 'true') { - $op = $params['searchOper']; - $field = $params['searchField']; - $string = $params['searchString']; + if (isset($params['searchOper'])) { + $searches[] = array('op' => $params['searchOper'], + 'field' => $params['searchField'], + 'value' => $params['searchString']); + } + else { + // DOH! Crappy mechanism puts toolbar search terms + // directly into params as name/value pairs. No + // way to know which elements of params are search + // terms, so skipping this at the moment. + } } elseif (isset($params['filt']) && $params['filt']) { - $op = 'bw'; - $field = $params['filtField']; - $string = $params['filtString']; + $searches[] = array('op' => 'bw', + 'field' => $params['filtField'], + 'value' => $params['filtString']); } else { return array(); @@ -189,10 +199,15 @@ class AppController extends Controller { 'cn' => array('op' => 'LIKE', 'pre' => '%', 'post' => '%'), ); - $op = $ops[$op]; - $field .= $op['op'] ? ' '.$op['op'] : ''; - $string = $op['pre'] . $string . $op['post']; - return array($field => $string); + $conditions = array(); + foreach ($searches AS $search) { + $op = $ops[$search['op']]; + $field = $search['field'] . ($op['op'] ? ' '.$op['op'] : ''); + $value = $op['pre'] . $search['value']. $op['post']; + $conditions[] = array($field => $value); + } + + return $conditions; } function jqGridDataFields(&$params) { diff --git a/views/elements/customers.ctp b/views/elements/customers.ctp index 341c4d7..f71d590 100644 --- a/views/elements/customers.ctp +++ b/views/elements/customers.ctp @@ -35,6 +35,10 @@ $cols['Comment'] = array('index' => 'Customer.comment', 'width' => foreach (array_intersect_key($cols, array('Comment'=>1)) AS $k => $v) $cols[$k]['sortable'] = false; +// Some of the columns should be searchable +foreach (array_intersect_key($cols, array('Last Name'=>1, 'First Name'=>1)) AS $k => $v) + $cols[$k]['search'] = true; + // Create the javascript code for jqGrid to create each table column $colModels = array(); foreach ($cols AS $col) { @@ -43,7 +47,7 @@ foreach ($cols AS $col) { '{ ' . implode(", ", array_map(create_function ('$k, $v', - 'return "$k:".($v===false?"false":"\'$v\'");'), + 'return "$k:".($v===false?"false":($v===true?"true":"\'$v\'"));'), array_keys($col), array_values($col))) . '}'; @@ -70,8 +74,8 @@ $url = $html->url(array('controller' => 'customers', ?> -
-
-
Search By:
-
-Enable Autosearch -
-
Last Name
+
Search By:
+Enable Autosearch
+Last Name
@@ -139,13 +168,3 @@ function gridReload() { --> -Get Table Code
*/ -/*
*/ - -/*

*/ -/*
*/ -/* Show Loading
*/ -/* Set Top Margin
*/ -/* Set Left Margin
*/ -?> \ No newline at end of file