从PHP

时间:2017-02-13 10:02:59

标签: php

我有一个私人函数,用于计算星期六工作的人数。然后我有一个单独的小私有函数,从数据库中检索某些日期间隔的假期。所以我从另一个功能中调用这个假期功能。但它没有用。

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;
        }
}

如果我评论getholiday()然后它被执行但我无法得到确切的结果。

1 个答案:

答案 0 :(得分:0)

您可以看到错误,因为缺少第二个参数$ countryId。 您应该传递此参数或为$ countryId设置默认值,如下所示:

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;
    }