mercredi 17 août 2016

Multiple if structure in a php function

I am trying to run a php script which would return the name of a specific icon, depending on the day.

I have added this special method which computes the Easter day (Sunday).

Now, I have added a special case for today (17.08), just to test my algorithm. However, my $returnValue does not return the icon that I would like (i.e. assets/icons/logo_halloween.png) ... I know it's not halloween yet, but come on ;-)

I am probably doing something wrong here with my structure of the if's. Would be glad if you could assist me on this. Thanks a lot in advance.

function getIconFileName()
{
$iconPath = "assets/icons/";
$returnValue = ".";    


// gets current year and stores it in a variable
$year = date('Y');

// Calcul des dates variables (Pâques)

// gets the Easter Sunday
$date_Easter_Sunday = easter_date($year);

// computes the Good Friday and Easter Monday (based on Easter Sunday)
$date_tmp = date('Y-m-d', $date_Easter_Sunday);
$date_Easter_Monday = strtotime(date("Y-m-d", strtotime($date_tmp)) . " +1 day"); 
$date_Good_Friday = strtotime(date("Y-m-d", strtotime($date_tmp)) . " -2 day"); 

echo "Easter Sunday : " . $date_tmp . "<br>"; 
echo "Easter Monday : " . date('Y-m-d', $date_Easter_Monday) . "<br>"; 
echo "Good Friday : " . date('Y-m-d', $date_Good_Friday) . "<br>"; 

if ((date('m') == (date('m', $date_Easter_Sunday))) && (date('d') == (date('d', $date_Easter_Sunday))))
{
    // Dimanche de Pâques
    //$returnValue = $iconPath . "logo.png";
}

elseif ((date('m') == (date('m', $date_Easter_Monday))) && (date('d') == (date('d', $date_Easter_Monday))))
{
    // Lundi de Pâques
    //$returnValue = $iconPath . "logo.png";
}

elseif ((date('m') == (date('m', $date_Good_Friday))) && (date('d') == (date('d', $date_Good_Friday))))
{
    // Vendredi Saint
    //$returnValue = $iconPath . "logo.png";
}

elseif ((date('m') == 08) && (date('d') == 17))                 // ---> It looks like my code never returns this value (logo_halloween.png) <----
{
    $returnValue = $iconPath . "logo_halloween.png";
}

// Calcul des dates fixes

elseif ((date('m') == 01) && (date('d') == 01)) 
{
    // Premier jour de l'an
    $returnValue = $iconPath . "logo.png";
}

elseif ((date('m') == 03) && (date('d') == 21)) 
{
    // Premier jour du printemps
    $returnValue = $iconPath . "logo.png";
}

else
{
    // Ceci est un jour normal
    $returnValue = $iconPath . "logo.png";
}

echo "Path to icon : " . $returnValue . "<br>";

return $returnValue;
}

Aucun commentaire:

Enregistrer un commentaire