Packageindex Classtrees Modulegroups Elementlist Report XML Files

pxdb.content.output

pxdb_search

pxdb_data
   |
  +-- pxdb_search

public class pxdb_search extends pxdb_data

Read the documentation for instructions and examples on searching & filtering result sets. Filters may be used in conjunction with the pxdb_collection class. By themselves instances of this class will not filter on privileges or record approval status (they will only filter on values specified through the add_value() or add_var() methods).

AuthorsHans Lellelid <hans@velum.net>
Version$Revision: 1.15 $

 

Methods inherited from pxdb_data

pxdb_data, set_show_unapproved, get_datatype, get_datatype_list, get_datatype_array, set_datatype, bind_tpl, bind_auth, lookup_colname, lookup_tfid, get_column_identifiers, get_identifiers, set_user_minimal_columns, sql_minimal_columns, sql_aliased_columns

Public Method Summary

void pxdb_search([ mixed $dt ])
Initializes the filter system. Use the factory class methods instead.
Object &search([ mixed $dt ])
Factory method for returning a 'search' version of this class.
object Reference &filter([ mixed $dt ])
Factory method for returning a 'filter' version of this class.
void set_value_conj(string $conj)
Set the conjunction to use between multiple values specified for a given field.
string set_conj(string $conj)
Sets the conjunction to use.
boolean set_type(string $type)
Sets the type for this filter: 'search' or 'filter'.
string get_where_sql([ object [unknown] $obj, string $records_alias ])
Based on filter values, gets the SQL that will be inserted into the *WHERE* clause of the SQL statement.
array get_join_sql([ object [unknown] $obj, string $records_alias ])
Based on filter values, gets the SQL that will be inserted into the *FROM* clause of the SQL statement.
void merge(object [unknown] &$filter)
Merges an pxdb_filter object with the current pxdb_filter object.
boolean add_related(object [unknown] &$filter, [ mixed $relid ])
Relate an pxdb_filter to the current filter via primaryrel table.
void add_secondaryrel_related(object [unknown] &$filter)
Relate an pxdb_filter to the current filter via secondaryrel table.
void add_parent(object [unknown] $filter, [ int $noderel_id, resource $weight_sort ])
Relate an pxdb_filter as the parent of the current object (noderel).
void add_child(object [unknown] &$filter, [ int $noderel_id ])
Relate an pxdb_filter as the child of the current object (noderel).
boolean add_value(string $fname, string $value, [ string $relop, string $fieldopt, boolean $quote ])
Adds a filter value.
boolean add_var(string $fname, string $varname, [ string $relop, string $fieldopt, boolean $quote ])
Adds a field based on a varname.
array get_vars([ Object $obj ])
Recursive function to get all variable names that are used by this record & any related records
void pass([ string $method ])
Pass currently set filters via URL or HTML form elements.
boolean is_filtered()
Whether or not any of the filter values are currently set.
string clean_querystring()
Clears the values that are set for the filters in the query string.
array get_values_array()
Get an array of values for all set filters.
string get_values_list([ string $delim, string $smart_end ])
Get a formatted list of the current filter values.
string filter_sql(string $sql)
Filters a SQL statement by adding in statements to the JOIN and WHERE clauses.

Private Method Summary

string _get_relop_sql(string $relop)
Get the SQL snippet for a given rel operator.
boolean _add_field(string $fname, string $var, [ string $relop, string $source, string $fieldopt, boolean $quote ])
Adds a field to be filtered on.
string _clean_varname(string $varname)
Cleans out any PHP global variable arrays from the passed variable name.

Fields inherited from pxdb_data

$debug, $errors, $datatype, $auth, $tpl, $show_unapproved, $db, $user_minimal_columns

Public Field Summary

array $fields
Hash of fields we are looking for here.
array $related
The array of related records.
string $default_records_alias
The default top-level records table alias.
string $records_alias
The alias for the current record table.

Private Field Summary

string $_lop
The conjunction / logical operator to use in the WHERE clause.
string $_value_lop
The conjunction / logical operator to use in cases where many values are passed.

Public Method Details

pxdb_search

public void pxdb_search([ mixed $dt ])

 

