Revision 29857cb0
Added by Andreas Kohlbecker over 2 years ago
modules/cdm_dataportal/includes/descriptions.inc | ||
---|---|---|
1847 | 1847 |
); |
1848 | 1848 |
|
1849 | 1849 |
|
1850 |
$status = distribution_status_label_and_markup($description_element);
|
|
1850 |
$status = distribution_status_label_and_markup([$description_element]);
|
|
1851 | 1851 |
|
1852 | 1852 |
$out = ''; |
1853 | 1853 |
$out .= '<' . $enclosingTag . ' class="descriptionElement descriptionElement-' . $description_element->uuid |
... | ... | |
1866 | 1866 |
} |
1867 | 1867 |
|
1868 | 1868 |
/** |
1869 |
* @param $description_element
|
|
1869 |
* @param array $distribution_status
|
|
1870 | 1870 |
* @return array an array with following keys |
1871 | 1871 |
* - 'label': the plain text status label |
1872 | 1872 |
* - 'markup': markup for the status |
1873 | 1873 |
*/ |
1874 |
function distribution_status_label_and_markup($description_element, $status_glue = '‒ ') { |
|
1874 |
function distribution_status_label_and_markup(array $distribution_status, $status_glue = '‒ ') { |
|
1875 |
|
|
1875 | 1876 |
$status_markup = ''; |
1876 | 1877 |
$status_label = ''; |
1877 | 1878 |
|
1878 |
if (isset($description_element->status)) {
|
|
1879 |
$status_label = $description_element->status->representation_L10n;
|
|
1880 |
$status_markup = '<span class="distributionStatus"> ' |
|
1881 |
. $status_glue
|
|
1882 |
. '<span class="distributionStatus-' . $description_element->status->idInVocabulary . '">'
|
|
1883 |
. $status_label
|
|
1879 |
foreach($distribution_status as $status) {
|
|
1880 |
$status_label .= ($status_label ? $status_glue : '') . $status->representation_L10n;
|
|
1881 |
$status_markup .= '<span class="distributionStatus"> '
|
|
1882 |
. ($status_markup ? $status_glue : '')
|
|
1883 |
. '<span class="distributionStatus-' . $status->idInVocabulary . '">' |
|
1884 |
. $status->representation_L10n
|
|
1884 | 1885 |
. '</span></span>'; |
1885 | 1886 |
|
1886 | 1887 |
}; |
... | ... | |
1970 | 1971 |
return $merged_tree; |
1971 | 1972 |
} |
1972 | 1973 |
|
1973 |
|
|
1974 |
/** |
|
1975 |
* @param $distribution_tree |
|
1976 |
* A tree cdm TreeNode items. A TreeNode item has a NamedArea as nodeId |
|
1977 |
* and Distribution items as data array. Per data array some Distributions may |
|
1978 |
* be with status information, others only with sources, others with both. |
|
1979 |
* Each node may also have subordinate node items in the children field. |
|
1980 |
* TreeNode: |
|
1981 |
* - array data |
|
1982 |
* - array children |
|
1983 |
* - int numberOfChildren |
|
1984 |
* - stdClass nodeId |
|
1985 |
* |
|
1986 |
* @param $feature_block_settings |
|
1987 |
* |
|
1988 |
* @return array |
|
1989 |
* @throws \Exception |
|
1990 |
*/ |
|
1974 | 1991 |
function compose_distribution_hierarchy($distribution_tree, $feature_block_settings){ |
1975 | 1992 |
|
1976 | 1993 |
static $hierarchy_style; |
... | ... | |
2007 | 2024 |
return $render_array; |
2008 | 2025 |
} |
2009 | 2026 |
|
2010 |
/** |
|
2011 |
* this function should produce markup as the compose_description_elements_distribution() |
|
2012 |
* function. |
|
2013 |
* |
|
2014 |
* @see compose_description_elements_distribution() |
|
2015 |
* |
|
2016 |
* @param $distribution_tree |
|
2017 |
* @param $feature_block_settings |
|
2018 |
* @param $tree_nodes |
|
2019 |
* @param $markup |
|
2020 |
* @param $hierarchy_style |
|
2021 |
*/ |
|
2022 |
function _compose_distribution_hierarchy($tree_nodes, $feature_block_settings, &$markup, $hierarchy_style, $level_index = -1){ |
|
2027 |
/** |
|
2028 |
* this function should produce markup as the |
|
2029 |
* compose_description_elements_distribution() function. |
|
2030 |
* |
|
2031 |
* @param array $tree_nodes |
|
2032 |
* An array of cdm TreeNode items. A TreeNode item has a NamedArea as nodeId |
|
2033 |
* and Distribution items as data array. Per data array some Distributions may |
|
2034 |
* be with status information, others only with sources, others with both. |
|
2035 |
* TreeNode: |
|
2036 |
* - array data |
|
2037 |
* - array children |
|
2038 |
* - int numberOfChildren |
|
2039 |
* - stdClass nodeId |
|
2040 |
* @param array $feature_block_settings |
|
2041 |
* @param $markup |
|
2042 |
* @param $hierarchy_style |
|
2043 |
* @param int $level_index |
|
2044 |
* |
|
2045 |
* @throws \Exception |
|
2046 |
* |
|
2047 |
* @see compose_description_elements_distribution() |
|
2048 |
* @see compose_distribution_hierarchy() |
|
2049 |
* |
|
2050 |
*/ |
|
2051 |
function _compose_distribution_hierarchy(array $tree_nodes, array $feature_block_settings, &$markup, $hierarchy_style, $level_index = -1){ |
|
2023 | 2052 |
|
2024 | 2053 |
$level_index++; |
2025 | 2054 |
static $enclosingTag = "span"; |
... | ... | |
2032 | 2061 |
|
2033 | 2062 |
$node_index = -1; |
2034 | 2063 |
$per_node_markup = array(); |
2064 |
|
|
2035 | 2065 |
foreach ($tree_nodes as $node){ |
2036 | 2066 |
|
2037 | 2067 |
$per_node_markup[++$node_index] = ''; |
2038 |
|
|
2039 | 2068 |
$label = $node->nodeId->representation_L10n; |
2040 | 2069 |
|
2041 | 2070 |
$distributions = $node->data; |
2042 | 2071 |
$distribution_uuids = array(); |
2043 | 2072 |
$distribution_aggregate = NULL; |
2044 |
foreach($distributions as $distribution){ |
|
2045 |
|
|
2046 |
$distribution_uuids[] = $distribution->uuid; |
|
2047 |
|
|
2048 |
// if there is more than one distribution we aggregate the sources and |
|
2049 |
// annotations into a synthetic distribution so that the footnote keys |
|
2050 |
// can be rendered consistently |
|
2051 |
if(!$distribution_aggregate) { |
|
2052 |
$distribution_aggregate = $distribution; |
|
2053 |
if(!isset($distribution_aggregate->sources[0])){ |
|
2054 |
$distribution_aggregate->sources = array(); |
|
2055 |
} |
|
2056 |
if(!isset($distribution_aggregate->annotations[0])){ |
|
2057 |
$distribution_aggregate->annotations = array(); |
|
2058 |
} |
|
2073 |
$status = ['label' => '', 'markup' => '']; |
|
2074 |
|
|
2075 |
foreach($distributions as $distribution){ |
|
2076 |
$distribution_uuids[] = $distribution->uuid; |
|
2077 |
// if there is more than one distribution we aggregate the sources and |
|
2078 |
// annotations into a synthetic distribution so that the footnote keys |
|
2079 |
// can be rendered consistently |
|
2080 |
if(!$distribution_aggregate) { |
|
2081 |
$distribution_aggregate = $distribution; |
|
2082 |
if(isset($distribution->status)){ |
|
2083 |
$distribution_aggregate->status = [$distribution->status]; |
|
2059 | 2084 |
} else { |
2060 |
if(isset($distribution->sources[0])) { |
|
2061 |
$distribution_aggregate->sources = array_merge($distribution_aggregate->sources, |
|
2062 |
$distribution->sources); |
|
2063 |
} |
|
2064 |
if(isset($distribution->annotations[0])) { |
|
2065 |
$distribution_aggregate->annotations = array_merge($distribution_aggregate->annotations, |
|
2066 |
$distribution->annotations); |
|
2067 |
} |
|
2085 |
$distribution_aggregate->status = []; |
|
2086 |
} |
|
2087 |
if(!isset($distribution_aggregate->sources[0])){ |
|
2088 |
$distribution_aggregate->sources = array(); |
|
2089 |
} |
|
2090 |
if(!isset($distribution_aggregate->annotations[0])){ |
|
2091 |
$distribution_aggregate->annotations = array(); |
|
2092 |
} |
|
2093 |
} else { |
|
2094 |
if(isset($distribution->status)){ |
|
2095 |
$distribution_aggregate->status[] = $distribution->status; |
|
2096 |
} |
|
2097 |
if(isset($distribution->sources[0])) { |
|
2098 |
$distribution_aggregate->sources = array_merge($distribution_aggregate->sources, |
|
2099 |
$distribution->sources); |
|
2100 |
} |
|
2101 |
if(isset($distribution->annotations[0])) { |
|
2102 |
$distribution_aggregate->annotations = array_merge($distribution_aggregate->annotations, |
|
2103 |
$distribution->annotations); |
|
2068 | 2104 |
} |
2069 | 2105 |
} |
2106 |
} |
|
2070 | 2107 |
|
2071 |
$status_label= ''; |
|
2072 |
$status_markup = ''; |
|
2073 | 2108 |
$annotations_and_sources = null; |
2074 | 2109 |
if($distribution_aggregate) { |
2075 | 2110 |
$annotations_and_sources = handle_annotations_and_sources( |
... | ... | |
2079 | 2114 |
UUID_DISTRIBUTION |
2080 | 2115 |
); |
2081 | 2116 |
|
2082 |
$status = distribution_status_label_and_markup($distribution_aggregate, $level_style['status_glue']); |
|
2117 |
$status = distribution_status_label_and_markup($distribution_aggregate->status, $level_style['status_glue']); |
|
2118 |
} |
|
2083 | 2119 |
|
2084 | 2120 |
$per_node_markup[$node_index] .= '<' . $enclosingTag . ' class="descriptionElement' |
2085 | 2121 |
. join(' descriptionElement-', $distribution_uuids) |
... | ... | |
2110 | 2146 |
} |
2111 | 2147 |
|
2112 | 2148 |
$per_node_markup[$node_index] .= '</' . $enclosingTag . '>'; |
2113 |
} |
|
2114 | 2149 |
} |
2115 | 2150 |
$markup .= $level_style['item_group_prefix'] . join( $level_style['item_glue'], $per_node_markup) . $level_style['item_group_postfix']; |
2116 | 2151 |
} |
Also available in: Unified diff
solving problems with multiple distributions per tree node