function _taxonomy_edge_generate_term_path_query in Taxonomy Edge 8
Same name and namespace in other branches
- 6 taxonomy_edge.module \_taxonomy_edge_generate_term_path_query()
- 7.2 taxonomy_edge.module \_taxonomy_edge_generate_term_path_query()
- 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.
2 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.
- 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 645 - 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();
$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_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 {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, ' ') FROM (SELECT (tpd.weight + 1500) || tpd.name || ' ' || 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 + ' ' + CAST(tpd.tid as nvarchar) + ' '\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 ('')))\n )";
default:
}
}