Project

General

Profile

« Previous | Next » 

Revision 961319fe

Added by Andreas Kohlbecker almost 5 years ago

ref #8406 clenaing and harmonization of the specimen related code in the dataportal

View differences:

modules/cdm_dataportal/includes/occurrences.inc
985 985

  
986 986
    return $sequence_elements;
987 987
}
988

  
989
/**
990
 * Crates an array which can be used in render arrays to be passed to the theme_table() and theme_list().
991
 * @param array $fieldunit_dtos
992
 *     list of FieldUnitDTOs
993
 */
994
function specimen_render_array_items(array $fieldunit_dtos){
995

  
996
  $render_array_items = array();
997
  $items = array();
998

  
999
  //we need one more item to contain the items of one level (fieldunit, derivate data etc.)
1000
  foreach ($fieldunit_dtos as &$fieldunit_dto) {
1001

  
1002
    $items['data'] = $fieldunit_dto->listLabel ;
1003
    $specimen = compose_cdm_specimen_or_observation_tree_entry($fieldunit_dto);
1004
    $children = array();
1005
    $child = array();
1006
    $child['data'] =$specimen;
1007
    // $children[] = create_specimen_array($specimenOrObservation->derivates);
1008
    if (isset($fieldunit_dto->derivates) && sizeof($fieldunit_dto->derivates) > 0){
1009
      $child['children']= specimen_render_array_items($fieldunit_dto->derivates);
1010
    }
1011
    $children[]=$child;
1012
    $items['children'] = $children;
1013
    $render_array_items[] = $items;
1014
  }
1015
  return $render_array_items;
1016
}
1017

  
1018
/**
1019
 * Creates the drupal render array for the table showing all derivatives which
1020
 * stem from a common gathering event.
1021
 *
1022
 * @param $field_unit_uuids array
1023
 *  An array of uuids for cdm FieldUnit entities.
1024
 *
1025
 * @return array
1026
 *  A drupal render array for a table
1027
 *
1028
 * @ingroup compose
1029
 */
1030

  
1031
function compose_compressed_specimen_derivate_table($field_unit_uuids) {
1032

  
1033
  // prepare font icons
1034
  $expand_icon = font_awesome_icon_markup(
1035
    'fa-plus-square-o',
1036
    array(
1037
      'alt' => 'Show details',
1038
      'class' => array('expand_icon')
1039
    )
1040
  );
1041
  $collapse_icon = font_awesome_icon_markup(
1042
    'fa-minus-square-o',
1043
    array(
1044
      'alt' => 'Show details',
1045
      'class' => array('collapse_icon')
1046
    )
1047
  );
1048
  $detail_image_icon = '<img title="Detail Image" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/detail_image_derivate-16x16-32.png' . '"/>';
1049
  $checked_box_icon = '<img src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/step_done.gif' . '"/>';
1050
  $sequence_icon = '<img title="Molecular Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/sequence_derivate-16x16-32.png' . '"/>';
1051
  $character_data_icon = '<img title="Character Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/character_data_derivate-16x16-32.png' . '"/>';
1052

  
1053
  $rowcount = 0;
1054
  $rows = array();
1055

  
1056
  foreach ($field_unit_uuids as $field_unit_uuid) {
1057

  
1058
    //get derivate hierarchy for the FieldUnit
1059
    $derivateHierarchy = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($field_unit_uuid, 'derivateHierarchy'));
1060
    if ($derivateHierarchy) {
1061
      //summary row
1062
      $rows[] = array(
1063
        'data' => array(
1064
          array(
1065
            'data' => $expand_icon . $collapse_icon,
1066
            'class' => array('summary_row_cell', 'summary_row_icon', 'expand_column')
1067
          ),
1068
          array(
1069
            'data' => $derivateHierarchy->country,
1070
            'class' => array('summary_row_cell')
1071
          ),
1072
          array(
1073
            'data' => $derivateHierarchy->date,
1074
            'class' => array('summary_row_cell')
1075
          ),
1076
          array(
1077
            'data' => $derivateHierarchy->collectingString,
1078
            'class' => array('summary_row_cell')
1079
          ),
1080
          @array(
1081
            'data' => $derivateHierarchy->collection,
1082
            'class' => array('summary_row_cell')
1083
          ),
1084
          array(
1085
            'data' => $derivateHierarchy->hasType ? $checked_box_icon : "",
1086
            'class' => array('summary_row_cell', 'summary_row_icon')
1087
          ),
1088
          array(
1089
            'data' => $derivateHierarchy->hasSpecimenScan ? $checked_box_icon : "",
1090
            'class' => array('summary_row_cell', 'summary_row_icon')
1091
          ),
1092
          array(
1093
            'data' => ($derivateHierarchy->hasDna ? $sequence_icon : "") . " "
1094
              . ($derivateHierarchy->hasDetailImage ? $detail_image_icon : "") . " "
1095
              . ($derivateHierarchy->hasCharacterData ? $character_data_icon : ""),
1096
            'class' => array('summary_row_cell', 'summary_row_icon')
1097
          )
1098
        ),
1099
        'id' => 'derivate_summary' . $rowcount, // summary row id
1100
        'class' => array('summary_row'),
1101
      );
1102

  
1103
      //assemble field unit details
1104
      $detail_html = "";
1105
      // - citation
1106
      if ($derivateHierarchy->citation) {
1107
        $detail_html .= create_label("Citation") . $derivateHierarchy->citation . "<br>";
1108
      }
1109
      //assemble specimen details
1110
      if ($derivateHierarchy->derivates) {
1111
        foreach ($derivateHierarchy->derivates as $preservedSpecimenDTO) {
1112
          $detail_html .= "<br>";
1113
          $detail_html .= render_cdm_specimenDTO_page($preservedSpecimenDTO);
1114
        }
1115
      }
1116
      $detail_html .= "<br>";
1117
      //detail row resp. one BIG detail cell
1118
      $rows[] = array(
1119
        'data' => array(
1120
          array(
1121
            'data' => "", //empty first column
1122
            'class' => array('expand_column')
1123
          ),
1124
          array(
1125
            'data' => $detail_html,
1126
            'colspan' => 7,
1127
          ),
1128
        ),
1129
        'id' => 'derivate_details' . $rowcount,//details row ID
1130
        'class' => array('detail_row'),
1131
      );
1132
      $rowcount++;
1133
    }
1134
  }
