Framework  3.9
StringSearchParameterHandler Class Reference

StringSearchParameterHandler is a SearchParameterHandler for text database types. More...

+ Inheritance diagram for StringSearchParameterHandler:
+ Collaboration diagram for StringSearchParameterHandler:

Public Member Functions

 equal ($name, $value)
 Generates the constraint expression for equality matching parameters. More...
 
 like ($name, $value)
 Generates the constraint expression for 'like' matching parameters, i.e. More...
 
 startsWith ($name, $value)
 Generates the constraint expression for 'startsWith' matching parameters, i.e. More...
 
 from ($name, $from)
 Generates the constraint expression for 'from' matching parameters, i.e. More...
 
 to ($name, $to)
 Generates the constraint expression for 'to' matching parameters, i.e. More...
 
 range ($name, $from, $to)
 Generates the constraint expression for 'range' matching parameters, i.e. More...
 
 any ($name, $value)
 Generate the constraint expression for matching any word in a group of words. More...
 
 all ($name, $value)
 Generate the constraint expression for matching all words in a group of words but allowing other words in between. More...
 
 fullName ($f_name, $l_name, $value)
 Generate the constraint expression for matching the f_name and l_name fields to a given value. More...
 
 member ($name, $set)
 Generate the constraint expression for set membership matching paramters, matching values in a comma delimite set. More...
 
- Public Member Functions inherited from SearchParameterHandler
 checked ($name, $value)
 Generate the constraint expresssion for matching boolean only when the UI element is selected. More...
 

Detailed Description

StringSearchParameterHandler is a SearchParameterHandler for text database types.

Author
andy

Definition at line 273 of file search_form.inc.

Member Function Documentation

◆ all()

StringSearchParameterHandler::all (   $name,
  $value 
)

Generate the constraint expression for matching all words in a group of words but allowing other words in between.

Parameters
string$namethe name of the field
string$valuea string that may contain multiple words
Returns
string a SQL expression to peform the match

Reimplemented from SearchParameterHandler.

Definition at line 334 of file search_form.inc.

335  {
336  $value = preg_replace("/\\s+/", " ", $value);
337 
338  $words = explode(" ", $value);
339 
340  if (count($words) == 0) return;
341 
342  $query .= " (";
343  $first = true;
344  foreach($words as $word)
345  {
346  $txt = ConnectionManager::quote("%{$word}%");
347  if (!$first) $query .= " AND ";
348  $query .= "$name LIKE $txt";
349  $first = false;
350  }
351  $query .= ")";
352 
353  return $query;
354  }
static quote($str)
Quote a string value based on the character set of the global connection.

◆ any()

StringSearchParameterHandler::any (   $name,
  $value 
)

Generate the constraint expression for matching any word in a group of words.

Parameters
string$namethe name of the field
string$valuea string that may contain multiple words
Returns
string a SQL expression to peform the match

Reimplemented from SearchParameterHandler.

Definition at line 313 of file search_form.inc.

314  {
315  $value = preg_replace("/\\s+/", " ", $value);
316  $words = explode(" ", $value);
317 
318  if (count($words) == 0) return;
319 
320  $query .= " (";
321  $first = true;
322  foreach($words as $word)
323  {
324  $txt = ConnectionManager::quote("%{$word}%");
325  if (!$first) $query .= " OR ";
326  $query .= "$name LIKE $txt";
327  $first = false;
328  }
329  $query .= ")";
330 
331  return $query;
332  }

◆ equal()

StringSearchParameterHandler::equal (   $name,
  $value 
)

Generates the constraint expression for equality matching parameters.

Parameters
string$namethe name of the field
mixed$valuethe value to match
Returns
string a SQL expression to perform the match

Reimplemented from SearchParameterHandler.

Definition at line 275 of file search_form.inc.

276  {
277  $txt = ConnectionManager::quote($value);
278  return "$name=$txt";
279  }

◆ from()

StringSearchParameterHandler::from (   $name,
  $from 
)

Generates the constraint expression for 'from' matching parameters, i.e.

matching values that are greater than or equal to the specified value.

Parameters
string$namethe name of the field
mixed$fromthe lower bound
Returns
string a SQL expression to perform the match

Reimplemented from SearchParameterHandler.

Definition at line 293 of file search_form.inc.

