function outputDetail($dt, $value, $rt, &$reverse_pointers, &$relationships, $depth = 0, $outputStub, $parentID) { global $DTN, $DTT, $TL, $RQS, $INV, $GEO_TYPES, $MAX_DEPTH, $INCLUDE_FILE_CONTENT, $SUPRESS_LOOPBACKS, $relTypDT, $relTrgDT, $relSrcDT; /*****DEBUG****/ //error_log("in outputDetail dt = $dt value = ". print_r($value,true)); $attrs = array('id' => $dt, 'conceptID' => getDetailTypeConceptID($dt)); if (array_key_exists($dt, $DTN)) { $attrs['type'] = $DTN[$dt]; } if (array_key_exists($rt, $RQS) && array_key_exists($dt, $RQS[$rt])) { $attrs['name'] = $RQS[$rt][$dt]; } if ($dt === $relTypDT && array_key_exists($value, $INV) && $INV[$value] && array_key_exists($INV[$value], $TL)) { //saw Enum change $attrs['inverse'] = $TL[$INV[$value]]['trm_Label']; $attrs['invTermConceptID'] = getTermConceptID($INV[$value]); } if (is_array($value)) { if (array_key_exists('id', $value)) { // record pointer if ($dt === $relSrcDT || $dt === $relTrgDT) { // in a relationship record don't expand from side if ($value['id'] == $parentID) { $attrs['direction'] = "from"; if ($dt === $relTrgDT) { $attrs['useInverse'] = 'true'; } if ($SUPRESS_LOOPBACKS) { openTag('detail', $attrs); if ($outputStub) { outputRecordStub(loadRecordStub($value['id'])); } else { echo $value['id']; } closeTag('detail'); return; } } else { $attrs['direction'] = "to"; if ($dt === $relSrcDT) { $attrs['useInverse'] = 'true'; } } openTag('detail', $attrs); outputRecord(loadRecord($value['id']), $reverse_pointers, $relationships, $depth + 1, $outputStub, $parentID); closeTag('detail'); } else { if ($depth < $MAX_DEPTH) { openTag('detail', $attrs); outputRecord(loadRecord($value['id']), $reverse_pointers, $relationships, $depth + 1, $outputStub, $parentID); closeTag('detail'); } else { if ($outputStub) { openTag('detail', $attrs); outputRecordStub(loadRecordStub($value['id'])); closeTag('detail'); } else { makeTag('detail', $attrs, $value['id']); } } } } else { if (array_key_exists('file', $value)) { $file = $value['file']; /*****DEBUG****/ //error_log(" in outputDetail file = \n".print_r($file,true)); openTag('detail', $attrs); openTag('file'); makeTag('id', null, $file['id']); makeTag('nonce', null, $file['nonce']); makeTag('origName', null, $file['origName']); makeTag('type', null, $file['type']); makeTag('size', array('units' => 'kB'), $file['size']); makeTag('date', null, $file['date']); makeTag('description', null, $file['description']); makeTag('url', null, $file['URL']); makeTag('thumbURL', null, $file['thumbURL']); if ($INCLUDE_FILE_CONTENT) { makeFileContentNode($file); } closeTag('file'); closeTag('detail'); } else { if (array_key_exists('geo', $value)) { openTag('detail', $attrs); openTag('geo'); makeTag('type', null, $GEO_TYPES[$value['geo']['type']]); makeTag('wkt', null, $value['geo']['wkt']); closeTag('geo'); closeTag('detail'); } } } } else { if ($DTT[$dt] === 'date') { openTag('detail', $attrs); if (strpos($value, "|") === false) { outputDateDetail($attrs, $value); } else { outputTemporalDetail($attrs, $value); } closeTag('detail'); } else { if ($DTT[$dt] === 'resource') { openTag('detail', $attrs); outputRecord(loadRecord($value), $reverse_pointers, $relationships, $depth + 1, $outputStub, $parentID); closeTag('detail'); } else { if (($DTT[$dt] === 'enum' || $DTT[$dt] === 'relationtype') && array_key_exists($value, $TL)) { $attrs['termConceptID'] = getTermConceptID($value); if (@$TL[$value]['trm_ParentTermID']) { $attrs['ParentTerm'] = $TL[$TL[$value]['trm_ParentTermID']]['trm_Label']; } /*****DEBUG****/ //error_log("value = ".$value." label = ".$TL[$value]['trm_Label']); makeTag('detail', $attrs, $TL[$value]['trm_Label']); } else { makeTag('detail', $attrs, replaceIllegalChars($value)); } } } } }
/** * Outputs the set of records as an xml stream or separate files per record (if $intofile set) * * returns array of printed out recID=>recTypeID * * @param mixed $result */ function outputRecords($result) { global $OUTPUT_STUBS, $FRESH, $MAX_DEPTH, $intofile, $hunifile, $relRT; $recSet = array('count' => 0, 'relatedSet' => array()); $rec_ids = explode(",", $result['recIDs']); if (array_key_exists('expandColl', $_REQUEST)) { $rec_ids = expandCollections($rec_ids); } if (!is_array($rec_ids)) { $rec_ids = array(); } set_time_limit(0); /* if(count($rec_ids)>1000){ set_time_limit( 30 * count($rec_ids) % 1000 ); } */ $current_depth_recs_ids = $rec_ids; $current_depth = 0; $already_out = array(); //result - array of all printed out records recID => recTypeID if (!$intofile) { openTag('records'); //, array('count' => $recSet['count'])); } $relations_rec_ids = array(); //list of all relationship records while ($current_depth <= $MAX_DEPTH) { $next_depth_recs_ids = array(); $relations_rec_ids[$current_depth] = array(); foreach ($current_depth_recs_ids as $recID) { // output one record - returns recTypeID and array of related records for given record $res = outputRecord($recID, $current_depth, $OUTPUT_STUBS); // close the file if using HuNI manifest + separate files output // The file is opened in outputRecord but left open! if ($intofile && $hunifile) { fclose($hunifile); } if ($res) { //output is successful $already_out[$recID] = $res['recTypeID']; $related_rec_ids = $res['related']; if (count($res['relationRecs']) > 0) { $relations_rec_ids[$current_depth] = array_merge($relations_rec_ids[$current_depth], $res['relationRecs']); } //add to $next_depth_recs_ids if not already printed out or in current depth foreach ($related_rec_ids as $rel_recID) { if (!(@$already_out[$rel_recID] || in_array($rel_recID, $current_depth_recs_ids) || in_array($rel_recID, $next_depth_recs_ids))) { array_push($next_depth_recs_ids, $rel_recID); } } } else { if ($intofile && file_exists(HEURIST_HML_DIR . $recID . ".xml")) { unlink(HEURIST_HML_DIR . $record['rec_ID'] . ".xml"); } } } unset($current_depth_recs_ids); $current_depth_recs_ids = $next_depth_recs_ids; $current_depth++; } //while depth //print out relationship records with half depth $current_depth = 0; while ($current_depth <= $MAX_DEPTH) { foreach ($relations_rec_ids[$current_depth] as $recID) { if (!@$already_out[$recID]) { $res = outputRecord($recID, $current_depth . '.5', $OUTPUT_STUBS); if ($res) { $already_out[$recID] = $relRT; } elseif ($intofile && file_exists(HEURIST_HML_DIR . $recID . ".xml")) { unlink(HEURIST_HML_DIR . $record['rec_ID'] . ".xml"); } } } $current_depth++; } if (!$intofile) { closeTag('records'); } return $already_out; /* OLD VERSION pre 2016-12-05 foreach ($rec_ids as $recID) { if($recID>0) $recSet['relatedSet'][$recID] = array('depth' => 0, 'recID' => $recID ); } buildGraphStructure($rec_ids, $recSet); $recSet['count'] = count($recSet['relatedSet']); $resout = array(); if(!$intofile){ openTag('records', array('count' => $recSet['count'])); } foreach ($recSet['relatedSet'] as $recID => $recInfo) { if (intval($recInfo['depth']) <= $MAX_DEPTH) { // output one record - returns rec_RecTypeID for given record $res = outputRecord($recInfo, $recSet['relatedSet'], $OUTPUT_STUBS); // close the file if using HuNI manifest + separate files output // The file is opened in outputRecord but left open! if($intofile && $hunifile){ fclose($hunifile); } if($res){ $resout[$recID] = $res; //$recInfo['record']['rec_RecTypeID']; }else if ($intofile && file_exists(HEURIST_HML_DIR.$recID.".xml")){ unlink(HEURIST_HML_DIR.$record['rec_ID'].".xml"); } } } if(!$intofile){ closeTag('records'); } return $resout; */ }
/** * Outputs the set of records as an xml stream or separate files per record (if $intofile set) * * @param mixed $result */ function outputRecords($result) { global $OUTPUT_STUBS, $FRESH, $MAX_DEPTH, $intofile, $hunifile; $recSet = array('count' => 0, 'relatedSet' => array()); $rec_ids = explode(",", $result['recIDs']); if (array_key_exists('expandColl', $_REQUEST)) { $rec_ids = expandCollections($rec_ids); } if (!is_array($rec_ids)) { $rec_ids = array(); } if (count($rec_ids) > 1000) { set_time_limit(30 * count($rec_ids) % 1000); } foreach ($rec_ids as $recID) { if ($recID > 0) { $recSet['relatedSet'][$recID] = array('depth' => 0, 'recID' => $recID); } } buildGraphStructure($rec_ids, $recSet); $recSet['count'] = count($recSet['relatedSet']); /* ARTEM: avoid memory overflow foreach ($recSet['relatedSet'] as $recID => $recInfo) { $recSet['relatedSet'][$recID]['record'] = loadRecord_NoCache($recID, true); //loadRecord($recID, $FRESH, true); } */ $resout = array(); if (!$intofile) { openTag('records', array('count' => $recSet['count'])); } foreach ($recSet['relatedSet'] as $recID => $recInfo) { if (intval($recInfo['depth']) <= $MAX_DEPTH) { // output one record - returs rec_RecTypeID for given record $res = outputRecord($recInfo, $recSet['relatedSet'], $OUTPUT_STUBS); // close the file if using HuNI manifest + separate files output // The file is opened in outputRecord but left open! if ($intofile && $hunifile) { fclose($hunifile); } if ($res) { $resout[$recID] = $res; //$recInfo['record']['rec_RecTypeID']; } else { if ($intofile && file_exists(HEURIST_HML_DIR . $recID . ".xml")) { unlink(HEURIST_HML_DIR . $record['rec_ID'] . ".xml"); } } } } if (!$intofile) { closeTag('records'); } return $resout; }
/** * 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 outputRecords($result) { global $OUTPUT_STUBS, $FRESH, $MAX_DEPTH; $recSet = array('count' => 0, 'relatedSet' => array()); $rec_ids = explode(",", $result['recIDs']); if (array_key_exists('expandColl', $_REQUEST)) { $rec_ids = expandCollections($rec_ids); } foreach ($rec_ids as $recID) { $recSet['relatedSet'][$recID] = array('depth' => 0); } buildGraphStructure($rec_ids, $recSet); $recSet['count'] = count($recSet['relatedSet']); foreach ($recSet['relatedSet'] as $recID => $recInfo) { $recSet['relatedSet'][$recID]['record'] = loadRecord($recID, $FRESH, true); } openTag('records', array('count' => $recSet['count'])); foreach ($recSet['relatedSet'] as $recID => $recInfo) { if (intval($recInfo['depth']) <= $MAX_DEPTH) { outputRecord($recInfo, $recSet['relatedSet'], $OUTPUT_STUBS); } } closeTag('records'); }