1135

  
1136
  $tableId = "derivate_hierarchy_table";
1137
  $derivateHierarchyTable = array(
1138
    "#theme" => "table",
1139
    "#weight" => 2,
1140
    "#header" => array(
1141
      array(
1142
        'data' => "",
1143
        'class' => array('expand_column')
1144
      ),
1145
      "Country", "Date", "Collector + collecting number", "Herbaria", "Type", "Scan", "Derivatives"),
1146
    "#rows" => $rows,
1147
    "#attributes" => array(
1148
      "id" => $tableId,
1149
      "border" => 2
1150
    )
1151
  );
1152

  
1153
  //add toggle functionality to derivate hierarchy table
1154
  drupal_add_js_rowToggle("#" . $tableId);
1155

  
1156
  return $derivateHierarchyTable;
1157
}
1158

  
988 1159
/**
989 1160
 * Creates an array from a list of FieldUnitDTOs.
990 1161
 *
......
996 1167
 *
997 1168
 * @ingroup compose
998 1169
 */
999
function compose_specimen_array(array $fieldunit_dtos){
1000
    $items_specimen = array();
1001
    $items = array();
1170
function compose_specimen_table_top_down(array $fieldunit_dtos){
1002 1171

  
1003
    //we need one more item to contain the items of one level (fieldunit, derivate data etc.)
1004
    foreach ($fieldunit_dtos as &$fieldunit_dto) {
1005

  
1006
        $items['data'] = $fieldunit_dto->listLabel ;
1007
        $specimen = compose_cdm_specimen_or_observation_tree_entry($fieldunit_dto);
1008
        $children = array();
1009
        $child = array();
1010
        $child['data'] =$specimen;
1011
       // $children[] = create_specimen_array($specimenOrObservation->derivates);
1012
       if (isset($fieldunit_dto->derivates) && sizeof($fieldunit_dto->derivates) > 0){
1013
           $child['children']= compose_specimen_array($fieldunit_dto->derivates);
1014
       }
1015
       $children[]=$child;
1016
       $items['children'] = $children;
1017
       $items_specimen[] = $items;
1018
    }
1019
    return $items_specimen;
1172
  $specimen_render_array_items = specimen_render_array_items($fieldunit_dtos);
1173

  
1174
    // add icons
1175
  $expand_icon = font_awesome_icon_markup(
1176
    'fa-plus-square-o',
1177
    array(
1178
      'alt' => 'Show details',
1179
      'class' => array('expand_icon')
1180
    )
1181
  );
1182
  $collapse_icon = font_awesome_icon_markup(
1183
    'fa-minus-square-o',
1184
    array(
1185
      'alt' => 'Show details',
1186
      'class' => array('collapse_icon')
1187
    )
1188
  );
1189
  $tableId = "specimen_tree_table";
1190
  $specimen_table = array(
1191
    '#theme' => 'table',
1192
    '#weight' => 2,
1193
    // prefix attributes and rows with '#' to let it pass toF the theme function,
1194
    // otherwise it is handled as child render array
1195
    '#attributes' => array(
1196
      'class' => 'specimens',
1197
      'id' => $tableId
1198
    ),
1199
    '#rows' => array(),
1200
  );
1201
  $rowcount = 0;
1202
  foreach($specimen_render_array_items as $value){
1203
    $renderArray = array(
1204
      '#theme' => 'item_list',
1205
      '#items' => $value['children'],
1206
      '#type' => 'ul');
1207
    $output = drupal_render($renderArray);
1208

  
1209
    $specimen_table['#rows'][] = array(
1210
      'data' =>array(
1211
        array(
1212
          'data' => $expand_icon . $collapse_icon,
1213
          'class' => array('summary_row_cell', 'summary_row_icon', 'expand_column')
1214
        ),
1215
        $value['data']
1216
      ),
1217
      'id' => 'label' . $rowcount, // summary row id
1218
      'class' => array('summary_row'),
1219
    );
1220
    $specimen_table['#rows'][] = array(
1221
      'data' =>  array(
1222
        array(
1223
          'data' => "", //empty first column
1224
          'class' => array('expand_column')
1225
        ),
1226
        array(
1227
          'data' => $output
1228

  
1229
        )
1230
      ),
1231
      'class' =>  array('detail_row')
1232
//                'class' =>  array(
1233
//                    'descriptionElement',
1234
//                    'descriptionElement_IndividualsAssociation'
1235
      //               ),
1236
    );
1237
    $rowcount++;
1238

  
1239
  }
1240
  drupal_add_js_rowToggle("#".$tableId);
1241

  
1242
  return $specimen_table;
1020 1243
}
1021 1244

  
1022 1245

  
......
1540 1763
  return $specimen_table;
1541 1764
}
1542 1765

  
1766

  
1767
/**
1768
 * Orders occurrences by date but types should be on top of the list.
1769
 *
1770
 * @param $specimensOrObservations_or_fieldUnitDTO
1771
 *
1772
 * @return array
1773
 */
