Project

General

Profile

« Previous | Next » 

Revision 267da0d1

Added by Katja Luther over 5 years ago

create an item_list for specimen page

View differences:

modules/cdm_dataportal/includes/occurrences.inc
817 817

  
818 818
    return $sequence_elements;
819 819
}
820
/**
821
 * Creates an array from a list of FieldUnitDTOs.
822
 *
823
 *
824
 * @param object $specimenOrObservations
825
 *   list of FieldUnitDTOs
826
 * @return array
827
 *   An array containing the hierarchy of the field units corresponding to the taxon
828
 *
829
 * @ingroup compose
830
 */
831
function create_specimen_array(array $specimenOrObservations){
832
    $items_specimen = array();
833
    $items = array();
834
    $children = array();
835
    //we need one more item to contain the items of one level (fieldunit, derivate data etc.)
836
    foreach ($specimenOrObservations as &$specimenOrObservation) {
837
        $items['data'] = $specimenOrObservation->titleCache;
838
        $specimen = create_cdm_specimen_or_observation($specimenOrObservation);
839
        $children = array();
840
        $child = array();
841
        $child['data'] =$specimen;
842
       // $children[] = create_specimen_array($specimenOrObservation->derivates);
843
       if (isset($specimenOrObservation->derivates) && sizeof($specimenOrObservation->derivates) > 0){
844
           $child['children']= create_specimen_array($specimenOrObservation->derivates);
845
       }
846
       $children[]=$child;
847
       $items['children'] = $children;
848
       $items_specimen[] = $items;
849
    }
850
    return $items_specimen;
851
}
852

  
853

  
854
/**
855
 * Compose an render array from a CDM DerivedUnitFacade object.
856
 *
857
 * compose_hook() implementation
858
 *
859
 * @param object $specimenOrObservation
860
 *   the CDM instance of type SpecimenOrObservation to compose
861
 *   the render array for
862
 * @param array $derivatives
863
 *   the render array which contains the compositions of the derivatives
864
 *   of the supplied $specimenOrObservation
865
 *
866
 * @return array
867
 *   the supplied render array $derivatives to which the composition of the supplied
868
 *   $specimenOrObservation has been added to
869
 *
870
 * @ingroup compose
871
 */
