function tripal_cv_init_tree
1.x trees.inc | tripal_cv_init_tree($cv_id, $cnt_table = NULL, $fk_column = NULL,
$cnt_column = NULL, $filter = NULL, $label = NULL) |
Generates JSON needed for jsTree Root-level Branches
This function returns the JSON array for the jsTree jQuery code that builds a tree for browsing the ontology. This function should be called to generate the root level branches of the tree.
Related topics
1 call to tripal_cv_init_tree()
- tripal_cv_update_tree in tripal_cv/
includes/ trees.inc
File
- tripal_cv/
includes/ trees.inc, line 187 - @todo Stephen describe this file
Code
function tripal_cv_init_tree($cv_id, $cnt_table = NULL, $fk_column = NULL,
$cnt_column = NULL, $filter = NULL, $label = NULL) {
// get the list of root terms for the provided CV
$sql = "
SELECT *
FROM {cv_root_mview} CRM
WHERE cv_id = %d
";
$results = chado_query($sql, $cv_id);
// prepare the SQL statement that will allow us to pull out count
// information for each term in the tree.
if ($cnt_table) {
if (!$filter) {
$filter = '(1=1)';
}
$cnt_sql = "
SELECT CVT.name, CVT.cvterm_id, CNT.$cnt_column as num_items
FROM {$cnt_table} CNT
INNER JOIN {cvterm} CVT on CNT.$fk_column = CVT.cvterm_id
WHERE $filter AND CVT.cvterm_id = %d
ORDER BY $cnt_column desc
";
}
while ($term = db_fetch_object($results)) {
$name = $term->name;
$count = 0;
if ($cnt_table) {
$cnt_results = chado_query($cnt_sql, $term->cvterm_id);
while ($cnt = db_fetch_object($cnt_results)) {
$count += $cnt->cnt;
}
if ($count > 0) {
$name .= " ($count $label(s))";
}
}
$content[] = array(
'attributes' => array(
'id' => $term->cvterm_id,
),
'state' => 'closed',
'data' => $name,
'children' => array(),
);
}
return $content;
}