A dynamic method of generating URLs with nested conditions

The name of the pictureThe name of the pictureThe name of the pictureClash 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;







share|improve this question





















  • 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
















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;







share|improve this question





















  • 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












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;







share|improve this question













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;









share|improve this question












share|improve this question




share|improve this question








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
















  • 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















active

oldest

votes











Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");

StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















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



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














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













































































Popular posts from this blog

Chat program with C++ and SFML

Function to Return a JSON Like Objects Using VBA Collections and Arrays

Will my employers contract hold up in court?