You are here

function _taxonomy_edge_generate_term_path_query in Taxonomy Edge 6

Same name and namespace in other branches
  1. 8 taxonomy_edge.module \_taxonomy_edge_generate_term_path_query()
  2. 7.2 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

$tid: Term ID to generate dynamic path from.

Return value

String containing query.

3 calls 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.
taxonomy_edge_rebuild_order in ./taxonomy_edge.rebuild.inc
Rebuild the sorted tree.
views_handler_sort_term_edge_hierarchy::query in views_taxonomy_edge/handlers/views_handler_sort_term_edge_hierarchy.inc
Overridden to add the ORDER BY clause and join required tables.

File

./taxonomy_edge.module, line 562
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($tid) {
  $args = func_get_args();
  global $db_type;
  switch ($db_type) {
    case 'pgsql':
      return "(SELECT array_to_string(array_agg(((tpx.weight + 1500) || tpx.name || '    ' || tpx.tid)), '    ') FROM (SELECT tpd.* FROM {term_edge} tpe INNER JOIN {term_data} tpd ON tpd.tid = tpe.parent WHERE tpe.tid = {$tid} ORDER BY tpe.distance DESC) tpx)";
    case 'mysql':
    case 'mysqli':
      return "(SELECT GROUP_CONCAT(tpd.weight + 1500, tpd.name, '    ', tpd.tid ORDER BY tpe.distance DESC SEPARATOR '    ') FROM {term_edge} tpe INNER JOIN {term_data} tpd ON tpd.tid = tpe.parent WHERE tpe.tid = {$tid})";
    case 'sqlite':
      return "(SELECT GROUP_CONCAT(val, '    ') FROM (SELECT (tpd.weight + 1500) || tpd.name || '    ' || tpd.tid AS val FROM {term_edge} tpe INNER JOIN {term_data} tpd ON tpd.tid = tpe.parent WHERE tpe.tid = {$tid} ORDER BY tpe.distance DESC))";
    case 'sqlsrv':
      return "(SELECT RTRIM((\n                     SELECT CAST(tpd.weight + 1500 as nvarchar) + tpd.name + '    ' + CAST(tpd.tid as nvarchar) + '    '\n                     FROM {term_edge} tpe\n                     JOIN {term_data} tpd ON tpd.tid = tpe.parent\n                     WHERE tpe.tid = {$tid}\n                     ORDER BY tpe.distance DESC\n                     FOR XML PATH ('')))\n                  )";
    default:
  }
}