示例#1
0
/**
* buildGraph - Function to build the structure for a set of records and all there related(linked) records to a given level
* @author Stephen White
* @param $rec_ids an array of recIDs from the Records table for which to build the tree
* @param $recSet an out array to store look up records by recordID
* @param $relationships an out array of recIDs to store look up relationRecID by supplied target/source recIDs
*/
function buildGraphStructure($rec_ids, &$recSet)
{
    global $MAX_DEPTH, $REVERSE, $RECTYPE_FILTERS, $RELTYPE_FILTERS, $PTRTYPE_FILTERS, $EXPAND_REV_PTR, $OUTPUT_STUBS;
    $depth = 0;
    $rtfilter = array_key_exists($depth, $RECTYPE_FILTERS) ? $RECTYPE_FILTERS[$depth] : null;
    if ($rtfilter) {
        $query = 'SELECT rec_ID from Records ' . 'WHERE rec_ID in (' . join(",", $rec_ids) . ') ' . 'AND rec_RecTypeID in (' . join(",", $rtfilter) . ')';
        $filteredIDs = array();
        $res = mysql_query($query);
        while ($res && ($row = mysql_fetch_row($res))) {
            $filteredIDs[$row[0]] = 1;
        }
        $rec_ids = array_keys($filteredIDs);
    }
    if ($MAX_DEPTH == 0 && $OUTPUT_STUBS && count($rec_ids) > 0) {
        findPointers($rec_ids, $recSet, 1, null, null);
    } else {
        while ($depth++ < $MAX_DEPTH && count($rec_ids) > 0) {
            $rtfilter = @$RECTYPE_FILTERS && array_key_exists($depth, $RECTYPE_FILTERS) ? $RECTYPE_FILTERS[$depth] : null;
            $relfilter = @$RELTYPE_FILTERS && array_key_exists($depth, $RELTYPE_FILTERS) ? $RELTYPE_FILTERS[$depth] : null;
            $ptrfilter = @$PTRTYPE_FILTERS && array_key_exists($depth, $PTRTYPE_FILTERS) ? $PTRTYPE_FILTERS[$depth] : null;
            $p_rec_ids = findPointers($rec_ids, $recSet, $depth, $rtfilter, $ptrfilter);
            $rp_rec_ids = $REVERSE ? findReversePointers($rec_ids, $recSet, $depth, $rtfilter, $ptrfilter) : array();
            $rel_rec_ids = findRelatedRecords($rec_ids, $recSet, $depth, $rtfilter, $relfilter);
            $rec_ids = array_merge($p_rec_ids, $EXPAND_REV_PTR ? $rp_rec_ids : array(), $rel_rec_ids);
            // record set for a given level
        }
    }
}
示例#2
0
/**
* buildTree - Function to build the structure for a set of records and all there related(linked) records
* @author Kim Jackson
* @author Stephen White
* @param $rec_ids an array of recIDs from the Records table for which to build the tree
* @param $reverse_pointers an out array of recIDs to store look up detailTypeID by pointed_to recID by pointed_to_by recID
* @param $relationships an out array of recIDs to store look up relationRecID by supplied target/source recIDs
**/
function buildTree($rec_ids, &$reverse_pointers, &$relationships)
{
    global $MAX_DEPTH, $REVERSE, $RECTYPE_FILTERS;
    $depth = 0;
    $filter = array_key_exists($depth, $RECTYPE_FILTERS) ? $RECTYPE_FILTERS[$depth] : null;
    if ($filter) {
        $query = 'SELECT rec_ID from Records ' . 'WHERE rec_ID in (' . join(",", $rec_ids) . ') ' . 'AND rec_RecTypeID in (' . join(",", $filter) . ')';
        //echo "query = $query <br/>";
        $filteredIDs = array();
        $res = mysql_query($query);
        while ($res && ($row = mysql_fetch_row($res))) {
            $filteredIDs[$row[0]] = 1;
        }
        $rec_ids = array_keys($filteredIDs);
    }
    //echo "depth = $depth  filter = ". print_r($filter,true)."<br/>";
    //echo json_format($rec_ids).'<br/>';
    while ($depth++ < $MAX_DEPTH && count($rec_ids) > 0) {
        $filter = array_key_exists($depth, $RECTYPE_FILTERS) ? $RECTYPE_FILTERS[$depth] : null;
        //echo "depth = $depth  filter = ". print_r($filter,true)."<br/>";
        $p_rec_ids = findPointers($rec_ids, $filter);
        $rp_rec_ids = $REVERSE ? findReversePointers($rec_ids, $reverse_pointers, $filter) : array();
        $rel_rec_ids = findRelatedRecords($rec_ids, $relationships, $filter);
        $rec_ids = array_merge($p_rec_ids, $rp_rec_ids, $rel_rec_ids);
        // record set for a given level
        //echo json_format($rec_ids).'<br/>';
    }
}
function buildFilteredGraphStructure($rec_ids, &$recSet, $depth = 0)
{
    global $MAX_DEPTH, $REVERSE, $RECTYPE_FILTERS, $RELTYPE_FILTERS, $PTRTYPE_FILTERS, $EXPAND_REV_PTR;
    $rtfilter = array_key_exists($depth, $RECTYPE_FILTERS) ? $RECTYPE_FILTERS[$depth] : null;
    if ($rtfilter) {
        // apply rctype filterring as we may have just the query results
        $query = 'SELECT rec_ID from Records ' . 'WHERE rec_ID in (' . join(",", $rec_ids) . ') ' . 'AND rec_RecTypeID in (' . join(",", $rtfilter) . ')';
        //echo "query = $query <br/>\n";
        $filteredIDs = array();
        $res = mysql_query($query);
        while ($res && ($row = mysql_fetch_row($res))) {
            $filteredIDs[$row[0]] = 1;
        }
        $rec_ids = array_keys($filteredIDs);
    }
    //echo "depth = $depth  recID = ". json_format($rec_ids)."\n";
    while ($depth++ < $MAX_DEPTH && count($rec_ids) > 0) {
        $rtfilter = array_key_exists($depth, $RECTYPE_FILTERS) ? $RECTYPE_FILTERS[$depth] : null;
        $relfilter = array_key_exists($depth, $RELTYPE_FILTERS) ? $RELTYPE_FILTERS[$depth] : null;
        $ptrfilter = array_key_exists($depth, $PTRTYPE_FILTERS) ? $PTRTYPE_FILTERS[$depth] : null;
        //echo "depth = $depth  rtfilter = ". print_r($rtfilter,true)."\n<br/>";
        //echo "depth = $depth  ptrfilter = ". print_r($ptrfilter,true)."\n<br/>";
        //echo "depth = $depth  relfilter = ". print_r($relfilter,true)."\n<br/>";
        if (!@$recSet['infoByDepth'][$depth]) {
            $recSet['infoByDepth'][$depth] = array('recIDs' => array(), 'rectypes' => array());
        }
        if ($rtfilter || $ptrfilter || $relfilter) {
            if (!@$recSet['infoByDepth'][$depth]['filters']) {
                $recSet['infoByDepth'][$depth]['filters'] = array();
            }
            if ($rtfilter) {
                $recSet['infoByDepth'][$depth]['filters']['rtfilter'] = $rtfilter;
            }
            if ($ptrfilter) {
                $recSet['infoByDepth'][$depth]['filters']['ptrfilter'] = $ptrfilter;
            }
            if ($relfilter) {
                $recSet['infoByDepth'][$depth]['filters']['relfilter'] = $relfilter;
            }
        }
        $p_rec_ids = findPointers($rec_ids, $recSet, $depth, $rtfilter, $ptrfilter);
        //echo "depth = $depth  new ptr recID = ". json_format($p_rec_ids)."\n";
        $rp_rec_ids = $REVERSE ? findReversePointers($rec_ids, $recSet, $depth, $rtfilter, $ptrfilter) : array();
        //echo "depth = $depth  new revptr recID = ". json_format($rp_rec_ids)."\n";
        $rel_rec_ids = findRelatedRecords($rec_ids, $recSet, $depth, $rtfilter, $relfilter);
        //echo "depth = $depth  new rel recID = ". json_format($rel_rec_ids)."\n";
        $rec_ids = array_merge($p_rec_ids, $EXPAND_REV_PTR ? $rp_rec_ids : array(), $rel_rec_ids);
        // record set for a given level
        //echo "depth = $depth  recID = ". json_format($rec_ids)."\n";
    }
}