193 |
193 |
// ===================== Tagged Text functions ================== //
|
194 |
194 |
|
195 |
195 |
/**
|
|
196 |
* Walks the passed TaggedText array to find all elements which have a
|
|
197 |
* TaggedText->entityReference. For each of these the taggedTexts is loaded
|
|
198 |
* from the webservice and the original enty in the TaggedText array will be
|
|
199 |
* replaced by the newly loaded array.
|
|
200 |
*
|
|
201 |
* @param array $taggedtxt
|
|
202 |
* The original TaggedText array
|
|
203 |
* @param array $skiptags
|
|
204 |
* Optional list of tag names to skip
|
|
205 |
* @return array
|
|
206 |
* The new tagged text with all TaggedText->entityReference objects expanded
|
|
207 |
*/
|
|
208 |
function cdm_tagged_text_expand_entity_references(array $taggedtxt, $skiptags = array()) {
|
|
209 |
$tagged_text_expanded = array();
|
|
210 |
foreach ($taggedtxt as $tt) {
|
|
211 |
if (isset($tt->entityReference) && !in_array($tt->type, $skiptags)) {
|
|
212 |
$base_uri = cdm_ws_base_uri($tt->entityReference->type);
|
|
213 |
if($base_uri){
|
|
214 |
$tagged_text_method = "/taggedText";
|
|
215 |
if($base_uri == CDM_WS_NAME){
|
|
216 |
$tagged_text_method = "/taggedName";
|
|
217 |
}
|
|
218 |
$referenced_tt = cdm_ws_get($base_uri . "/" . $tt->entityReference->uuid . $tagged_text_method);
|
|
219 |
if($referenced_tt){
|
|
220 |
$tagged_text_expanded = array_merge($tagged_text_expanded, $referenced_tt);
|
|
221 |
continue;
|
|
222 |
}
|
|
223 |
}
|
|
224 |
}
|
|
225 |
// default case
|
|
226 |
$tagged_text_expanded[] = $tt;
|
|
227 |
}
|
|
228 |
return $tagged_text_expanded;
|
|
229 |
}
|
|
230 |
|
|
231 |
/**
|
196 |
232 |
* Converts an array of TaggedText items into corresponding html tags.
|
197 |
233 |
*
|
198 |
234 |
* Each item is provided with a class attribute which is set to the key of the
|
... | ... | |
1058 |
1094 |
* The CDM entity to construct the annotations pager uri for
|
1059 |
1095 |
*/
|
1060 |
1096 |
function cdm_compose_annotations_uri($cdmBase) {
|
|
1097 |
|
1061 |
1098 |
if (!$cdmBase->uuid) {
|
1062 |
1099 |
return;
|
1063 |
1100 |
}
|
1064 |
1101 |
|
|
1102 |
$ws_base_uri = cdm_ws_base_uri($cdmBase->class);
|
|
1103 |
|
|
1104 |
if($ws_base_uri === null){
|
|
1105 |
trigger_error(check_plain('Unsupported CDM Class - no annotations available for ' . $cdmBase->class), E_USER_ERROR);
|
|
1106 |
}
|
|
1107 |
return cdm_compose_url($ws_base_uri, array(
|
|
1108 |
$cdmBase->uuid,
|
|
1109 |
'annotations',
|
|
1110 |
));
|
|
1111 |
}
|
|
1112 |
|
|
1113 |
/**
|
|
1114 |
* Provides the base URI of the cdm REST service responsible for the passed simple name
|
|
1115 |
* of a CDM java class. For example 'TaxonName' is the simple name of 'eu.etaxonomy.cdm.model.name.TaxonName'
|
|
1116 |
*
|
|
1117 |
* @param $cdm_type_simple
|
|
1118 |
* simple name of a CDM java class
|
|
1119 |
* @return null|string
|
|
1120 |
*/
|
|
1121 |
function cdm_ws_base_uri($cdm_type_simple)
|
|
1122 |
{
|
1065 |
1123 |
$ws_base_uri = NULL;
|
1066 |
|
switch ($cdmBase->class) {
|
|
1124 |
switch ($cdm_type_simple) {
|
1067 |
1125 |
case 'TaxonBase':
|
1068 |
1126 |
case 'Taxon':
|
1069 |
1127 |
case 'Synonym':
|
... | ... | |
1087 |
1145 |
case 'TaxonInteraction':
|
1088 |
1146 |
case 'QuantitativeData':
|
1089 |
1147 |
case 'IndividualsAssociation':
|
1090 |
|
case 'Distribution':
|
1091 |
1148 |
case 'CommonTaxonName':
|
1092 |
1149 |
case 'CategoricalData':
|
1093 |
1150 |
$ws_base_uri = CDM_WS_DESCRIPTIONELEMENT;
|
... | ... | |
1096 |
1153 |
case 'PolytomousKey':
|
1097 |
1154 |
case 'MediaKey':
|
1098 |
1155 |
case 'MultiAccessKey':
|
1099 |
|
$ws_base_uri = $cdmBase->class;
|
|
1156 |
$ws_base_uri = $cdm_type_simple;
|
1100 |
1157 |
$ws_base_uri{0} = strtolower($ws_base_uri{0});
|
1101 |
1158 |
break;
|
1102 |
1159 |
|
1103 |
1160 |
default:
|
1104 |
|
trigger_error(check_plain('Unsupported CDM Class - no annotations available for ' . $cdmBase->class), E_USER_ERROR);
|
1105 |
|
return;
|
|
1161 |
$ws_base_uri = null;
|
1106 |
1162 |
}
|
1107 |
|
return cdm_compose_url($ws_base_uri, array(
|
1108 |
|
$cdmBase->uuid,
|
1109 |
|
'annotations',
|
1110 |
|
));
|
|
1163 |
return $ws_base_uri;
|
1111 |
1164 |
}
|
1112 |
1165 |
|
1113 |
1166 |
/**
|
fix #7602 expand TaggedText->entityReference objects