You are here

function _taxonomy_edge_generate_term_path_query in Taxonomy Edge 7.2

Same name and namespace in other branches
  1. 8 taxonomy_edge.module \_taxonomy_edge_generate_term_path_query()
  2. 6 taxonomy_edge.module \_taxonomy_edge_generate_term_path_query()
  3. 7 taxonomy_edge.module \_taxonomy_edge_generate_term_path_query()

Generate query for ordering by dynamically compiled path

Parameters

$pid: Path ID to generate dynamic path from.

Return value

String containing query.

1 call to _taxonomy_edge_generate_term_path_query()
taxonomy_edge_get_tree_optimized in ./taxonomy_edge.core.inc
Reimplementation of taxonomy_get_tree(). Limit db fetch to only specified parent AND use presorting.

File

./taxonomy_edge.module, line 700
Selecting all children of a given taxonomy term can be a pain. This module makes it easier to do this, by maintaining a complete list of edges for each term using the adjecency matrix graph theory.

Code

function _taxonomy_edge_generate_term_path_query($pid) {
  $args = func_get_args();
  $db_type = Database::getConnection()
    ->databaseType();
  switch ($db_type) {
    case 'pgsql':
      return "(SELECT array_to_string(array_agg(((tpx.weight + 1500) || '-' || tpx.name || '-' || tpx.tid)), '/') FROM (SELECT tpd.* FROM taxonomy_term_edge tpe INNER JOIN taxonomy_term_edge_path tpp ON tpe.parent = tpp.pid INNER JOIN taxonomy_term_data tpd ON tpp.tid = tpd.tid WHERE tpe.pid = {$pid} ORDER BY tpe.distance DESC) tpx)";
    case 'mysql':
    case 'mysqli':
      return "(SELECT GROUP_CONCAT(CONCAT(tpd.weight + 1500, '    ', tpd.name, '    ', tpd.tid) ORDER BY tpe.distance DESC SEPARATOR '    ') FROM taxonomy_term_edge tpe INNER JOIN taxonomy_term_edge_path tpp ON tpe.parent = tpp.pid INNER JOIN taxonomy_term_data tpd ON tpp.tid = tpd.tid WHERE tpe.pid = {$pid})";
    case 'sqlite':
      return "(SELECT GROUP_CONCAT(CONCAT(tpd.weight + 1500, '    ', tpd.name, '    ', tpd.tid), '    ') FROM taxonomy_term_edge tpe INNER JOIN taxonomy_term_edge_path tpp ON tpe.parent = tpp.pid INNER JOIN taxonomy_term_data tpd ON tpp.tid = tpd.tid WHERE tpe.pid = {$pid} ORDER BY tpe.distance DESC)";
    default:
  }
}