I am writing a rostering app. This statement checks that by booking an extra shift the user doesn't violate a rule whereby they have booked more than 7 night shifts in a row. This code runs fine but I am trying to find a more elegant way to write it, for instance using a for loop within the if statement. This snippet exists within a bigger while loop.
if (
$original_shift->night_shift==true &&
$p_lookback_night_7===[1,1,1,1,1,1,1] || $p_lookforward_night_7===[1,1,1,1,1,1,1] ||
($p_lookback_night_1===[1] && $p_lookforward_night_6===[1,1,1,1,1,1]) ||
($p_lookback_night_2===[1,1] && $p_lookforward_night_5===[1,1,1,1,1]) ||
($p_lookback_night_3===[1,1,1] && $p_lookforward_night_4===[1,1,1,1]) ||
($p_lookback_night_4===[1,1,1,1] && $p_lookforward_night_3===[1,1,1]) ||
($p_lookback_night_5===[1,1,1,1,1] && $p_lookforward_night_2===[1,1]) ||
($p_lookback_night_6===[1,1,1,1,1,1] && $p_lookforward_night_1===[1])
) {
return 'You can\'t do more than 7 night shifts in a row';
break;
}
Aucun commentaire:
Enregistrer un commentaire