A dynamic method of generating URLs with nested conditions
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
0
down vote
favorite
This function dynamically generates a URL string depending on the set 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') \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
$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;
php url drupal
add a comment |Â
up vote
0
down vote
favorite
This function dynamically generates a URL string depending on the set 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') \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
$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;
php url drupal
I changed the title so that it describes what the code does per site goals: "State what your code does in your title, not your main concerns about it.". Feel free to edit and give it a different title if there is something more appropriate.
â Sam Onela
Jan 12 at 17:04
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This function dynamically generates a URL string depending on the set 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') \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
$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;
php url drupal
This function dynamically generates a URL string depending on the set 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') \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
$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;
php url drupal
edited Jan 13 at 0:43
Jamalâ¦
30.1k11114225
30.1k11114225
asked Jan 12 at 13:14
Matoeil
1033
1033
I changed the title so that it describes what the code does per site goals: "State what your code does in your title, not your main concerns about it.". Feel free to edit and give it a different title if there is something more appropriate.
â Sam Onela
Jan 12 at 17:04
add a comment |Â
I changed the title so that it describes what the code does per site goals: "State what your code does in your title, not your main concerns about it.". Feel free to edit and give it a different title if there is something more appropriate.
â Sam Onela
Jan 12 at 17:04
I changed the title so that it describes what the code does per site goals: "State what your code does in your title, not your main concerns about it.". Feel free to edit and give it a different title if there is something more appropriate.
â Sam Onela
Jan 12 at 17:04
I changed the title so that it describes what the code does per site goals: "State what your code does in your title, not your main concerns about it.". Feel free to edit and give it a different title if there is something more appropriate.
â Sam Onela
Jan 12 at 17:04
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Â
draft saved
draft discarded
Â
draft saved
draft discarded
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f184954%2fa-dynamic-method-of-generating-urls-with-nested-conditions%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
I changed the title so that it describes what the code does per site goals: "State what your code does in your title, not your main concerns about it.". Feel free to edit and give it a different title if there is something more appropriate.
â Sam Onela
Jan 12 at 17:04