Esempio n. 1
0
/**
 * Compare if in $nodes array exists some qname with prefix $prefix.
 * Using the $node['text'] attribute because the $node['id'] attr changes sometimes
 * @param unknown_type $prefix
 * @param array $nodes
 * @return unknown_type
 */
function _neologism_gateway_in_nodes($prefix, array $nodes)
{
    $result = false;
    foreach ($nodes as $node) {
        $qterm_splited = explode(':', $node['text']);
        if ($prefix == $qterm_splited[0]) {
            $result = true;
        } elseif (!empty($node['children'])) {
            $result = _neologism_gateway_in_nodes($prefix, $node['children']);
        }
    }
    return $result;
}
Esempio n. 2
0
/**
 * This recurive function search for chindren of $node return class from the same $voc. 
 * If the parent does not belong to the $voc but has children that does, this parent is added as well.
 * @param object $node
 * @param object $voc
 * @param object $add_checkbox [optional]
 * @return 
 */
function neologism_gateway_get_class_children_old($node, $voc = NULL, $add_checkbox = FALSE, array &$disjointwith_array = NULL)
{
    $nodes = array();
    static $array_of_id = array();
    $children = db_query('select prefix, reference from {evoc_rdf_superclasses} where superclass = "' . $node . '"');
    while ($child = db_fetch_object($children)) {
        $class = db_fetch_object(db_query('select * from evoc_rdf_classes where prefix = "' . $child->prefix . '" and id = "' . $child->reference . '" '));
        if ($class) {
            $class->prefix = trim($class->prefix);
            $class->id = trim($class->id);
            $qname = $class->prefix . ':' . $class->id;
            // extra information needed by the treeview
            $extra_information = true;
            $realId = '';
            if (isset($array_of_id[$qname])) {
                $modified_id = $array_of_id[$qname] . '_' . $qname;
                $array_of_id[$qname] += 1;
                $realId = $qname;
            } else {
                $array_of_id[$qname] = 1;
                $extra_information = false;
            }
            //-----------------------------------------
            // fetch extra information
            // fetch the disjointwith
            $disjointwith = array();
            if ($class->ndisjointwith > 0) {
                $result = db_query('select disjointwith from {evoc_rdf_disjointwith} where prefix = "' . $class->prefix . '" and reference = "' . $class->id . '" ');
                while ($c = db_fetch_object($result)) {
                    $disjointwith[] = $c->disjointwith;
                }
                if (isset($disjointwith_array) && is_array($disjointwith_array)) {
                    $disjointwith_array[$qname] = $disjointwith;
                }
            }
            // fetch the superclasses
            $superclasses = array();
            if ($class->superclasses > 0) {
                $result = db_query('select superclass from {evoc_rdf_superclasses} where prefix = "' . $class->prefix . '" and reference = "' . $class->id . '" ');
                while ($s = db_fetch_object($result)) {
                    $superclasses[] = $s->superclass;
                }
            }
            $children_nodes = neologism_gateway_get_class_children($qname, $voc, $add_checkbox, $disjointwith_array);
            if ($voc) {
                if ($class->prefix == $voc || _neologism_gateway_in_nodes($voc, $children_nodes)) {
                    $leaf = count($children_nodes) == 0;
                    $qtip = '<b>' . $class->label . '</b><br/>' . $class->comment;
                    $nodes[] = array('text' => $qname, 'id' => !$extra_information ? $qname : $modified_id, 'leaf' => $leaf, 'iconCls' => $class->prefix == $voc ? 'class-samevoc' : 'class-diffvoc', 'cls' => $class->prefix == $voc ? 'currentvoc' : '', 'children' => $children_nodes, 'qtip' => $qtip, 'disjointwith' => $disjointwith, 'superclasses' => $superclasses, 'nodeStatus' => 0);
                    if ($extra_information) {
                        $nodes[count($nodes) - 1]['realid'] = $qname;
                    }
                    if ($add_checkbox) {
                        $nodes[count($nodes) - 1]['checked'] = false;
                    }
                }
            } else {
                $leaf = count($children_nodes) == 0;
                $qtip = '<b>' . $class->label . '</b><br/>' . $class->comment;
                $nodes[] = array('text' => $qname, 'id' => !$extra_information ? $qname : $modified_id, 'leaf' => $leaf, 'iconCls' => 'class-samevoc', 'children' => $children_nodes, 'qtip' => $qtip, 'disjointwith' => $disjointwith, 'superclasses' => $superclasses, 'nodeStatus' => 0);
                if ($extra_information) {
                    $nodes[count($nodes) - 1]['realid'] = $qname;
                }
                if ($add_checkbox) {
                    $nodes[count($nodes) - 1]['checked'] = false;
                }
            }
        }
    }
    return $nodes;
}