Changeset 5983

Show
Ignore:
Timestamp:
05/13/07 19:16:28 (2 years ago)
Author:
rambo
Message:

bulletproofing against failure to load component and auto_wildcards support to universalchooser

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/midcom.helper.datamanager2/exec/universalchooser_handler.php

    r4547 r5983  
    2828    exit(); 
    2929} 
     30// Convert tradiotional wildcard to SQL wildcard 
    3031$search = str_replace('*', '%', $_REQUEST['search']); 
     32// Make sure we don't have multiple successive wildcards (performance killer) 
     33$search = preg_replace('/%+/', '%', $search); 
    3134 
    3235// 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'); 
    3437foreach ($map as $varname) 
    3538{ 
     
    8790} 
    8891 
     92// Handle automatic wildcards 
     93if (   !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} 
    89112// Load component if required 
    90113if (!class_exists($class)) 
    91114{ 
    92     $_MIDCOM->componentloader->load($component); 
     115    $_MIDCOM->componentloader->load_graceful($component); 
    93116} 
    94117// Could not get required class defined, abort 
     
    145168} 
    146169 
    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(); 
     170if (preg_match('/^%+$/', $search)) 
     171
     172    debug_add('$search is all wildcards, don\'t was time with adding LIKE constraints'); 
     173
     174else 
     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
    154184 
    155185if (is_array($orders)) 
  • trunk/src/midcom.helper.datamanager2/widget/universalchooser.php

    r5071 r5983  
    122122     */ 
    123123    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; 
    124136 
    125137   /** 
     
    345357        // Serialize the parameter we need in the search end 
    346358        $searchconstraints_serialized = "idsuffix={$idsuffix}"; 
    347         $serialize = array('component', 'class', 'titlefield', 'idfield', 'searchfields'); 
     359        $serialize = array('component', 'class', 'titlefield', 'idfield', 'searchfields', 'auto_wildcards'); 
    348360        foreach ($serialize as $field) 
    349361        {