Revision a6ae799b
Added by Andreas Kohlbecker almost 6 years ago
modules/cdm_dataportal/cdm_dataportal.search.php | ||
---|---|---|
4 | 4 |
* Search related functions. |
5 | 5 |
*/ |
6 | 6 |
|
7 |
define("SESSION_KEY_SEARCH_REGISTRATION_FILTER", "SESSION_KEY_SEARCH_REGISTRATION_FILTER"); |
|
8 |
|
|
7 | 9 |
/** |
8 | 10 |
* Returns a Drupal path to a search form for a CDM webservice. |
9 | 11 |
* |
... | ... | |
48 | 50 |
* The description text for the query field |
49 | 51 |
* @param string $process |
50 | 52 |
* The value for #process, if NULL (default), 'cdm_dataportal_search_process' |
51 |
* is used. |
|
53 |
* is used. - TODO not used, remove?
|
|
52 | 54 |
* |
53 | 55 |
* @return array |
54 | 56 |
* The prepared form array. |
55 | 57 |
*/ |
56 | 58 |
function cdm_dataportal_search_form_prepare($action_path, $search_webservice, $query_field_default_value, $query_field_description, $process = NULL) { |
57 | 59 |
|
58 |
if ($process == NULL) { |
|
59 |
$process = 'cdm_dataportal_search_process'; |
|
60 |
} |
|
60 |
//if ($process == NULL) {
|
|
61 |
// $process = 'cdm_dataportal_search_process';
|
|
62 |
//}
|
|
61 | 63 |
|
62 | 64 |
$form['#method'] = 'get'; |
63 | 65 |
// |
... | ... | |
189 | 191 |
$search_service_endpoint, |
190 | 192 |
$query_field_default_value, |
191 | 193 |
t('Enter the name or part of a name you wish to search for. |
192 |
The asterisk character * can be used as wildcard, but must not be used as first character.'), |
|
193 |
NULL |
|
194 |
The asterisk character * can be used as wildcard, but must not be used as first character.') |
|
194 | 195 |
); |
195 | 196 |
|
196 | 197 |
if (!$advanced_form) { |
... | ... | |
438 | 439 |
) |
439 | 440 |
), |
440 | 441 |
) |
441 |
), |
|
442 |
NULL |
|
442 |
) |
|
443 | 443 |
); |
444 | 444 |
|
445 | 445 |
$form['search']['tree'] = array( |
... | ... | |
618 | 618 |
|
619 | 619 |
/** |
620 | 620 |
* Removes Drupal internal form elements from query. |
621 |
* FIXME remove since unused? |
|
621 | 622 |
*/ |
622 | 623 |
function cdm_dataportal_search_process($form, &$form_state) { |
623 | 624 |
unset($form['form_id']); |
... | ... | |
625 | 626 |
return $form; |
626 | 627 |
} |
627 | 628 |
|
629 |
/** |
|
630 |
* Removed the drupal internal form parameters 'form_id', 'form_token', 'form_build_id' from the request array. |
|
631 |
* |
|
632 |
* @param $request array |
|
633 |
* Pass $_REQUEST as paramter |
|
634 |
* @return array |
|
635 |
* The $request array without drupal internal form parameters |
|
636 |
*/ |
|
637 |
function remove_drupal_form_params($request) { |
|
638 |
|
|
639 |
static $exclude_keys = array('form_id', 'form_token', 'form_build_id'); |
|
640 |
$request_sanitized = array(); |
|
641 |
foreach ($request as $key => $value) { |
|
642 |
if(!array_search($key, $exclude_keys)){ |
|
643 |
$request_sanitized[$key] = $value; |
|
644 |
} |
|
645 |
} |
|
646 |
|
|
647 |
return $request_sanitized; |
|
648 |
} |
|
649 |
|
|
628 | 650 |
/** |
629 | 651 |
* Sends a search request to the cdm server. |
630 | 652 |
* |
... | ... | |
663 | 685 |
return $taxon_pager; |
664 | 686 |
} |
665 | 687 |
|
688 |
|
|
689 |
/** |
|
690 |
* Sends a request to search for registrations to the cdm server. |
|
691 |
*/ |
|
692 |
function cdm_dataportal_search_registrations_execute() |
|
693 |
{ |
|
694 |
|
|
695 |
static $query_param_map = array( |
|
696 |
'identifier' => 'identifierFilterPattern', |
|
697 |
'taxon_name'=> 'taxonNameFilterPattern', |
|
698 |
'type_designation_status' => 'typeDesignationStatusUuids', |
|
699 |
); |
|
700 |
|
|
701 |
// Read the query parameters from $_REQUEST and add additional query |
|
702 |
// parameters if necessary. |
|
703 |
$request_params = array(); |
|
704 |
|
|
705 |
$request = remove_drupal_form_params($_REQUEST); |
|
706 |
|
|
707 |
if(count($request) > 0){ |
|
708 |
$_SESSION['cdm'][SESSION_KEY_SEARCH_REGISTRATION_FILTER] = $request; |
|
709 |
foreach ($query_param_map as $filter_key => $query_param){ |
|
710 |
if (isset($request[$filter_key])) { |
|
711 |
$request_params[$query_param] = $request[$filter_key]; |
|
712 |
} |
|
713 |
} |
|
714 |
if(isset($request['pager']['pageNumber'])){ |
|
715 |
$request_params['pageNumber'] = $request['pager']['pageNumber']; |
|
716 |
} |
|
717 |
} |
|
718 |
|
|
719 |
if(count($request_params) == 0 && isset($_SESSION['cdm'][SESSION_KEY_SEARCH_REGISTRATION_FILTER])){ |
|
720 |
foreach ($query_param_map as $filter_key => $query_param){ |
|
721 |
if (isset($_SESSION['cdm'][SESSION_KEY_SEARCH_REGISTRATION_FILTER][$filter_key])) { |
|
722 |
$request_params[$query_param] = $_SESSION['cdm'][SESSION_KEY_SEARCH_REGISTRATION_FILTER][$filter_key]; |
|
723 |
} |
|
724 |
} |
|
725 |
if(isset($_SESSION['cdm'][SESSION_KEY_SEARCH_REGISTRATION_FILTER]['pager']['pageNumber'])){ |
|
726 |
$request_params['pageNumber'] = $_SESSION['cdm'][SESSION_KEY_SEARCH_REGISTRATION_FILTER]['pager']['pageNumber']; |
|
727 |
} |
|
728 |
} |
|
729 |
|
|
730 |
// cleanup |
|
731 |
if(isset($request_params['typeDesignationStatusUuids'])){ |
|
732 |
if(!$request_params['typeDesignationStatusUuids'] |
|
733 |
|| $request_params['typeDesignationStatusUuids'] == "0" |
|
734 |
|| (isset($request_params['typeDesignationStatusUuids'][0]) && !$request_params['typeDesignationStatusUuids'][0])){ |
|
735 |
unset($request_params['typeDesignationStatusUuids']); |
|
736 |
} |
|
737 |
|
|
738 |
} |
|
739 |
|
|
740 |
$registration_pager = cdm_ws_get('registrationDTO/find', NULL, queryString($request_params)); |
|
741 |
|
|
742 |
return $registration_pager; |
|
743 |
} |
|
744 |
|
|
666 | 745 |
/** |
667 | 746 |
* Transforms the termDTO tree into options array. |
668 | 747 |
* |
... | ... | |
709 | 788 |
|
710 | 789 |
return $options; |
711 | 790 |
} |
791 |
|
|
792 |
|
|
793 |
function cdm_dataportal_search_registration_form($form, &$form_state) { |
|
794 |
|
|
795 |
$filter_presets = (isset($_SESSION['cdm'][SESSION_KEY_SEARCH_REGISTRATION_FILTER]) ? $_SESSION['cdm'][SESSION_KEY_SEARCH_REGISTRATION_FILTER] : array()); |
|
796 |
$filter_presets = array_merge($filter_presets, remove_drupal_form_params($_REQUEST)); |
|
797 |
|
|
798 |
$form['#method'] = 'get'; |
|
799 |
$form['#attributes'] = array('class' => array('search-filter')); |
|
800 |
$form['identifier'] = array( |
|
801 |
'#type' => 'textfield', |
|
802 |
'#title' => t('Identifier'), |
|
803 |
'#default_value' => $filter_presets['identifier'], |
|
804 |
'#size' => 20, |
|
805 |
'#maxlength' => 128 |
|
806 |
); |
|
807 |
$form['taxon_name'] = array( |
|
808 |
'#type' => 'textfield', |
|
809 |
'#title' => t('Scientific name'), |
|
810 |
'#default_value' => $filter_presets['taxon_name'], |
|
811 |
'#size' => 20, |
|
812 |
'#maxlength' => 128 |
|
813 |
); |
|
814 |
$form['type_designation_status'] = array( |
|
815 |
'#type' => 'select', |
|
816 |
'#title' => t('Type designation status'), |
|
817 |
'#multiple' => true, |
|
818 |
'#options' => cdm_terms_by_type_as_option('TypeDesignationStatusBase', null, null, TRUE), |
|
819 |
'#default_value' => $filter_presets['type_designation_status'] |
|
820 |
); |
|
821 |
|
|
822 |
$form['submit'] = array( |
|
823 |
'#type' => 'submit', |
|
824 |
'#attributes' => array('class' => array('fa-icon'), 'title' => t('Search')), |
|
825 |
'#value' => decode_entities(''), // fontawesome search icon |
|
826 |
'#prefix' => "<div class=\"form-item\"><label> </label>", |
|
827 |
'#suffix' => "</div>" |
|
828 |
|
|
829 |
); |
|
830 |
return $form; |
|
831 |
} |
|
832 |
|
|
833 |
|
|
834 |
/** |
|
835 |
* Compose the result set of a registration search from a pager object |
|
836 |
* |
|
837 |
* @param $registration_pager |
|
838 |
* The pager containing registration objects |
|
839 |
* |
|
840 |
* @return |
|
841 |
* A drupal render array. |
|
842 |
* |
|
843 |
* @ingroup compose |
|
844 |
* |
|
845 |
* TODO compose function into search.inc ? |
|
846 |
*/ |
|
847 |
function compose_registrations_pager($registration_pager){ |
|
848 |
|
|
849 |
$render_array = array(); |
|
850 |
$render_array['pre'] = markup_to_render_array("<div class=\"pager_records\">"); |
|
851 |
if($registration_pager != null){ |
|
852 |
$items_render_array = array(); |
|
853 |
foreach($registration_pager->records as $registration) { |
|
854 |
$summary_markup = cdm_tagged_text_to_markup($registration->summaryTaggedText); |
|
855 |
$items_render_array[] = markup_to_render_array( |
|
856 |
"<div class=\"item\"><div class=\"" . html_class_attribute_ref(new TypedEntityReference("Registration", $registration->uuid)) . "\">" |
|
857 |
. "<div class=\"identifier\">" |
|
858 |
. l($registration->identifier, $registration->identifier, array('absolute' => true, 'attributes' => array('class' => array('identifier')))) |
|
859 |
. "</div>" |
|
860 |
. $summary_markup |
|
861 |
. "</div></div>" |
|
862 |
); |
|
863 |
; |
|
864 |
} |
|
865 |
$render_array['items'] = $items_render_array; |
|
866 |
$render_array['pager'] = markup_to_render_array(theme('cdm_pager', array( |
|
867 |
'pager' => $registration_pager, |
|
868 |
'path' => "cdm_dataportal/search/registration", |
|
869 |
'parameters' => $_REQUEST, |
|
870 |
))); |
|
871 |
|
|
872 |
} else { |
|
873 |
$render_array['items'] = markup_to_render_array("No results! Please use the search filter."); |
|
874 |
} |
|
875 |
$render_array['post'] = markup_to_render_array("</div>"); |
|
876 |
|
|
877 |
return $render_array; |
|
878 |
|
|
879 |
} |
Also available in: Unified diff
fix #7494 registration search form block and result page