You are here

function customfilter_get_filters in Custom filter 5

Get filters from database

Parameters

$sid: ID of the filter set.

$root: The root filter. Return the tree of filters with this filter as the root.

$sortby: Sort the result (and subfilters) by this field (default: sort by weight).

Return value

Array of filters (each have ['sub'], contains subfilters if any).

5 calls to customfilter_get_filters()
customfilter_delete_set in ./customfilter.module
customfilter_filter_render_table in ./customfilter.module
Render the table of filters.
customfilter_set_delete in ./customfilter.module
Delete a filter set.
customfilter_xml_filterset in ./customfilter.module
_customfilter_process in ./customfilter.module
Filter process function.

File

./customfilter.module, line 929

Code

function customfilter_get_filters($sid, $root = 0, $sortby = 'weight', $cols = '*') {
  static $filters;
  if (!is_array($filters)) {
    $filters = array();
  }
  if (!isset($filters[$sid]) || $root > 0) {

    // Prepare columns to select
    if (!is_array($cols)) {
      $cols = array(
        $cols,
      );
    }
    $columns = join(', ', $cols);

    // Prepare nodes
    $nodes = array();
    if (is_array($root)) {
      $nodes = $root;
    }
    else {
      $nodes = array(
        $root,
      );
    }
    foreach ($nodes as $node) {
      $result = db_query("SELECT {$columns} FROM {customfilter_filter} WHERE sid = %d and parentid = %d ORDER BY {$sortby}", $sid, $node);
      while ($filter = db_fetch_array($result)) {
        $filter['sub'] = customfilter_get_filters($sid, $filter['fid'], $sortby, $cols);
        $filters[$sid][$filter['fid']] = $filter;
      }
    }
  }
  return $filters[$sid];
}