I have a private function, that calculate number of working saturdays. Then i have a seperate small private function that retrieve holidays for certain date intervals from database. So im calling this holiday function from another fucntion. But it is not working.
class DashboardPage{
private function getWorkingDays($FirstDate,$LastDate,$holidays){
$endDate = strtotime($LastDate);
$startDate = strtotime($FirstDate);
//Calculate even saturdays
$end = date("Y-m-d h:m:s",strtotime("+1 day",strtotime($LastDate))); //Add one day to include LastDate
$all_days = new DatePeriod(new DateTime($FirstDate), new DateInterval('P1D'), new DateTime($end));
foreach ($all_days as $day) {
$dayOfWeek = (int)$day->format('w'); //0-6, 6 = Saturday
$dayOfMonth =(int)$day->format('j');
$weekNum = ceil($dayOfMonth / 7);
if ($dayOfWeek == 6)
{
if ($weekNum % 2 == 0)
{
$holiday = $this->getHoliday($day); //Problem when i call this
funtion
if(empty($holiday)){
$no_saturdays += 1 ;
}
}
}
.
.
. // Further coding
$workinghours = $workingDays*9 + $no_saturdays*4;
return $workinghours;
}
private function getHoliday($day, $countryId){
$hd = new HoliDay();
$hd->Load("dateh = ? and country IS NULL",array($day));
if($hd->dateh == $day){
return $hd;
}
return null;
}
}
If i commented that getholiday() then it get executed but i could not get exact result.
You can see the error because the second parameter $countryId is missing. You should either pass this parameter or setup default value for $countryId like this:
private function getHoliday($day, $countryId = null){
$hd = new HoliDay();
$hd->Load("dateh = ? and country IS NULL",array($day));
if($hd->dateh == $day){
return $hd;
}
return null;
}