/** * 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'); }