872

  
873
function create_cdm_specimen_or_observation($specimenOrObservation)
874
{
875
    $exclude_occurrence_fields = &drupal_static(__FUNCTION__);
876
    if (!isset($exclude_occurrence_fields)) {
877
        $exclude_occurrence_fields = array(
878
            'type',
879
            'derivationEvent',
880
            'taxonRelatedDerivedUnits',
881
            'titleCache',
882
            'protectedTitleCache',
883
            'derivedUnitMedia',
884
            'created',
885
            'publish',
886
            'updated',
887
            'class',
888
            'uuid',
889
            'collectionDTO'
890
        );
891
    }
892
    $items = array();
893

  
894
    // only show uuid it the user is logged in
895
    if (user_is_logged_in() && ($a_idx = array_search('uuid', $exclude_occurrence_fields)) !== FALSE) {
896
      //  unset($exclude_occurrence_fields[$a_idx]);
897
    }
898

  
899

  
900
    if (is_object($specimenOrObservation)) {
901

  
902
        $type_label = $specimenOrObservation->recordBase;
903
        RenderHints::setFootnoteListKey($type_label . '-' . $specimenOrObservation->uuid);
904

  
905
        // collect typeStatus as label
906
        if (isset($specimenOrObservation->specimenTypeDesignations)) {
907
            $type_status = array();
908
            foreach ($specimenOrObservation->specimenTypeDesignations as $typeDesignation) {
909
                if (isset($typeDesignation->typeStatus->representation_L10n)) {
910
                    $type_status[] = $typeDesignation->typeStatus->representation_L10n;
911
                }
912
            }
913
            if (count($type_status) > 0) {
914
                $type_label = implode(', ', $type_status);
915
            }
916
        }
917

  
918
        $title = $type_label . ': ' . $specimenOrObservation->titleCache;
919
        $items['data'] = title;
920

  
921
        $groups = array();
922
        $items['children'] = $groups;
923
        $children_items = array();
924
        // --- add initialized fields
925
        foreach (get_object_vars($specimenOrObservation) as $field => $value) {
926
            $child_item = array();
927

  
928
            if (!in_array($field, $exclude_occurrence_fields) && ($value && (!is_object($value) || isset($value->class)))) {
929
                switch ($field) {
930
//            case 'recordBasis':
931
//                if ($value != '' /* FieldUnit' */) {
932
//                    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
933
//                }
934
//                break;
935
                    /* ---- java.lang.Object --- */
936
                    case 'class':
937
                        if ($value != '' /* FieldUnit' */) {
938
                        //    @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
939
                        }
940

  
941
                        break;
942

  
943
                    case 'markers':
944
                       /* $dd_elements = array();
945
                        foreach ($value as $marker) {
946
                            $dd_elements[] = compose_cdm_marker($marker);
947
                        }
948
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
949
                       */
950
                       break;
951

  
952

  
953
                    case 'annotations':
954
                        /*$dd_elements = array();
955
                        foreach ($value as $annotation) {
956
                            // TODO respect annotation type filter settings
957
                            $dd_elements[] = $annotation->text;
958
                        }
959
                        @_description_list_group_add($groups, t('Notes'), $dd_elements);
960
                        */
961
                        break;
962

  
963
                    /* ---- SpecimenOrObservationBase --- */
964
                    case 'sex':
965
                    case 'lifeStage':
966
                    case 'kindOfUnit':
967
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value->representation_L10n, NULL, 1);
968
                        break;
969

  
970
                    case 'definition':
971
                        // TODO
972
                        break;
973

  
974
                    case 'preferredStableUri':
975

  
976
                       // @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), array(array('#markup' => cdm_external_uri($value, false))));
977
                        break;
978

  
979
                    case 'specimenTypeDesignations':
980
                      /*     $groups,
981
                            cdm_occurrence_field_name_label($field),
982
                            array(
983
                                '#markup' => theme('cdm_typedesignations', array('typeDesignations' => $value)),
984
                            )
985
                        );
986
                      */
987
                        break;
988

  
989
                    case 'determinations':
990
                        /*$dd_elements = array();
991
                        $glue = ', ';
992

  
993
                        foreach ($value as $determinationEvent) {
994
                            $timeperiod_string = NULL;
995
                            if (isset($determinationEvent->timeperiod)) {
996
                                $timeperiod_string = timePeriodToString($determinationEvent->timeperiod);
997
                            }
998
                            $weight = isset($determinationEvent->preferred) && $determinationEvent->preferred == 1 ? '0' : ($timeperiod_string ? $timeperiod_string : '1');
999
                            // check key exists
1000
                            while (array_key_exists($weight, $dd_elements)) {
1001
                                $weight .= '0';
1002
                            }
1003

  
1004
                            $taxon_name = '';
1005
                            $name_link = '';
1006
                            if ($determinationEvent->taxonName) {
1007
                                $taxon_name = $determinationEvent->taxonName;
1008
                            } else if ($determinationEvent->taxon) {
1009
                                $taxon_name = cdm_ws_get(CDM_WS_TAXON . '/$0/name', $determinationEvent->taxon->uuid);
1010
                                $name_link = path_to_taxon($determinationEvent->taxon->uuid);
1011
                            }
1012
                            if ($taxon_name) {
1013
                                $taxon_html = render_taxon_or_name($taxon_name, $name_link);
1014
                                $dd_elements[$weight] = $taxon_html;
1015
                            }
1016
                            if (isset($determinationEvent->modifier)) {
1017
                                $dd_elements[$weight] .= cdm_term_representation($determinationEvent->modifier);
1018
                            }
1019
                            if ($timeperiod_string) {
1020
                                $dd_elements[$weight] .= $glue . $timeperiod_string;
1021
                            }
1022
                            if (isset($determinationEvent->actor->titleCache)) {
1023
                                $dd_elements[$weight] .= $glue . $determinationEvent->actor->titleCache;
1024
                            }
1025
                            if (isset($determinationEvent->description)) {
1026
                                $dd_elements[$weight] .= $glue . $determinationEvent->description;
1027
                            }
1028
                        }
1029
                        ksort($dd_elements);
1030
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('determinations'), $dd_elements);
1031
                        */
1032
                        break;
1033

  
1034
                    case 'descriptions':
1035
                        /*
1036
                        $occurrence_featureTree = cdm_get_occurrence_featureTree();
1037
                        $dd_elements = array();
1038

  
1039
                        foreach ($value as $description) {
1040
                            $description = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION, $description->uuid);
1041
//               if($description->imageGallery == TRUE) {
1042
//                 continue;
1043
//               }
1044
                            $elements_by_feature = _mergeFeatureTreeDescriptions($occurrence_featureTree->root->childNodes, $description->elements);
1045
                            $description_render_elements = _block_get_renderable_array(make_feature_block_list($elements_by_feature, null));
1046
                            $dd_elements[] = $description_render_elements;
1047
                            if ($description->isImageGallery) {
1048
                                $mediaList = array();
1049
                                if (is_array($description->elements)) {
1050
                                    $mediaList = $description->elements;
1051
                                }
1052
                                $gallery_html = '';
1053
                                if (count($mediaList) > 0) {
1054
                                    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
1055
                                    $captionElements = array(
1056
                                        '#uri' => t('open media'),
1057
                                    );
1058

  
1059
                                    $gallery_html = compose_cdm_media_gallerie(array(
1060
                                        'mediaList' => $mediaList,
1061
                                        'galleryName' => $gallery_name,
1062
                                        'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
1063
                                        'cols' => $gallery_settings['cdm_dataportal_media_cols'],
1064
                                        'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
1065
                                        'captionElements' => $captionElements,
1066
                                        'mediaLinkType' => 'LIGHTBOX',
1067
                                        'alternativeMediaUri' => NULL,
1068
                                        'galleryLinkUri' => NULL,
1069
                                    ));
1070
                                }
1071

  
1072
                            }
1073
                        }
1074

  
1075
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
1076
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $gallery_html);
1077
                        */
1078
                        break;
1079

  
1080
                    case 'sources':
1081
                        /*
1082
                        $dd_elements = array();
1083
                        foreach ($value as $identifiable_source) {
1084
                            $dd_elements[] = theme('cdm_OriginalSource', array('source' => $identifiable_source));
1085
                        }
1086
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements, NULL, 10);
1087
                        */
1088
                        break;
1089

  
1090

  
1091
                    /* ---- DerivedUnitBase --- */
1092

  
820 1093

  
1094
                    case 'collection':
1095
                        /*
1096
                        $sub_dl_groups = array();
1097
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('code'), $value->code, NULL, 1);
1098
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('codeStandard'), $value->codeStandard, NULL, 2);
1099
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('institute'), $value->institute, NULL, 3);
1100
                        @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('townOrLocation'), $value->townOrLocation, NULL, 4);
1101
                        // TODO "superCollection"
1102
                        // TODO may have media
1103

  
1104
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field),
1105
                            array(
1106
                                array('#markup' => $value->titleCache),
1107
                                array('#theme' => 'description_list', '#groups' => $sub_dl_groups)
1108
                            )
1109
                        );
1110
                        */
1111
                        break;
1112

  
1113
                    case 'storedUnder':
1114

  
1115
                        //@_description_list_group_add($groups, cdm_occurrence_field_name_label('storedUnder'), render_taxon_or_name($value));
1116
                        break;
1117

  
1118

  
1119
                    /* ---- Specimen --- */
1120
                    case 'sequences':
1121
                        /*
1122
                        $dd_elements = array();
1123
                        foreach ($value as $sequence) {
1124
                            $dd_elements[] = compose_cdm_sequence($sequence);
1125
                        }
1126
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label($field), $dd_elements);
1127
                        */
1128
                        break;
1129

  
1130
                    // TODO preservation
1131
                    // TODO exsiccatum
1132

  
1133

  
1134
                    /* ---- FieldObservation --- */
1135
                    case 'gatheringEvent':
1136

  
1137
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collector'), $value->actor->titleCache);
1138
                        @_description_list_group_add($groups, t('Gathering time'), timePeriodToString($value->timeperiod));
1139
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('description'), $value->description);
1140
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('locality'), $value->locality->text);
1141
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('country'), $value->country->representation_L10n);
1142
                        @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingMethod'), $value->collectingMethod);
1143
                        if (isset($value->absoluteElevation)) {
1144
                            $min_max_markup = min_max_measure($value, 'absoluteElevation');
1145
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('absoluteElevation'), $min_max_markup);
1146
                        }
1147
                        if (isset($value->distanceToGround)) {
1148
                            $min_max_markup = min_max_measure($value, 'distanceToGround');
1149
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToGround'), $min_max_markup);
1150
                        }
1151
                        if (isset($value->distanceToWaterSurface)) {
1152
                            $min_max_markup = min_max_measure($value, 'distanceToWaterSurface');
1153
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('distanceToWaterSurface'), $min_max_markup);
1154
                        }
1155

  
1156
                        if (isset($value->collectingAreas)) {
1157
                            $area_representations = array();
1158
                            foreach ($value->collectingAreas as $area) {
1159
                                $area_representations[] = l($area->representation_L10n, path_to_named_area($area->uuid));
1160
                            }
1161
                            if (!empty($area_representations))
1162
                                @_description_list_group_add($groups, cdm_occurrence_field_name_label('collectingAreas'),
1163
                                    array(
1164
                                        array('#markup' => implode(', ', $area_representations))
1165
                                    )
1166
                                );
1167
                        }
1168
                        if (isset($value->exactLocation)  && $value->exactLocation->sexagesimalString) {
1169
                            $sub_dl_groups = array();
1170
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('errorRadius'), $value->exactLocation->errorRadius, ' m', 1);
1171
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('longitude'), round($value->exactLocation->longitude, 7), '°', 2);
1172
                            @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('latitude'), round($value->exactLocation->latitude, 7), '°', 3);