294  {
295  $txt = ConnectionManager::quote($from);
296  return "$name >= $txt";
297  }

◆ fullName()

StringSearchParameterHandler::fullName (   $f_name,
  $l_name,
  $value 
)

Generate the constraint expression for matching the f_name and l_name fields to a given value.

Parameters
string$f_namethe name of the first name field
string$l_namethe name of the last name field
string$valuea string that may contain multiple words
Returns
string a SQL expression to perform the match

Reimplemented from SearchParameterHandler.

Definition at line 357 of file search_form.inc.

358  {
359  $value = preg_replace("/\\s+/", " ", $value);
360  $words = explode(" ", $value);
361 
362  if(count($words) < 2) return;
363 
364  $idx = 0;
365  $query = " (";
366  $first = true;
367 
368  while($idx < count($words)-1)
369  {
370  if (!$first) $query .= " OR (";
371 
372  $txt1 = ConnectionManager::quote("%{$words[$idx]}%");
373  $txt2 = ConnectionManager::quote("%{$words[$idx+1]}%");
374  $query .= "{$f_name} LIKE $txt1 AND {$l_name} LIKE $txt2";
375 
376  $idx += 1;
377  $query .= ") ";
378  $first = false;
379  }
380 
381  return $query;
382  }

◆ like()

StringSearchParameterHandler::like (   $name,
  $value 
)

Generates the constraint expression for 'like' matching parameters, i.e.

matching a substring or partial match.

Parameters
string$namethe name of the field
mixed$valuethe value to match
Returns
string a SQL expression to perform the match

Reimplemented from SearchParameterHandler.

Definition at line 281 of file search_form.inc.

282  {
283  $txt = ConnectionManager::quote("%{$value}%");
284  return "$name LIKE $txt";
285  }

◆ member()

StringSearchParameterHandler::member (   $name,
  $set 
)

Generate the constraint expression for set membership matching paramters, matching values in a comma delimite set.

Parameters
string$namethe name of the field
string$seta comma delimited set of values to match
Returns
string a SQL expression to peform the match

Reimplemented from SearchParameterHandler.

Definition at line 389 of file search_form.inc.

390  {
391  trace("## STRINGSEARCHPARAMETERHANDLER", 1);
392  if(!$set || !isset($set)) return "";
393 
394  $values = $set;
395  if(is_array($set))
396  {
397  $values = "'". implode("','", array_keys($set)) . "'";
398  }
399  else if($set)
400  {
401  $values = "'".implode("','", explode(",", $set))."'";
402  $values = preg_replace("/''/", "'", $values);
403  }
404 
405  return "$name IN ($values)";
406  }
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.
Definition: functions.inc:1010

◆ range()

StringSearchParameterHandler::range (   $name,
  $from,
  $to 
)

Generates the constraint expression for 'range' matching parameters, i.e.

matching values that within the range of the two specified values.

Parameters
string$namethe name of the field
string$fromthe lower bound
mixed$tothe value to match
Returns
string a SQL expression to perform the match

Reimplemented from SearchParameterHandler.

Definition at line 305 of file search_form.inc.

306  {
307  $from = ConnectionManager::quote($from);
308  $to = ConnectionManager::quote($to);
309 
310  return "($name >= $from AND $name <= $to)";
311  }

◆ startsWith()

StringSearchParameterHandler::startsWith (   $name,
  $value 
)

Generates the constraint expression for 'startsWith' matching parameters, i.e.

matching a substring or partial match at the start of the field only.

Parameters
string$namethe name of the field
string$valuethe value to match
Returns
string a SQL expression to perform the match

Reimplemented from SearchParameterHandler.

Definition at line 287 of file search_form.inc.

288  {
289  $txt = ConnectionManager::quote("{$value}%");
290  return "$name LIKE $txt";
291  }

◆ to()

StringSearchParameterHandler::to (   $name,
  $to 
)

Generates the constraint expression for 'to' matching parameters, i.e.

matching values that are less than or equal to the specified value.

Parameters
string$namethe name of the field
mixed$tothe upper bound
Returns
string a SQL expression to perform the match

Reimplemented from SearchParameterHandler.

Definition at line 299 of file search_form.inc.

300  {
301  $txt = ConnectionManager::quote($to);
302  return "$name <= $txt";
303  }

The documentation for this class was generated from the following file: