Project

General

Profile

Revision efbff4b3

IDefbff4b39f7f77dd90111211da4f9df6baa9061e
Parent 819ee4a9
Child 5195ddf2

Added by Andreas Kohlbecker 10 months ago

ref #7835 first version of taxonGraph search block implemented
- registration search page with tabs for filter search and taxon graph search
- changing the search page path was needed

View differences:

modules/cdm_dataportal/cdm_dataportal.module
497 497
    'access arguments' => array('access cdm content'),
498 498
    'type' => MENU_LOCAL_TASK,
499 499
  );
500

  
501 500
  $items['cdm_dataportal/search/results/taxon'] = array(
502 501
    'page callback' => 'cdm_dataportal_view_search_results_taxon',
503 502
    'access arguments' => array('access cdm content'),
504 503
    'type' => MENU_CALLBACK,
505 504
  );
506
  $items['cdm_dataportal/search/registration'] = array(
505
  /*
506
   * MENU_CALLBACK at cdm_dataportal/registration-search is needed to make the
507
   * tabs in the subordinate paths work, accessing this 'page' will cause the
508
   * MENU_DEFAULT_LOCAL_TASK being displayed
509
   */
510
  $items['cdm_dataportal/registration-search'] = array(
511
    'title' => 'Search', // will be passed through t()
507 512
    'page callback' => 'cdm_dataportal_view_search_registrations_results',
513
    'page arguments' => array("filter"),
508 514
    'access arguments' => array('access cdm content'),
509 515
    'type' => MENU_CALLBACK,
510 516
  );
517
  /*
518
   * the MENU_DEFAULT_LOCAL_TASK creates a tab for the MENU_CALLBACK
519
   * defined at a higher level of the path (cdm_dataportal/registration-search)
520
   */
521
  $items['cdm_dataportal/registration-search/filter'] = array(
522
    'title' => 'Search', // will be passed through t()
523
    'page callback' => 'cdm_dataportal_view_search_registrations_results',
524
    'page arguments' => array("filter"),
525
    'access arguments' => array('access cdm content'),
526
    'type' => MENU_DEFAULT_LOCAL_TASK,
527
  );
528
  /*
529
   * the MENU_LOCAL_TASK creates another tab
530
   */
531
  $items['cdm_dataportal/registration-search/taxongraph'] = array(
532
    'title' => 'Taxonomic search', // will be passed through t()
533
    'page callback' => 'cdm_dataportal_view_search_registrations_results',
534
    'page arguments' => array("taxongraph"),
535
    'access arguments' => array('access cdm content'),
536
    'type' => MENU_LOCAL_TASK,
537
  );
538

  
511 539
  // Optional callback arguments: page.
512 540
  $items['cdm_dataportal/registration'] = array(
513 541
    'page callback' => 'cdm_dataportal_registration_page_view',
......
841 869
    'info' => t('CDM - Registrations search filter'),
842 870
    'cache' => DRUPAL_CACHE_PER_PAGE,
843 871
    'visibility' => BLOCK_VISIBILITY_NOTLISTED,
844
    'pages' => "cdm_dataportal/search/registration\ncdm_dataportal/search/registration/*", // multiple page paths separated by "\n"!!!
872
    'pages' => "cdm_dataportal/search-registration\ncdm_dataportal/search-registration/*", // multiple page paths separated by "\n"!!!
845 873
  );
846

  
847
    return $block;
874
  $block['registrations_search_taxongraph'] =  array(
875
    'title' => 'Taxonomic registration search',
876
    'info' => t('CDM - Registrations search by taxon graph'),
877
    'cache' => DRUPAL_CACHE_PER_PAGE,
878
    'visibility' => BLOCK_VISIBILITY_NOTLISTED,
879
    'pages' => "cdm_dataportal/search-registration\ncdm_dataportal/search-registration/*", // multiple page paths separated by "\n"!!!
880
  );
881
  return $block;
848 882
}
849 883

  
850 884
/**
......
903 937
      return $block;
904 938
    case 'registrations_search_filter':
905 939
      $block['subject'] = '<none>';
906
      $block['content'] = $form = drupal_get_form('cdm_dataportal_search_registration_form'); // see cdm_dataportal_search_registration_form($form, &$form_state)
940
      $block['content'] = drupal_get_form('cdm_dataportal_search_registration_filter_form'); // see cdm_dataportal_search_registration_filter_form($form, &$form_state)
941
      return $block;
942
    case 'registrations_search_taxongraph':
943
      $block['subject'] = '<none>';
944
      $block['content'] = drupal_get_form('cdm_dataportal_search_registration_taxongraph_form'); // see cdm_dataportal_search_registration_taxongraph_form($form, &$form_state)
907 945
      return $block;
908 946
    default:
909 947
      return null;
......
2000 2038
/**
2001 2039
 * Executes the search for registrations and generates the result list..
2002 2040
 */
2003
function cdm_dataportal_view_search_registrations_results() {
2004

  
2005
  $block = block_load('cdm_dataportal', 'registrations_search_filter');
2006
  $render_array = _block_get_renderable_array(_block_render_blocks(array($block)));
2041
function cdm_dataportal_view_search_registrations_results($mode = 'filter') {
2007 2042

  
2008
  $registration_pager = cdm_dataportal_search_registrations_execute();
2043
  switch($mode ){
2044
    case 'taxongraph':
2045
      $block = block_load('cdm_dataportal', 'registrations_search_taxongraph');
2046
      $registration_pager = cdm_dataportal_search_registrations_taxongraph_execute();
2047
      break;
2048
    case 'filter':
2049
    default:
2050
      $block = block_load('cdm_dataportal', 'registrations_search_filter');
2051
      $registration_pager = cdm_dataportal_search_registrations_filter_execute();
2052
  }
2053
  $block->title = null;
2009 2054

  
2010 2055
  drupal_set_title(t('Search registrations'), PASS_THROUGH);
2011 2056

  
2057
  $render_array = _block_get_renderable_array(_block_render_blocks(array($block)));
2012 2058
  $registrations_pager_array = compose_registrations_search_results($registration_pager);
2013

  
2014 2059
  $render_array = array_merge($render_array, $registrations_pager_array);
2015 2060

  
2016 2061
  return $render_array;
modules/cdm_dataportal/cdm_dataportal.search.php
5 5
 */
6 6

  
7 7
define("SESSION_KEY_SEARCH_REGISTRATION_FILTER", "SESSION_KEY_SEARCH_REGISTRATION_FILTER");
8
define('SESSION_KEY_SEARCH_TAXONGRAPH_FOR_REGISTRATION_FILTER', 'SESSION_KEY_SEARCH_TAXONGRAPH_FOR_REGISTRATION_FILTER');
8 9

  
9 10
/**
10 11
 * Returns a Drupal path to a search form for a CDM webservice.
......
670 671

  
671 672

  
672 673
/**
673
 * Sends a request to search for registrations to the cdm server.
674
 * Sends a request for a registrations filter search to the cdm server.
674 675
 */
675
function cdm_dataportal_search_registrations_execute()
676
function cdm_dataportal_search_registrations_filter_execute()
676 677
{
677 678

  
678 679
  static $query_param_map = array(
......
681 682
    'type_designation_status' => 'typeDesignationStatusUuids',
682 683
  );
683 684

  
684
  // Read the query parameters from $_REQUEST and add additional query
685
  // parameters if necessary.
686
  $request_params = array();
687

  
688
  $request = remove_drupal_form_params($_REQUEST);
689

  
690
  if(count($request) > 0){
691
    $_SESSION['cdm'][SESSION_KEY_SEARCH_REGISTRATION_FILTER] = $request;
692
    foreach ($query_param_map as $filter_key => $query_param){
693
      if (isset($request[$filter_key])) {
694
        $request_params[$query_param] = $request[$filter_key];
695
      }
696
    }
697
    if(isset($request['pager']['pageNumber'])){
698
      $request_params['pageNumber'] = $request['pager']['pageNumber'];
699
    }
700
  }
701

  
702
  if(count($request_params) == 0 && isset($_SESSION['cdm'][SESSION_KEY_SEARCH_REGISTRATION_FILTER])){
703
    foreach ($query_param_map as $filter_key => $query_param){
704
      if (isset($_SESSION['cdm'][SESSION_KEY_SEARCH_REGISTRATION_FILTER][$filter_key])) {
705
        $request_params[$query_param] = $_SESSION['cdm'][SESSION_KEY_SEARCH_REGISTRATION_FILTER][$filter_key];
706
      }
707
    }
708
    if(isset($_SESSION['cdm'][SESSION_KEY_SEARCH_REGISTRATION_FILTER]['pager']['pageNumber'])){
709
      $request_params['pageNumber'] = $_SESSION['cdm'][SESSION_KEY_SEARCH_REGISTRATION_FILTER]['pager']['pageNumber'];
710
    }
711
  }
685
  $session_key = SESSION_KEY_SEARCH_REGISTRATION_FILTER;
686
  $request_params = cdm_dataportal_search_request_params($session_key, $query_param_map);
712 687

  
713 688
  // cleanup
714 689
  if(isset($request_params['typeDesignationStatusUuids'])){
......
732 707
}
733 708

  
734 709
/**
710
 * Sends a request for a registrations taxongraph search to the cdm server.
711
 */
712
function cdm_dataportal_search_registrations_taxongraph_execute()
713
{
714

  
715
  static $query_param_map = array(
716
    'taxon_name'=> 'taxonNameFilter'
717
  );
718

  
719
  $session_key = SESSION_KEY_SEARCH_TAXONGRAPH_FOR_REGISTRATION_FILTER;
720
  $request_params = cdm_dataportal_search_request_params($session_key, $query_param_map);
721

  
722
  // cleanup
723
  if(isset($request_params['taxonNameFilter'])){
724
    // trim and remove empty taxon name query strings
725
    $request_params['taxonNameFilter'] = trim($request_params['taxonNameFilter']);
726
    if(!$request_params['taxonNameFilter']){
727
      unset($request_params['taxonNameFilter']);
728
    }
729
  }
730

  
731
  $registration_pager = cdm_ws_get('registrationDTO/findInTaxonGraph', NULL, queryString($request_params));
732

  
733
  return $registration_pager;
734
}
735

  
736
/**
737
 * @param $session_key
738
 * @param $query_param_map
739
 * @return array
740
 */
741
function cdm_dataportal_search_request_params($session_key, $query_param_map)
742
{
743
  // Read the query parameters from $_REQUEST and add additional query
744
  // parameters if necessary.
745
  $request_params = array();
746

  
747
  $request = remove_drupal_form_params($_REQUEST);
748

  
749
  if (count($request) > 0) {
750
    $_SESSION['cdm'][$session_key] = $request;
751
    foreach ($query_param_map as $filter_key => $query_param) {
752
      if (isset($request[$filter_key])) {
753
        $request_params[$query_param] = $request[$filter_key];
754
      }
755
    }
756
    if (isset($request['pager']['pageNumber'])) {
757
      $request_params['pageNumber'] = $request['pager']['pageNumber'];
758
    }
759
  }
760

  
761
  if (count($request_params) == 0 && isset($_SESSION['cdm'][$session_key])) {
762
    foreach ($query_param_map as $filter_key => $query_param) {
763
      if (isset($_SESSION['cdm'][$session_key][$filter_key])) {
764
        $request_params[$query_param] = $_SESSION['cdm'][$session_key][$filter_key];
765
      }
766
    }
767
    if (isset($_SESSION['cdm'][$session_key]['pager']['pageNumber'])) {
768
      $request_params['pageNumber'] = $_SESSION['cdm'][$session_key]['pager']['pageNumber'];
769
    }
770
  }
771
  return $request_params;
772
}
773

  
774
/**
735 775
 * Transforms the termDTO tree into options array.
736 776
 *
737 777
 *   TermDto:
......
779 819
}
780 820

  
781 821

  
782
function cdm_dataportal_search_registration_form($form, &$form_state) {
822
function cdm_dataportal_search_registration_filter_form($form, &$form_state) {
783 823

  
784 824
  static $filter_presets_empty = array(
785 825
    'identifier'=> null,
......
789 829

  
790 830
  _add_font_awesome_font();
791 831

  
832
  if($_REQUEST['q'] == 'cdm_dataportal/registration-search/filter' || $_REQUEST['q'] == 'cdm_dataportal/registration-search'){
833
    // read the $request_params only if it was send from this form
834
    $request_params = remove_drupal_form_params($_REQUEST);
835
  } else {
836
    $request_params = array();
837
  }
792 838
  $filter_presets = (isset($_SESSION['cdm'][SESSION_KEY_SEARCH_REGISTRATION_FILTER]) ? $_SESSION['cdm'][SESSION_KEY_SEARCH_REGISTRATION_FILTER] : array());
793
  $filter_presets = array_merge($filter_presets_empty, $filter_presets, remove_drupal_form_params($_REQUEST));
794
  $form['#action'] =  url('/cdm_dataportal/search/registration/');
839
  $filter_presets = array_merge($filter_presets_empty, $filter_presets, $request_params);
840
  $form['#action'] =  url('/cdm_dataportal/registration-search/filter');
795 841
  $form['#method'] = 'get';
796 842
  $form['#attributes'] = array('class' => array('search-filter'));
797 843
  $form['identifier'] = array(
......
828 874
}
829 875

  
830 876

  
877
function cdm_dataportal_search_registration_taxongraph_form($form, &$form_state) {
878

  
879
  static $filter_presets_empty = array(
880
    'taxon_name'=> null
881
  );
882

  
883
  _add_font_awesome_font();
884

  
885
  if($_REQUEST['q']  == 'cdm_dataportal/registration-search/taxongraph'){
886
    // read the $request_params only if it was send from this form
887
    $request_params = remove_drupal_form_params($_REQUEST);
888
  } else {
889
    $request_params = array();
890
  }
891
  $filter_presets = (isset($_SESSION['cdm'][SESSION_KEY_SEARCH_TAXONGRAPH_FOR_REGISTRATION_FILTER]) ? $_SESSION['cdm'][SESSION_KEY_SEARCH_TAXONGRAPH_FOR_REGISTRATION_FILTER] : array());
892
  $filter_presets = array_merge($filter_presets_empty, $filter_presets, $request_params);
893

  
894
  $form['#action'] =  url('/cdm_dataportal/registration-search/taxongraph');
895
  $form['#method'] = 'get';
896
  $form['#attributes'] = array('class' => array('search-filter'));
897
  $form['taxon_name'] = array(
898
    '#type' => 'textfield',
899
    '#title' => t('Scientific name'),
900
    '#default_value' => $filter_presets['taxon_name'],
901
    '#size' => 20,
902
    '#maxlength' => 128
903
  );
904

  
905
  $form['submit'] = array(
906
    '#type' => 'submit',
907
    '#attributes' => array('class' => array('fa-icon'), 'title' => t('Search')),
908
    '#value' => decode_entities('&#xf002;'), // fontawesome search icon
909
//    '#prefix' => "<div class=\"form-item\"><label>&nbsp</label>",
910
//    '#suffix' => "</div>"
911

  
912
  );
913
  return $form;
914
}
915

  
831 916
/**
832 917
 * Compose the result set of a registration search from a pager object
833 918
 *
......
859 944
        );
860 945
      ;
861 946
    }
947

  
862 948
    $render_array['items'] = $items_render_array;
863 949
    $render_array['pager'] =  markup_to_render_array(theme('cdm_pager', array(
864 950
          'pager' => $registration_pager,
865
          'path' => "cdm_dataportal/search/registration",
951
          'path' => $_REQUEST['q'], // stay on same page
866 952
          'parameters' => $_REQUEST,
867 953
        )));
868 954

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)