Parameter
mixed $dt = >>null<<
The datatype(s) that this filter affects. (important for knowing how to look up field names to correponsing typesfields rows)
Returns void


&search

public Object &search([ mixed $dt ])

  Currently identical to constructor.

Parameter
mixed $dt = >>null<<
The datatype(s) that this filter affects. (important for knowing how to look up field names to correponsing typesfields rows)
Returns Object

Instance of this class in search mode.


&filter

public object Reference &filter([ mixed $dt ])

 

Parameter
mixed $dt = >>null<<
The datatype(s) that this filter affects. (important for knowing how to look up field names to correponsing typesfields rows)
Returns object Reference

to an instance of this class in filter mode.


set_value_conj

public void set_value_conj(string $conj)

 

Parameter
string $conj
The conjunction / logical operator to use. (e.g. 'AND' or 'OR')
Returns void

Since 0.0.2

set_conj

public string set_conj(string $conj)

  Currently there is no difference between this function and set_type(). You can also pass 'filter' or 'search' to set_type() which is what happens when this class is instantiated using the pxdb_search::filter() or pxdb_search::search() methods.

Parameter
string $conj
The conjunction to set.
Returns string

The operator set.

Since 0.0.2

set_type

public boolean set_type(string $type)

  This method sets the logical operator (or conjunction) that is used in the WHERE SQL.

Parameter
string $type
The type of filter this is.
Returns boolean

On success of setting filter.


get_where_sql

public string get_where_sql([ object [unknown] $obj, string $records_alias ])

  Uses current field values and field values of any records related to the current record.

Parameter
object [unknown] $obj = >>null<<
The current pxdb_filter object -- used for recursion.
string $records_alias = >>null<<
The alias of the current records table -- used for recursion.
Returns string

The text that should be inserted in the WHERE clause of SQL statement to activate these filters.


get_join_sql

public array get_join_sql([ object [unknown] $obj, string $records_alias ])

  This includes pickrel values (JOINing to pickrel table) and also any related recors also need to be INNER JOINed to current records table.

Parameter
object [unknown] $obj = >>null<<
The current pxdb_filter object -- used for recursion.
string $records_alias = >>null<<
The alias of the current records table -- used for recursion.
Returns array

The text that should be inserted in the FROM clause of SQL statement to activate these filters as well as the related order by fields.


merge

public void merge(object [unknown] &$filter)

  Fields, related records, pickrel items, datatypes are all merged, with values of current 'name ASC' for $orderby, then new value will be 'date 1 DESC, name ASC'

Parameter
object [unknown] &$filter
The other pxdb_filter object to merge.
Returns void


add_related

public boolean add_related(object [unknown] &$filter, [ mixed $relid ])

 

Parameter
object [unknown] &$filter
The pxdb_filter object to be related.
mixed $relid = >>null<<
The relid(s) by which this object can be related.
Returns boolean

Returns true on success


add_secondaryrel_related

public void add_secondaryrel_related(object [unknown] &$filter)

 

Parameter
object [unknown] &$filter
The pxdb_filter object to related.
Returns void


add_parent

public void add_parent(object [unknown] $filter, [ int $noderel_id, resource $weight_sort ])

  OAM: extended add_parent, the first parameter can now be a filter, or a section object, section id, or a section idnum.

Parameter
object [unknown] $filter
The pxdb_filter to related.
int $noderel_id = >>null<<
The noderel ID to be related.
resource $weight_sort = >>NULL<<
String to indicate if the subsequent collection will be sorted by this noderel.weight, if empty no sorting, otherwise specify ASC or DESC.
Returns void


add_child

public void add_child(object [unknown] &$filter, [ int $noderel_id ])

 

Parameter
object [unknown] &$filter
The pxdb_filter to related.
int $noderel_id = >>null<<
The noderel ID to be related.
Returns void


add_value

public boolean add_value(string $fname, string $value, [ string $relop, string $fieldopt, boolean $quote ])

  Note: filter values are *not* able to be passed on. Also, if you add a filter value using this method, is_filtered() will still report FALSE if no vars are defined.

Parameter
string $fname
The field name to filter on. (May also be a typesfields displayname)
string $value
The value that the given field should match.
string $relop = >>'='<<
The way that the field and value are related. (i.e. field='value' or field LIKE '%value%', etc.)
string $fieldopt = >>null<<
An option field name to lookup up on if getting a pickid value.
boolean $quote = >>true<<
whether or not to quote value
Returns boolean

