Framework  3.9
DateSearchParameterHandler Class Reference

DateSearchParameterHandler is a SearchParameterHandler for date database types. More...

+ Inheritance diagram for DateSearchParameterHandler:
+ Collaboration diagram for DateSearchParameterHandler:

Public Member Functions

 reformatToSQLDate ($date)
 
 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...
 
- Public Member Functions inherited from SearchParameterHandler
 member ($name, $set)
 Generate the constraint expression for set membership matching paramters, matching values in a comma delimite set. 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...
 
 checked ($name, $value)
 Generate the constraint expresssion for matching boolean only when the UI element is selected. More...
 

Detailed Description

DateSearchParameterHandler is a SearchParameterHandler for date database types.

Author
andy

Definition at line 415 of file search_form.inc.

Member Function Documentation

◆ equal()

DateSearchParameterHandler::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 439 of file search_form.inc.

440  {
441  $date = $this->reformatToSQLDate($value);
442  return "$name='$date'";
443  }

◆ from()

DateSearchParameterHandler::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 456 of file search_form.inc.

457  {
458 
459  $from = $this->reformatToSQLDate($from);
460  return "$name >= '$from'";
461  }

◆ like()

DateSearchParameterHandler::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 445 of file search_form.inc.

446  {
447  //TODO: Fuzzy Date Matching Logic
448  die("Inappropriate matching mode");
449  }

◆ range()

DateSearchParameterHandler::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 469 of file search_form.inc.

470  {
471  $from = $this->reformatToSQLDate($from);
472  $to = $this->reformatToSQLDate($to);
473 
474  if ($from > $to)
475  {
476  $tmp = $from;
477  $from = $to;
478  $to = $tmp;
479  }
480 
481  return "($name BETWEEN '$from' AND '$to')";
482  }

◆ reformatToSQLDate()

DateSearchParameterHandler::reformatToSQLDate (   $date)

Definition at line 417 of file search_form.inc.

418  {
419  trace($date, 3);
420  $fields = array();
421  if (preg_match("|^(\\d+)[\-/](\\d+)[\-/](\\d{4})$|", $date, $fields))
422  {
423  $date = $fields[3]."-".$fields[1]."-".$fields[2];
424  // JDG 5/2012 - need month and day to have "0" if single digit
425  $date = date('Y-m-d', strtotime($date));
426  }
427  // datetime
428  else if (preg_match("|^(\\d+)/(\\d+)/(\\d{4})\\s+(\\d+:\\d+:\\d+)|", $date, $fields))
429  {
430  // JDG 5/2012 - need month and day to have "0" if single digit
431  $date = date('Y-m-d', strtotime($date));
432  $date = $fields[3]."-".$fields[1]."-".$fields[2]." ".$fields[4];
433  }
434 
435  return ConnectionManager::escape($date);
436  }
static escape($str)
Escapes a string based on the character set of the global connection.
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.
Definition: functions.inc:1010

◆ startsWith()

DateSearchParameterHandler::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 451 of file search_form.inc.

452  {
453  die("Inappropriate matching mode");
454  }

◆ to()

DateSearchParameterHandler::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 463 of file search_form.inc.

464  {
465  $to = $this->reformatToSQLDate($to);
466  return "$name <= '$to'";
467  }

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