Changeset 5983
- Timestamp:
- 05/13/07 19:16:28 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/midcom.helper.datamanager2/exec/universalchooser_handler.php
r4547 r5983 28 28 exit(); 29 29 } 30 // Convert tradiotional wildcard to SQL wildcard 30 31 $search = str_replace('*', '%', $_REQUEST['search']); 32 // Make sure we don't have multiple successive wildcards (performance killer) 33 $search = preg_replace('/%+/', '%', $search); 31 34 32 35 // Get local copies of other variables from request 33 $map = array('component', 'class', 'titlefield', 'idsuffix', 'idfield', 'searchfields', 'constraints', 'orders', 'hash' );36 $map = array('component', 'class', 'titlefield', 'idsuffix', 'idfield', 'searchfields', 'constraints', 'orders', 'hash', 'auto_wildcards'); 34 37 foreach ($map as $varname) 35 38 { … … 87 90 } 88 91 92 // Handle automatic wildcards 93 if ( !empty($auto_wildcards) 94 && strpos($search, '%') === false) 95 { 96 switch($auto_wildcards) 97 { 98 case 'both': 99 $search = "%{$search}%"; 100 break; 101 case 'start': 102 $search = "%{$search}"; 103 break; 104 case 'end': 105 $search = "{$search}%"; 106 break; 107 default: 108 debug_add("Don't know how to handle auto_wilcards value '{$auto_wilcards}'", MIDCOM_LOG_WARN); 109 break; 110 } 111 } 89 112 // Load component if required 90 113 if (!class_exists($class)) 91 114 { 92 $_MIDCOM->componentloader->load ($component);115 $_MIDCOM->componentloader->load_graceful($component); 93 116 } 94 117 // Could not get required class defined, abort … … 145 168 } 146 169 147 $qb->begin_group('OR'); 148 foreach ($searchfields as $field) 149 { 150 debug_add("adding search (ORed) constraint: {$field} LIKE '{$search}'"); 151 $qb->add_constraint($field, 'LIKE', $search); 152 } 153 $qb->end_group(); 170 if (preg_match('/^%+$/', $search)) 171 { 172 debug_add('$search is all wildcards, don\'t was time with adding LIKE constraints'); 173 } 174 else 175 { 176 $qb->begin_group('OR'); 177 foreach ($searchfields as $field) 178 { 179 debug_add("adding search (ORed) constraint: {$field} LIKE '{$search}'"); 180 $qb->add_constraint($field, 'LIKE', $search); 181 } 182 $qb->end_group(); 183 } 154 184 155 185 if (is_array($orders)) trunk/src/midcom.helper.datamanager2/widget/universalchooser.php
r5071 r5983 122 122 */ 123 123 var $static_options = array(); 124 125 /** 126 * Whether to automatically append/prepend wildcards to the query 127 * 128 * Valid values: 'both', 'start', 'end' and <empty> (0, '', false & null) 129 * 130 * Example: 131 * 'auto_wildcards' => 'both', 132 * 133 * $var string 134 */ 135 var $auto_wildcards = false; 124 136 125 137 /** … … 345 357 // Serialize the parameter we need in the search end 346 358 $searchconstraints_serialized = "idsuffix={$idsuffix}"; 347 $serialize = array('component', 'class', 'titlefield', 'idfield', 'searchfields' );359 $serialize = array('component', 'class', 'titlefield', 'idfield', 'searchfields', 'auto_wildcards'); 348 360 foreach ($serialize as $field) 349 361 {
