Project

General

Profile

« Previous | Next » 

Revision e90899ac

Added by Andreas Kohlbecker about 8 years ago

implementing separator between nomstatus and sec reference

View differences:

modules/cdm_dataportal/cdm_dataportal.module
1873 1873
  }
1874 1874
}
1875 1875

  
1876
/**
1877
 * Preprocess the taggedTitle arrays.
1878
 *
1879
 * Step 1: Turns 'newly' introduces tag types ("hybridSign")
1880
 * into tag type "name"
1881
 *
1882
 * Step 2: Two taggedTexts which have the same type and which have
1883
 * a separator between them are merged together.
1884
 *
1885
 * @param array $taggedTextList
1886
 *    An array of TaggedText objects
1887
 */
1888
function normalize_tagged_title(&$taggedTextList) {
1889

  
1890
  if (is_array($taggedTextList)) {
1891 1876

  
1892
    // First pass: rename.
1893
    for ($i = 0; $i < count($taggedTextList); $i++) {
1894

  
1895
      if ($taggedTextList[$i]->type == "hybridSign") {
1896
        $taggedTextList[$i]->type = "name";
1897
      }
1898
    }
1899

  
1900
    // Second pass: resolve separators.
1901
    $taggedNameListNew = array();
1902
    for ($i = 0; $i < count($taggedTextList); $i++) {
1903

  
1904
      if ($i + 1 < count($taggedTextList) && $taggedTextList[$i + 1]->type == "separator") {
1905
        if ($taggedTextList[$i]->type == $taggedTextList[$i + 2]->type) {
1906
          $taggedName = clone $taggedTextList[$i];
1907
          $taggedName->text = $taggedName->text . $taggedTextList[$i + 1]->text . $taggedTextList[$i + 2]->text;
1908
          $taggedNameListNew[] = $taggedName;
1909
          ++$i;
1910
          ++$i;
1911
        }
1912
      }
1913
      else {
1914
        $taggedNameListNew[] = $taggedTextList[$i];
1915
      }
1916
    }
1917
    $taggedTextList = $taggedNameListNew;
1918
  }
1919
}
1920

  
1921
function split_secref_from_tagged_title(&$taggedTextList) {
1922

  
1923
  $secref_tt = array();
1924
  if (is_array($taggedTextList)) {
1925
    for ($i = 0; $i < count($taggedTextList) - 1; $i++) {
1926
      if ($taggedTextList[$i + 1]->type == "secReference" && $taggedTextList[$i]->type == "separator"){
1927
        $secref_tt[0] = $taggedTextList[$i];
1928
        $secref_tt[1] = $taggedTextList[$i + 1];
1929
        unset($taggedTextList[$i]);
1930
        unset($taggedTextList[$i + 1]);
1931
      }
1932
    }
1933
  }
1934
  return $secref_tt;
1935
}
1936 1877
/**
1937 1878
 * Creates a short taxonname.
1938 1879
 *
1939
 * The short name is created by using the taggename field of
1880
 * The short name is created by using the taggedTitle field of
1940 1881
 * NameSTO or NameTO instances.
1941
 * If the taggename if empty the fullname will be returned.
1882
 * If the taggedTitle if empty the fullname will be returned.
1942 1883
 *
1943 1884
 * @param unknown_type $name
1944 1885
 *   Name or TreeNode.
......
1948 1889
function cdm_dataportal_shortname_of($name) {
1949 1890
  $nameStr = '';
1950 1891

  
1951
  normalize_tagged_title($name->taggedTitle);
1892
  normalize_tagged_text($name->taggedTitle);
1952 1893

  
1953 1894
  // Get all tagged text tokens of the scientific name.
1954 1895
  foreach ($name->taggedTitle as $tagtxt) {

Also available in: Unified diff