1774
function order_specimens_or_observations_by_date_and_type($specimensOrObservations)
1775
{
1776
// order occurrences by date but types should be on top of the list
1777
  $type_specimens = array();
1778
  $other_occurrences = array();
1779
  foreach ($specimensOrObservations as &$occurrence) {
1780
    $typeDesignationsPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $occurrence->uuid);
1781
    if (isset($typeDesignationsPager->count) && $typeDesignationsPager->count > 0) {
1782
      $type_specimens[] = $occurrence;
1783
    } else {
1784
      $other_occurrences[] = $occurrence;
1785
    }
1786
  }
1787
  $specimensOrObservations = array_merge($type_specimens, $other_occurrences);
1788
  return $specimensOrObservations;
1789
}
1790

  
1791
/**
1792
 * Orders FieldUnitDTOs by date but types should be on top of the list.
1793
 *
1794
 * Delegates internally to order_specimens_or_observations_by_date_and_type()
1795
 *
1796
 * @param $fieldUnitDTOs
1797
 *
1798
 * @return array
1799
 */
1800
function order_fieldUnitDtos_by_date_and_type($fieldUnitDTOs)
1801
{
1802
  return order_specimens_or_observations_by_date_and_type($fieldUnitDTOs);
1803
}
1804

  

Also available in: Unified diff