(documented in _add_field)


add_var

public boolean add_var(string $fname, string $varname, [ string $relop, string $fieldopt, boolean $quote ])

  This is generally the preferred method for adding filters. Why? Because when you add a filter based on a varname (instead of a value) you can use the pass() method to pass the filters (the variables) to another page. Also, the is_filtered() will check to see if any of the filter vars are set. (is_filtered() will return false when only value filters are set.)

Parameter
string $fname
The field name to filter on. (May also be a typesfields displayname)
string $varname
The variable name that holds the value for the given field.
string $relop = >>'='<<
The way that the field and value are related. (i.e. field='value' or field LIKE '%value%', etc.)
string $fieldopt = >>null<<
An option field name to lookup up on if getting a pickid value.
boolean $quote = >>true<<
whether or not to quote value
Returns boolean

(documented in _add_field)


get_vars

public array get_vars([ Object $obj ])

 

Parameter
Object $obj = >>null<<
The object we are working with (used by recursion; will be set to $this on first invocation).
Returns array

Array of all variables used by this filter.


pass

public void pass([ string $method ])

 

Parameter
string $method = >>'form'<<
The way to pass vars -- e.g. 'form' or 'url'.
Returns void


is_filtered

public boolean is_filtered()

 

Returns boolean


clean_querystring

public string clean_querystring()

 

Returns string

the current query string ($QUERY_STRING) without any filter information in it.


get_values_array

public array get_values_array()

 

Returns array

Values for currently defined filters.


get_values_list

public string get_values_list([ string $delim, string $smart_end ])

  This method is for convenience only -- but it has a serious limitation: if you are using multi-select filters (i.e. arrays) you won't be able to use this method -- and will have to build your own display using get_values_array() method.

Parameter
string $delim = >>', '<<
The separator for the items of the array
string $smart_end = >>''<<
The text to add to last element -- e.g. if $smart_element = "and": Boston, Bermuda, and Baltimore.
Returns string

Formatted text list of the values for currently specified filters.


filter_sql

public string filter_sql(string $sql)

  This method provides additional flexibility in working with filters and SQL statements. You could probably build your entire SQL statement simply using combinations of filter & searches, but it may be easier to just build a basic SQL statement and then add the filters. NOTE: This will *not* filter on priv table.

Parameter
string $sql
The SQL statement to filter.
Returns string

The filtered SQL.


Private Method Details

_get_relop_sql

private string _get_relop_sql(string $relop)

  This may need to be moved into a RDBMS-specific library.

Parameter
string $relop
The relop for which to return SQL.
Returns string

The SQL snippet.


_add_field

private boolean _add_field(string $fname, string $var, [ string $relop, string $source, string $fieldopt, boolean $quote ])

  This field may be a regular value or a pickid-type field.

Parameter
string $fname
The field name to filter on. (May also be a typesfields displayname)
string $var
The name of the variable that holds the filter value for this field.
string $relop = >>'='<<
The way that the field and value are related. (i.e. field='value' or field LIKE '%value%', etc.)
string $source = >>'var'<<
Whether the source is a variable or a value
string $fieldopt = >>null<<
An option field name to lookup up on if getting a pickid value.
boolean $quote = >>true<<
whether or not to quote value
Returns boolean


_clean_varname

private string _clean_varname(string $varname)

  E.g. $_REQUEST['myfilter'] -> 'myfiter' $_REQUEST[pxdb][testvar] -> pxdb[testvar]

Parameter
string $varname
Variable name to clean.
Returns string

the cleaned variable name.


Public Field Details

$fields

public array $fields

>><<


$related

public array $related

>><<


$default_records_alias

public string $default_records_alias

>>'r'<<


$records_alias

public string $records_alias

>>''<<


Private Field Details

$_lop

private string $_lop

>>'OR'<<


$_value_lop

private string $_value_lop

>>'OR'<<



Packageindex Classtrees Modulegroups Elementlist Report XML Files
Generated on Fri, 28 Apr 2006 19:07:22 -0400 by PHPDoc v1.5 www.phpdoc.de