You are here

function _taxonomy_edge_generate_term_path_query in Taxonomy Edge 7

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.2 taxonomy_edge.module \_taxonomy_edge_generate_term_path_query()

Generate query for ordering by dynamically compiled path.

Parameters

integer $tid: Term ID to generate dynamic path from.

string $sep: Separator to use in path.

Return value

string String containing query.

2 calls to _taxonomy_edge_generate_term_path_query()
taxonomy_edge_get_tree_optimized in ./taxonomy_edge.core.inc
Reimplementation of taxonomy_get_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 673
Optimization of taxonomy data model for SQL performance.

Code

function _taxonomy_edge_generate_term_path_query($tid, $sep = '    ') {
  $db_type = Database::getConnection()
    ->databaseType();
  switch ($db_type) {
    case 'pgsql':
      return "(SELECT array_to_string(array_agg(((tpx.weight + 1500) || tpx.name || '{$sep}' || tpx.tid)), '{$sep}') FROM (SELECT tpd.* FROM {taxonomy_term_edge} tpe INNER JOIN {taxonomy_term_data} tpd ON tpd.tid = tpe.parent WHERE tpe.tid = {$tid} ORDER BY tpe.distance DESC) tpx)";
    case 'mysql':
      return "(SELECT GROUP_CONCAT(tpd.weight + 1500, tpd.name, '{$sep}', tpd.tid ORDER BY tpe.distance DESC SEPARATOR '{$sep}') FROM {taxonomy_term_edge} tpe INNER JOIN {taxonomy_term_data} tpd ON tpd.tid = tpe.parent WHERE tpe.tid = {$tid})";
    case 'sqlite':
      return "(SELECT GROUP_CONCAT(val, '{$sep}') FROM (SELECT (tpd.weight + 1500) || tpd.name || '{$sep}' || tpd.tid AS val FROM {taxonomy_term_edge} tpe INNER JOIN {taxonomy_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 + '{$sep}' + CAST(tpd.tid as nvarchar) + '{$sep}'\n         FROM {taxonomy_term_edge} tpe\n         JOIN {taxonomy_term_data} tpd ON tpd.tid = tpe.parent\n         WHERE tpe.tid = {$tid}\n         ORDER BY tpe.distance DESC\n         FOR XML PATH (''))))";
    default:
  }
}