Project

General

Profile

Revision 2f65af04

ID2f65af049f9784cd0b0de8096df842491c590b31
Parent 7efd13a9
Child 57dabcba

Added by Andreas Kohlbecker over 1 year ago

fix #8304 redirect from name to taxon page depending on drupal path argument, with test

View differences:

modules/cdm_dataportal/cdm_dataportal.module
586 586
  $items['cdm_dataportal/name/%'] = array(
587 587
    // 'page callback' => 'cdm_dataportal_view_name',
588 588
    'page callback' => 'cdm_dataportal_name_page_view',
589
    'page arguments' => array(2, 3, 4),
589
    'page arguments' => array(2, 3, 4, 5),
590 590
    'access arguments' => array('access cdm content'),
591 591
    'type' => MENU_CALLBACK,
592 592
  );
......
1715 1715
 *   The uuid of the CDM TaxonName to show a name page for
1716 1716
 * @param string $taxon_to_hide_uuid
1717 1717
 *   A taxon which should not be displayed in the taxon list
1718
 * @param $redirect_to_taxon
1719
 *   Automatically redirect to the related taxon if there is only one
1720
 *   accepted taxon for this name.
1718 1721
 * @param string $highlite_synonym_uuid
1719 1722
 *   Optinal parameter wich takes another taxon uuid, if given the
1720 1723
 *   target taxon pages will show the syonymy tab where the taxon
......
1724 1727
 * @return mixed
1725 1728
 *   The formatted name page as node.
1726 1729
 */
1727
function cdm_dataportal_name_page_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid = NULL) {
1730
function cdm_dataportal_name_page_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid = NULL, $redirect_to_taxon = '') {
1728 1731

  
1729 1732
  cdm_check_valid_portal_page();
1730 1733

  
1731
  $taxonname_page = cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid);
1734
  // redirect_to_taxon is a path element of the name page path, see path_to_name()
1735
  $do_redirect_to_taxon = $redirect_to_taxon == 'redirect_to_taxon';
1736
  $taxonname_page = cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $do_redirect_to_taxon, $synonym_uuid);
1732 1737
  if (!empty($taxonname_page)) {
1733 1738
    return cdm_node_show(NODETYPE_NAME, $taxon_name_uuid, $taxonname_page->title, $taxonname_page->content);
1734 1739
  }
......
1755 1760
 *   The uuid of the CDM TaxonName to show a name page for
1756 1761
 * @param string $taxon_to_hide_uuid
1757 1762
 *   A taxon which should not be displayed in the taxon list
1763
 * @param $redirect_to_taxon
1764
 *   Automatically redirect to the related taxon if there is only one
1765
 *   accepted taxon for this name.
1758 1766
 * @param string $highlite_synonym_uuid
1759
 *   Optinal parameter wich takes another taxon uuid, if given the
1760
 *   target taxon pages will show the syonymy tab where the taxon
1761
 *   refenrenced by the $highlite_synonym_uuid will be highlighted
1767
 *   Optional parameter which takes another taxon uuid, if given the
1768
 *   target taxon pages will show the synonymy tab where the taxon
1769
 *   referenced by the $highlite_synonym_uuid will be highlighted
1762 1770
 *   in case it is found on this page.
1763 1771
 *
1764
 * @return object
1772
 * @return object|boolean
1765 1773
 *   An object with two fields:
1766 1774
 *     - title: the page title
1767 1775
 *     - content: the page content
1776
 *   or FALSE
1777
 *
1768 1778
 */
1769
function cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $highlite_synonym_uuid = NULL) {
1779
function cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $redirect_to_taxon, $highlite_synonym_uuid = NULL) {
1770 1780
  // Getting the full taxonname object from the server.
1771 1781
  $taxon_name = cdm_ws_get(CDM_WS_PORTAL_NAME, array($taxon_name_uuid));
1772 1782
  if (!$taxon_name) {
......
1792 1802
    }
1793 1803
  }
1794 1804
  // Show the taxa list or go to the singular taxon.
1795
  if (sizeof($taxon_pager->records) == 1) {// Single taxon case.
1805
  if (sizeof($taxon_pager->records) == 1 && $redirect_to_taxon) {
1806
    // redirect to the taxon if there is only one.
1796 1807
    $singleTaxon = array_pop($taxon_pager->records);
1797 1808
    if ($singleTaxon->class != "Taxon") {
1798 1809
      // It is a Synonym -> look for the accepted.
......
1814 1825
      }
1815 1826
    }
1816 1827
  }
1817
  else {// More than one taxa case.
1828
  else {
1829
    // display the name page content
1818 1830
    $taxon_name_page = new stdClass();
1819 1831
    $taxon_name_page->title = theme('cdm_name_page_title', array('taxon_name' => $taxon_name));
1832
    $content = array();
1833

  
1834
    // name relationships
1835
    // TODO ....
1836
    // related taxa
1820 1837
    if ($taxon_pager->records) {
1821
      $taxon_name_page->content = compose_list_of_taxa($taxon_pager->records);
1838
      $content['related_taxa'] = compose_list_of_taxa($taxon_pager->records);
1822 1839
    }
1823 1840
    else {
1824
      $taxon_name_page->content = 'This name is not assigned to a taxon.';
1841
      $content['related_taxa'] = markup_to_render_array('This name is not assigned to a taxon.');
1825 1842
    }
1843
    $taxon_name_page->content = $content;
1826 1844
    return $taxon_name_page;
1827 1845
  }
1828 1846
}
......
2215 2233
 *   target taxon pages will show the synonymy tab where the taxon
2216 2234
 *   referenced by the $highlite_synonym_uuid will be highlighted
2217 2235
 *   in case it is found on this page.
2236
 * @param $redirect_to_taxon
2237
 *   If true, the name page will redirect to the related taxon if there is a single one
2238
 *   for this name only.
2218 2239
 *
2219 2240
 * @return string
2220 2241
 *  URI path element as string
2221 2242
 */
2222
function path_to_name($name_uuid, $taxon_to_hide_uuid = NULL, $highlited_synonym_uuid  = NULL) {
2243
function path_to_name($name_uuid, $taxon_to_hide_uuid = NULL, $highlited_synonym_uuid  = NULL, $redirect_to_taxon = false) {
2223 2244
  $res = FALSE;
2224 2245
  if ($name_uuid) {
2225
    $res = 'cdm_dataportal/name/' . $name_uuid;
2226
  }
2227
  if($taxon_to_hide_uuid){
2228
    $res .= '/' . $taxon_to_hide_uuid;
2229
    if($highlited_synonym_uuid){
2230
      $res .= '/' . $highlited_synonym_uuid;
2231
    }
2246
    $res = 'cdm_dataportal/name/' . $name_uuid .
2247
    '/' . (is_uuid($taxon_to_hide_uuid) ? $taxon_to_hide_uuid : "null") .
2248
    '/' . (is_uuid($highlited_synonym_uuid) ? $highlited_synonym_uuid : "null") .
2249
    '/' . ($redirect_to_taxon ? "redirect_to_taxon" : "");
2232 2250
  }
2251

  
2233 2252
  return $res;
2234 2253
}
2235 2254

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)