コード例 #1
0
ファイル: flathml2.php プロジェクト: HeuristNetwork/heurist
function outputRecord($recordInfo, $recInfos, $outputStub = false, $parentID = null)
{
    global $RTN, $DTN, $INV, $TL, $RQS, $WGN, $UGN, $MAX_DEPTH, $WOOT, $USEXINCLUDELEVEL, $RECTYPE_FILTERS, $SUPRESS_LOOPBACKS, $relRT, $relTrgDT, $relTypDT, $relSrcDT, $selectedIDs, $intofile, $hunifile, $dbID;
    $hunifile = null;
    //$record = $recordInfo['record'];
    $record = loadRecord_NoCache($recordInfo['recID'], true);
    //loadRecord($recID, $FRESH, true);
    $depth = $recordInfo['depth'];
    $filter = array_key_exists($depth, $RECTYPE_FILTERS) ? $RECTYPE_FILTERS[$depth] : null;
    if (isset($filter) && !in_array($record['rec_RecTypeID'], $filter)) {
        if ($record['rec_RecTypeID'] != $relRT) {
            //not a relationship rectype
            if ($depth > 0) {
                //				if ($USEXINCLUDELEVEL){
                //					outputXInclude($record);
                //				}else
                if ($outputStub) {
                    outputRecordStub($record);
                } else {
                    output($record['rec_ID']);
                }
            }
            return false;
        }
    }
    // using separare files per record
    // TODO: no error checking on success so silent failure if directory non-writable
    // beware: File is closed in outputRecords function
    $recAttr = array();
    if ($intofile) {
        $hunifile = fopen(HEURIST_HML_DIR . $record['rec_ID'] . ".xml", 'w');
        output("<?xml version='1.0' encoding='UTF-8'?>\n");
        //add attributes
        $recAttr['xmlns'] = 'http://heuristnetwork.org';
        $recAttr['xmlns:xsi'] = 'http://www.w3.org/2001/XMLSchema-instance';
        $recAttr['xsi:schemaLocation'] = 'http://heuristnetwork.org reference/scheme_record.xsd';
    }
    $recAttr['depth'] = $depth;
    $recAttr['visibility'] = $record['rec_NonOwnerVisibility'] ? $record['rec_NonOwnerVisibility'] : 'viewable';
    $recAttr['visnote'] = $record['rec_NonOwnerVisibility'] == 'hidden' ? 'owner group only' : ($record['rec_NonOwnerVisibility'] == 'public' ? 'no login required' : 'logged in users');
    $recAttr['selected'] = in_array($record['rec_ID'], $selectedIDs) ? 'yes' : 'no';
    openTag('record', $recAttr);
    if (isset($dbID) && $dbID != 0) {
        output("<dbID>" . $dbID . "</dbID>\n");
    } else {
        output("<dbID>0</dbID>\n");
        // unregistered database
    }
    if (array_key_exists('error', $record)) {
        makeTag('error', null, $record['error']);
        closeTag('record');
        return false;
    }
    if ($depth > $USEXINCLUDELEVEL) {
        outputXInclude($record);
        closeTag('record');
        return $record['rec_RecTypeID'];
    }
    $conceptID = getRecTypeConceptID($record['rec_RecTypeID']);
    makeTag('citeAs', null, HEURIST_BASE_URL . '?recID=' . $record['rec_ID'] . '&db=' . HEURIST_DBNAME);
    makeTag('id', null, $record['rec_ID']);
    makeTag('type', array('id' => $record['rec_RecTypeID'], 'conceptID' => $conceptID), $RTN[$record['rec_RecTypeID']]);
    makeTag('title', null, $record['rec_Title']);
    if ($record['rec_URL']) {
        makeTag('url', null, $record['rec_URL']);
    }
    if ($record['rec_ScratchPad']) {
        makeTag('notes', null, replaceIllegalChars($record['rec_ScratchPad']));
    }
    makeTag('added', null, $record['rec_Added']);
    makeTag('modified', null, $record['rec_Modified']);
    // saw FIXME  - need to output groups only
    if (array_key_exists($record['rec_OwnerUGrpID'], $WGN) || array_key_exists($record['rec_OwnerUGrpID'], $UGN)) {
        makeTag('workgroup', array('id' => $record['rec_OwnerUGrpID']), $record['rec_OwnerUGrpID'] > 0 ? array_key_exists($record['rec_OwnerUGrpID'], $WGN) ? $WGN[$record['rec_OwnerUGrpID']] : (array_key_exists($record['rec_OwnerUGrpID'], $UGN) ? $UGN[$record['rec_OwnerUGrpID']] : 'Unknown') : 'public');
    }
    foreach ($record['details'] as $dt => $details) {
        foreach ($details as $value) {
            outputDetail($dt, $value, $record['rec_RecTypeID'], $recInfos, $depth, $outputStub, $record['rec_RecTypeID'] == $relRT ? $parentID : $record['rec_ID']);
        }
    }
    if ($WOOT) {
        $result = loadWoot(array('title' => 'record:' . $record['rec_ID']));
        if ($result['success'] && is_numeric($result['woot']['id']) && count($result['woot']['chunks']) > 0) {
            openTag('woot', array('title' => 'record:' . $record['rec_ID']));
            openCDATA();
            foreach ($result['woot']['chunks'] as $chunk) {
                $text = preg_replace("/&nbsp;/", " ", $chunk['text']);
                output(replaceIllegalChars($text) . "\n");
            }
            closeCDATA();
            closeTag('woot');
        }
    }
    if (array_key_exists('revPtrLinks', $recordInfo) && $recordInfo['revPtrLinks']['byRecIDs']) {
        foreach ($recordInfo['revPtrLinks']['byRecIDs'] as $rec_id => $dtIDs) {
            foreach ($dtIDs as $dtID) {
                $linkedRec = loadRecord_NoCache($rec_id, true);
                //$recInfos[$rec_id]['record'];
                $attrs = array('id' => $dtID, 'conceptID' => getDetailTypeConceptID($dtID), 'type' => $DTN[$dtID]);
                if (array_key_exists($dtID, $RQS[$linkedRec['rec_RecTypeID']])) {
                    $attrs['name'] = $RQS[$linkedRec['rec_RecTypeID']][$dtID];
                }
                makeTag('reversePointer', $attrs, $rec_id);
            }
        }
    }
    if (array_key_exists('revRelLinks', $recordInfo) && $recordInfo['revRelLinks']['relRecIDs']) {
        $recID = $record['rec_ID'];
        foreach ($recordInfo['revRelLinks']['relRecIDs'] as $relRec_id) {
            $relRec = loadRecord_NoCache($relRec_id, true);
            //$recInfos[$relRec_id]['record'];
            $attrs = array();
            if ($details = $relRec['details']) {
                if ($details[$relTrgDT]) {
                    list($key, $value) = each($details[$relTrgDT]);
                    $toRecord = $value;
                    if (intval($toRecord['id']) != $recID) {
                        $relatedRecID = $toRecord['id'];
                    } else {
                        $attrs['useInverse'] = 'true';
                        if ($details[$relSrcDT]) {
                            list($key, $value) = each($details[$relSrcDT]);
                            $fromRecord = $value;
                            if (intval($fromRecord['id']) != $recID) {
                                $relatedRecID = $fromRecord['id'];
                            }
                        }
                    }
                }
                if ($details[$relTypDT]) {
                    list($key, $value) = each($details[$relTypDT]);
                    preg_replace("/-/", "", $value);
                    $trmID = $value;
                    if ($trmID) {
                        //saw Enum change
                        $attrs['type'] = $TL[$trmID]['trm_Label'];
                        $attrs['termID'] = $trmID;
                        $attrs['termConceptID'] = getTermConceptID($trmID);
                        if ($TL[$trmID]['trm_Code']) {
                            $attrs['code'] = $TL[$trmID]['trm_Code'];
                        }
                        if ($relatedRecID) {
                            $attrs['relatedRecordID'] = $relatedRecID;
                        }
                        if (array_key_exists($trmID, $INV) && $INV[$trmID]) {
                            $attrs['inverse'] = $TL[$INV[$trmID]]['trm_Label'];
                            $attrs['invTermID'] = $INV[$trmID];
                            $attrs['invTermConceptID'] = getTermConceptID($INV[$trmID]);
                        }
                    }
                }
            }
            makeTag('relationship', $attrs, $relRec_id);
        }
    }
    if (array_key_exists('relLinks', $recordInfo) && $recordInfo['relLinks']['relRecIDs']) {
        $recID = $record['rec_ID'];
        foreach ($recordInfo['relLinks']['relRecIDs'] as $relRec_id) {
            $relRec = loadRecord_NoCache($relRec_id, true);
            //$recInfos[$relRec_id]['record'];
            $attrs = array();
            if ($details = $relRec['details']) {
                if ($details[$relTrgDT]) {
                    list($key, $value) = each($details[$relTrgDT]);
                    $toRecord = $value;
                    if (intval($toRecord['id']) != $recID) {
                        $relatedRecID = $toRecord['id'];
                    } else {
                        $attrs['useInverse'] = 'true';
                        if ($details[$relSrcDT]) {
                            list($key, $value) = each($details[$relSrcDT]);
                            $fromRecord = $value;
                            if (intval($fromRecord['id']) != $recID) {
                                $relatedRecID = $fromRecord['id'];
                            }
                        }
                    }
                }
                if ($details[$relTypDT]) {
                    list($key, $value) = each($details[$relTypDT]);
                    preg_replace("/-/", "", $value);
                    $trmID = $value;
                    if ($trmID) {
                        //saw Enum change
                        $attrs['type'] = $TL[$trmID]['trm_Label'];
                        $attrs['termID'] = $trmID;
                        $attrs['termConceptID'] = getTermConceptID($trmID);
                        if ($relatedRecID) {
                            $attrs['relatedRecordID'] = $relatedRecID;
                        }
                        if (array_key_exists($trmID, $INV) && $INV[$trmID]) {
                            $attrs['inverse'] = $TL[$INV[$trmID]]['trm_Label'];
                            $attrs['invTermID'] = $INV[$trmID];
                            $attrs['invTermConceptID'] = getTermConceptID($INV[$trmID]);
                        }
                    }
                }
            }
            makeTag('relationship', $attrs, $relRec_id);
        }
    }
    closeTag('record');
    return $record['rec_RecTypeID'];
    //true;
}
コード例 #2
0
ファイル: flathml.php プロジェクト: beoutsports/heurist-v3-1
/**
 * description
 * @global    type description of global variable usage in a function
 * @staticvar type [$varname] description of static variable usage in function
 * @param     type [$varname] description
 * @return    type description
 * @link      URL
 * @see       name of another element (function or object) used in this function
 * @throws    list of exceptions thrown in this code
 * @uses      code_element_name description of use
 */
