Project

General

Profile

« Previous | Next » 

Revision 04d5812b

Added by Andreas Kohlbecker almost 4 years ago

ref #8134 deterministic sort order for type designations

View differences:

modules/cdm_dataportal/includes/name.inc
906 906

  
907 907
  // NameTypeDesignation ..................................
908 908
  if(!empty($name_type_designations)){
909
    uksort($name_type_designations, "compare_type_designation_status");
909
    usort($name_type_designations, "compare_type_designations_by_status");
910 910
    foreach($name_type_designations as $name_type_designation){
911 911
      if ($name_type_designation->notDesignated) {
912 912
        $out .= '<'. $element_tag .' class="' . html_class_attribute_ref($name_type_designation) . '">' .  type_designation_status_label_markup($name_type_designation)  . ': '
......
1008 1008
  } // END Specimen type designations
1009 1009

  
1010 1010
  // TextualTypeDesignation .........................
1011
  usort($textual_type_designations, 'compare_textual_type_designation');
1011 1012
  if(!empty($textual_type_designations)) {
1012 1013
    foreach ($textual_type_designations as $textual_type_designation) {
1013 1014
      $annotations_and_sources = handle_annotations_and_sources(
......
1759 1760

  
1760 1761

  
1761 1762
/**
1762
 * Compares the status of two SpecimenTypeDesignations
1763
 * Compares two SpecimenTypeDesignations
1763 1764
 *
1764 1765
 * @param object $a
1765 1766
 *   A SpecimenTypeDesignation.
......
1768 1769
 */
1769 1770
function compare_specimen_type_designation($a, $b) {
1770 1771

  
1771
  $type_status_order = type_status_order();
1772

  
1772
  $cmp_by_status = compare_type_designations_by_status($a,$b);
1773
  if($cmp_by_status !== 0){
1774
    return $cmp_by_status;
1775
  }
1773 1776

  
1774 1777
  $aQuantifier = FALSE;
1775 1778
  $bQuantifier = FALSE;
1776
  if (isset($a->typeStatus->titleCache) && isset($b->typeStatus->titleCache)) {
1777
    $aQuantifier = array_search($a->typeStatus->titleCache, $type_status_order);
1778
    $bQuantifier = array_search($b->typeStatus->titleCache, $type_status_order);
1779
  }
1780 1779
  if ($aQuantifier == $bQuantifier) {
1781 1780
    // Sort alphabetically.
1782 1781
    $a_text =  isset($a->typeSpecimen->titleCache) ? preg_replace('/[\[\]\"]/', '', $a->typeSpecimen->titleCache) : '';
1783 1782
    $b_text =  isset($b->typeSpecimen->titleCache) ? preg_replace('/[\[\]\"]/', '', $b->typeSpecimen->titleCache) : '';
1784 1783
    return strcasecmp($a_text, $b_text);
1785 1784
  }
1786
  return ($aQuantifier < $bQuantifier) ? -1 : 1;
1785
  return ($aQuantifier < $bQuantifier) ? -1 : (($aQuantifier > $bQuantifier) ? 1 : 0);
1787 1786
}
1788 1787

  
1789 1788
/**
1790
 * Compares the status of two SpecimenTypeDesignations
1789
 * Compares the status of two TypeDesignations
1790
 *
1791
 * @param object $a
1792
 *   A TypeDesignation
1793
 * @param object $b
1794
 *   TypeDesignation
1795
 */
1796
function compare_type_designations_by_status($a, $b) {
1797
  return compare_type_designation_status($a->typeStatus, $b->typeStatus);
1798
}
1799

  
1800
/**
1801
 * Compares two TypeDesignationStatusBase
1791 1802
 *
1792 1803
 * @param object $a
1793 1804
 *   A TypeDesignationStatusBase.
......
1795 1806
 *   TypeDesignationStatusBase.
1796 1807
 */
1797 1808
function compare_type_designation_status($a, $b) {
1798

  
1799 1809
  $type_status_order = type_status_order();
1800

  
1801

  
1802 1810
  $aQuantifier = FALSE;
1803 1811
  $bQuantifier = FALSE;
1804 1812
  if (isset($a->label) && isset($b->label)) {
1805 1813
    $aQuantifier = array_search($a->label, $type_status_order);
1806 1814
    $bQuantifier = array_search($b->label, $type_status_order);
1807 1815
  }
1808
  return ($aQuantifier < $bQuantifier) ? -1 : 1;
1816
  return ($aQuantifier < $bQuantifier) ? -1 : (($aQuantifier > $bQuantifier) ? 1 : 0);
1817
}
1818

  
1819
/**
1820
 * Compares the two TextualTypeDesignations
1821
 *
1822
 * @param object $a
1823
 *   A TextualTypeDesignations.
1824
 * @param object $b
1825
 *   TextualTypeDesignations.
1826
 */
1827
function compare_textual_type_designation($a, $b) {
1828

  
1829
  $cmp_by_status = compare_type_designations_by_status($a,$b);
1830
  if($cmp_by_status !== 0){
1831
    return $cmp_by_status;
1832
  }
1833

  
1834
  $aQuantifier = FALSE;
1835
  $bQuantifier = FALSE;
1836
  if ($aQuantifier == $bQuantifier) {
1837
    // Sort alphabetically.
1838
    $a_text =  isset($a->text_L10n->text) ? $a->text_L10n->text : '';
1839
    $b_text =  isset($b->text_L10n->text) ? $b->text_L10n->text : '';
1840
    return strcasecmp($a_text, $b_text);
1841
  }
1842
  return ($aQuantifier < $bQuantifier) ? -1 : (($aQuantifier > $bQuantifier) ? 1 : 0);
1809 1843
}
1810 1844

  
1811 1845

  
......
1821 1855

  
1822 1856
  $type_status_order = type_status_order();
1823 1857

  
1824

  
1825 1858
  $aQuantifier = FALSE;
1826 1859
  $bQuantifier = FALSE;
1827 1860
  if (isset($a) && isset($b)) {

Also available in: Unified diff