These function dynamically generate an url string depending on the setted parameters.
I would love to hear suggestions on how to simplify all these nested conditions :
function _amu_hal_generate_url($ config) { $ url = variable_get('amu_hal_url_ws') . 'search/'; if ($ config->retrieval_method_select == 'by_user_fields') { if (arg(0) == 'user' && arg(2) == '') { $ url .= '?'; $ user = user_load(arg(1)); if ($ user->field_selected_publis) { $ url = substr($ url, 0, -1); $ config->docids_publis = $ user->field_selected_publis["und"][0]["value"]; $ config->retrieval_method_select = 'by_docids'; } elseif ($ user->field_identifiant_hal) { $ url .= 'fq=authIdHal_i:' . $ user->field_identifiant_hal["und"][0]["value"] . ''; } elseif ($ user->field_auth_hal) { foreach ($ user->field_auth_hal["und"] as $ user_id) { $ tabFormesAuteur[] = $ user_id["value"]; } array_walk_recursive($ tabFormesAuteur, function (&$ value) { $ value = ucwords(strtolower($ value)); }); $ authLastNameFirstName_s = '("'; $ authLastNameFirstName_s .= implode('" OR "', $ tabFormesAuteur); $ authLastNameFirstName_s .= '")'; if ($ config->halId_s != '') { $ url .= $ config->halId_s . '&fq='; } else { ($ config->hal_struct_id != '') ? $ url .= 'fq=structId_i:' . $ config->hal_struct_id : $ url .= ''; } $ url .= '&fq=authLastNameFirstName_s:' . urlencode($ authLastNameFirstName_s) . ''; } else { $ authLastNameFirstName_s = '("' . ucwords(strtolower($ user->name)) . '")'; if ($ config->halId_s != '') { $ url .= $ config->halId_s . '?'; } else { ($ config->hal_struct_id != '') ? $ url .= '?fq=structId_i:' . $ config->hal_struct_id : $ url .= ''; } $ url .= '&fq=authLastNameFirstName_s:' . urlencode($ authLastNameFirstName_s) . ''; } } } if ($ config->retrieval_method_select == 'by_docids') { // explode each lines $ tabdocids = preg_split("/\r\n|\r|\n/", $ config->docids_publis); $ end = end($ tabdocids); $ docidValues = '('; foreach ($ tabdocids as $ docid) { if ($ end != $ docid) { $ docidValues .= $ docid . ' OR '; } else { $ docidValues .= $ docid . ')'; } } $ url .= '?fq=docid:' . urlencode($ docidValues); $ url .= '&rows=2000'; } if ($ config->retrieval_method_select == 'by_multi_hal_attributes') { // soit par collection soit structure if ($ config->halId_s != '') { $ url .= $ config->halId_s . '?'; } else { ($ config->hal_struct_id != '') ? $ url .= '?fq=structId_i:' . $ config->hal_struct_id : $ url .= ''; } if ($ config->docType_s != '') { $ tabdocType_s = preg_split("/\r\n|\r|\n/", $ config->docType_s); $ end = end($ tabdocType_s); $ docType_sValues = '('; foreach ($ tabdocType_s as $ doctype) { if ($ end != $ doctype) { $ docType_sValues .= $ doctype . ' OR '; } else { $ docType_sValues .= $ doctype . ')'; } } $ url .= '&q=docType_s:' . urlencode($ docType_sValues); } $ url .= '&rows=' . $ config->hal_last_pub_rows; } if ($ config->retrieval_method_select == 'by_single_hal_id') { $ url .= '?fq=halId_s:' . $ config->hal_id; } $ url .= '&fl=' . $ config->displayed_fields; if ($ config->year) { $ url .= '&fq=producedDateY_i:' . $ config->year; } $ url .= '&sort=producedDate_tdate+desc'; return $ url; }