function outputRecord($recordInfo, $recInfos, $outputStub = false, $parentID = null)
{
    global $RTN, $DTN, $INV, $TL, $RQS, $WGN, $UGN, $MAX_DEPTH, $WOOT, $USEXINCLUDELEVEL, $RECTYPE_FILTERS, $SUPRESS_LOOPBACKS, $relRT, $relTrgDT, $relTypDT, $relSrcDT, $selectedIDs;
    $record = $recordInfo['record'];
    $depth = $recordInfo['depth'];
    $filter = array_key_exists($depth, $RECTYPE_FILTERS) ? $RECTYPE_FILTERS[$depth] : null;
    if (isset($filter) && !in_array($record['rec_RecTypeID'], $filter)) {
        if ($record['rec_RecTypeID'] != $relRT) {
            //not a relationship rectype
            if ($depth > 0) {
                //				if ($USEXINCLUDELEVEL){
                //					outputXInclude($record);
                //				}else
                if ($outputStub) {
                    outputRecordStub($record);
                } else {
                    echo $record['rec_ID'];
                }
            }
            return;
        }
    }
    /*****DEBUG****/
    //if ($record['rec_ID'] == 45133) error_log(" depth = $depth  xlevel = $USEXINCLUDELEVEL rec = ".print_r($record,true));
    openTag('record', array('depth' => $depth, 'visibility' => $record['rec_NonOwnerVisibility'] ? $record['rec_NonOwnerVisibility'] : 'viewable', 'selected' => in_array($record['rec_ID'], $selectedIDs) ? 'yes' : 'no'));
    if (array_key_exists('error', $record)) {
        makeTag('error', null, $record['error']);
        closeTag('record');
        return;
    }
    if ($depth > $USEXINCLUDELEVEL) {
        outputXInclude($record);
        closeTag('record');
        return;
    }
    makeTag('id', null, $record['rec_ID']);
    makeTag('type', array('id' => $record['rec_RecTypeID'], 'conceptID' => getRecTypeConceptID($record['rec_RecTypeID'])), $RTN[$record['rec_RecTypeID']]);
    makeTag('title', null, $record['rec_Title']);
    if ($record['rec_URL']) {
        makeTag('url', null, $record['rec_URL']);
    }
    if ($record['rec_ScratchPad']) {
        makeTag('notes', null, replaceIllegalChars($record['rec_ScratchPad']));
    }
    makeTag('added', null, $record['rec_Added']);
    makeTag('modified', null, $record['rec_Modified']);
    // saw FIXME  - need to output groups only
    if (array_key_exists($record['rec_OwnerUGrpID'], $WGN) || array_key_exists($record['rec_OwnerUGrpID'], $UGN)) {
        makeTag('workgroup', array('id' => $record['rec_OwnerUGrpID']), $record['rec_OwnerUGrpID'] > 0 ? array_key_exists($record['rec_OwnerUGrpID'], $WGN) ? $WGN[$record['rec_OwnerUGrpID']] : (array_key_exists($record['rec_OwnerUGrpID'], $UGN) ? $UGN[$record['rec_OwnerUGrpID']] : 'Unknown') : 'public');
    }
    foreach ($record['details'] as $dt => $details) {
        foreach ($details as $value) {
            outputDetail($dt, $value, $record['rec_RecTypeID'], $recInfos, $depth, $outputStub, $record['rec_RecTypeID'] == $relRT ? $parentID : $record['rec_ID']);
        }
    }
    if ($WOOT) {
        $result = loadWoot(array('title' => 'record:' . $record['rec_ID']));
        if ($result['success'] && is_numeric($result['woot']['id']) && count($result['woot']['chunks']) > 0) {
            openTag('woot', array('title' => 'record:' . $record['rec_ID']));
            openCDATA();
            foreach ($result['woot']['chunks'] as $chunk) {
                $text = preg_replace("/&nbsp;/", " ", $chunk['text']);
                echo replaceIllegalChars($text) . "\n";
            }
            closeCDATA();
            closeTag('woot');
        }
    }
    if (array_key_exists('revPtrLinks', $recordInfo) && $recordInfo['revPtrLinks']['byRecIDs']) {
        foreach ($recordInfo['revPtrLinks']['byRecIDs'] as $rec_id => $dtIDs) {
            foreach ($dtIDs as $dtID) {
                $linkedRec = $recInfos[$rec_id]['record'];
                $attrs = array('id' => $dtID, 'conceptID' => getDetailTypeConceptID($dtID), 'type' => $DTN[$dtID]);
                if (array_key_exists($dtID, $RQS[$linkedRec['rec_RecTypeID']])) {
                    $attrs['name'] = $RQS[$linkedRec['rec_RecTypeID']][$dtID];
                }
                makeTag('reversePointer', $attrs, $rec_id);
            }
        }
    }
    if (array_key_exists('revRelLinks', $recordInfo) && $recordInfo['revRelLinks']['relRecIDs']) {
        $recID = $record['rec_ID'];
        foreach ($recordInfo['revRelLinks']['relRecIDs'] as $relRec_id) {
            $relRec = $recInfos[$relRec_id]['record'];
            $attrs = array();
            if ($details = $relRec['details']) {
                if ($details[$relTrgDT]) {
                    list($key, $value) = each($details[$relTrgDT]);
                    $toRecord = $value;
                    if (intval($toRecord['id']) != $recID) {
                        $relatedRecID = $toRecord['id'];
                    } else {
                        $attrs['useInverse'] = 'true';
                        if ($details[$relSrcDT]) {
                            list($key, $value) = each($details[$relSrcDT]);
                            $fromRecord = $value;
                            if (intval($fromRecord['id']) != $recID) {
                                $relatedRecID = $fromRecord['id'];
                            }
                        }
                    }
                }
                if ($details[$relTypDT]) {
                    list($key, $value) = each($details[$relTypDT]);
                    preg_replace("/-/", "", $value);
                    $trmID = $value;
                    if ($trmID) {
                        //saw Enum change
                        $attrs['type'] = $TL[$trmID]['trm_Label'];
                        $attrs['termID'] = $trmID;
                        $attrs['termConceptID'] = getTermConceptID($trmID);
                        if ($TL[$trmID]['trm_Code']) {
                            $attrs['code'] = $TL[$trmID]['trm_Code'];
                        }
                        if ($relatedRecID) {
                            $attrs['relatedRecordID'] = $relatedRecID;
                        }
                        if (array_key_exists($trmID, $INV) && $INV[$trmID]) {
                            $attrs['inverse'] = $TL[$INV[$trmID]]['trm_Label'];
                            $attrs['invTermID'] = $INV[$trmID];
                            $attrs['invTermConceptID'] = getTermConceptID($INV[$trmID]);
                        }
                    }
                }
            }
            makeTag('relationship', $attrs, $relRec_id);
        }
    }
    if (array_key_exists('relLinks', $recordInfo) && $recordInfo['relLinks']['relRecIDs']) {
        $recID = $record['rec_ID'];
        foreach ($recordInfo['relLinks']['relRecIDs'] as $relRec_id) {
            $relRec = $recInfos[$relRec_id]['record'];
            $attrs = array();
            if ($details = $relRec['details']) {
                if ($details[$relTrgDT]) {
                    list($key, $value) = each($details[$relTrgDT]);
                    $toRecord = $value;
                    if (intval($toRecord['id']) != $recID) {
                        $relatedRecID = $toRecord['id'];
                    } else {
                        $attrs['useInverse'] = 'true';
                        if ($details[$relSrcDT]) {
                            list($key, $value) = each($details[$relSrcDT]);
                            $fromRecord = $value;
                            if (intval($fromRecord['id']) != $recID) {
                                $relatedRecID = $fromRecord['id'];
                            }
                        }
                    }
                }
                if ($details[$relTypDT]) {
                    list($key, $value) = each($details[$relTypDT]);
                    preg_replace("/-/", "", $value);
                    $trmID = $value;
                    if ($trmID) {
                        //saw Enum change
                        $attrs['type'] = $TL[$trmID]['trm_Label'];
                        $attrs['termID'] = $trmID;
                        $attrs['termConceptID'] = getTermConceptID($trmID);
                        if ($relatedRecID) {
                            $attrs['relatedRecordID'] = $relatedRecID;
                        }
                        if (array_key_exists($trmID, $INV) && $INV[$trmID]) {
                            $attrs['inverse'] = $TL[$INV[$trmID]]['trm_Label'];
                            $attrs['invTermID'] = $INV[$trmID];
                            $attrs['invTermConceptID'] = getTermConceptID($INV[$trmID]);
                        }
                    }
                }
            }
            makeTag('relationship', $attrs, $relRec_id);
        }
    }
    closeTag('record');
}