1173
                            if (isset($value->exactLocation->referenceSystem)) {
1174
                                @_description_list_group_add($sub_dl_groups, cdm_occurrence_field_name_label('referenceSystem'), $value->exactLocation->referenceSystem->representation_L10n, '', 4);
1175
                            }
1176

  
1177
                            @_description_list_group_add($groups, cdm_occurrence_field_name_label('exactLocation'),
1178
                                array(
1179
                                    array('#markup' => $value->exactLocation->sexagesimalString),
1180
                                    array(
1181
                                        '#theme' => 'description_list',
1182
                                        '#groups' => $sub_dl_groups
1183
                                    ),
1184
                                )
1185
                            );
1186
                        }
1187

  
1188
                        break;
1189

  
1190
                    /* ---- DerivationEvent --- */
1191
                    case 'derivationEvents':
1192
                        //@_description_list_group_add($groups, t('Association type'), $value->description);
1193
                        break;
1194

  
1195

  
1196
                    default:
1197
                        if (is_object($value) || is_array($value)) {
1198
                           // drupal_set_message("Unhandled type in compose_cdm_specimenOrObservation() for field " . $field, "warning");
1199
                        } else {
1200
                            _description_list_group_add($groups, cdm_occurrence_field_name_label($field), $value);
1201
                        }
1202

  
1203
                }
1204

  
1205

  
1206
            }
1207
        } // END of loop over $derivedUnitFacade fields
1208

  
1209
        // Extensions
1210
       /* $extensions = cdm_ws_fetch_all(CDM_WS_PORTAL_OCCURRENCE . '/' . $specimenOrObservation->uuid . '/extensions', array($specimenOrObservation->uuid));
1211
        if ($extensions && count($extensions)) {
1212

  
1213
            $extensions_render_array = compose_extensions($extensions);
1214
            @_description_list_group_add($groups, t('Extensions') . ':',
1215
                $extensions_render_array,
1216
                '', 100);
1217
        }
1218
*/
1219

  
1220
        // template_preprocess_description_list() is not worting by weight so we do it right here
1221
        uasort($groups, 'element_sort');
1222

  
1223
        $occurrence_elements = array(
1224
           // '#title' => $title,
1225
            '#theme' => 'description_list',
1226
            '#groups' => $groups,
1227
            '#attributes' => array('class' => html_class_attribute_ref($specimenOrObservation)),
1228
        );
1229
        $output = drupal_render($occurrence_elements);
1230

  
1231

  
1232

  
1233

  
1234

  
1235

  
1236

  
1237

  
1238
    } // END of $specimenOrObservation exists
1239

  
1240
    return $output;
1241
}
821 1242

  

Also available in: Unified diff