1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* Returns the localized representations of the modifiers hold by the supplied cdm instance concatenated into one string.
|
5
|
*
|
6
|
* @param object $iModifieable
|
7
|
* cdm instance of an class implementing the interface IModifieable: DescriptionElementBase, StateDate, State
|
8
|
*/
|
9
|
function cdm_modifers_representations($iModifieable, $glue = ', ') {
|
10
|
$modifiers_strings = array();
|
11
|
if (isset($iModifieable->modifiers)) {
|
12
|
foreach ($iModifieable->modifiers as $modifier) {
|
13
|
$modifiers_strings[] = cdm_term_representation($modifier);
|
14
|
}
|
15
|
}
|
16
|
return implode(', ', $modifiers_strings);
|
17
|
}
|
18
|
/**
|
19
|
* Filters the given set of description elements and prefers computed elements over
|
20
|
* others. Computed description elements are identified by the MarkerType.COMPUTED()
|
21
|
*
|
22
|
* If the given set contains at least one computed element only the computed elements
|
23
|
* returned.
|
24
|
*
|
25
|
* @param $description_elements
|
26
|
* An array of CDM DescriptionElementBase instances
|
27
|
* @return only the computed description elements otherwise all others.
|
28
|
*/
|
29
|
function cdm_description_elements_prefer_computed($description_elements){
|
30
|
|
31
|
$computed_elements = array();
|
32
|
$other_elements = array();
|
33
|
|
34
|
if(!empty($description_elements)){
|
35
|
foreach ($description_elements as $element) {
|
36
|
if(cdm_entity_has_marker($element, UUID_MARKERTYPE_COMPUTED)){
|
37
|
$computed_elements[] = $element;
|
38
|
} else {
|
39
|
$other_elements[] = $element;
|
40
|
}
|
41
|
}
|
42
|
}
|
43
|
|
44
|
if(count($computed_elements) > 0) {
|
45
|
return $computed_elements;
|
46
|
} else {
|
47
|
return $other_elements;
|
48
|
}
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* Merge the fields 'annotations', 'markers', 'sources', 'media' from the source CDM DescriptionElement into the target.
|
53
|
*
|
54
|
* @param $target
|
55
|
* The source CDM DescriptionElement
|
56
|
* @param $source
|
57
|
* The target CDM DescriptionElement
|
58
|
*/
|
59
|
function cdm_merge_description_elements(&$target, &$source){
|
60
|
static $fields_to_merge = array('annotations', 'markers', 'sources', 'media');
|
61
|
|
62
|
foreach ($fields_to_merge as $field){
|
63
|
if(is_array($source->$field)) {
|
64
|
if(!is_array($target->$field)){
|
65
|
$target->$field = $source->$field;
|
66
|
} else {
|
67
|
$target->$field = array_merge($target->$field, $source->$field);
|
68
|
}
|
69
|
}
|
70
|
}
|
71
|
}
|