0

I need to call my JS function in my php function to get into my loop and do the check if it's holidays.

I already check if it is weekend days and I would like to do the same for public holidays

i try to this call in my condition if but it dosn't work.

it is possible ?

Function js for holiday

    /**
     * [_publicHoliday : remove all public holiday in France]
     * @param  {[type]} year [description]
     * @return {[type]}      [description]
     */
    function _publicHoliday(year) {
        var G = year % 19;
        var C = Math.floor(year / 100);
        var H = (C - Math.floor(C / 4) - Math.floor((8 * C + 13) / 25) + 19 * G + 15) % 30;
        var I = H - Math.floor(H / 28) * (1 - Math.floor(H / 28) * Math.floor(29 / (H + 1)) * Math.floor((21 - G) / 11));
        var J = (year * 1 + Math.floor(year / 4) + I + 2 - C + Math.floor(C / 4)) % 7;
        var L = I - J;
        var EasterMonth = 3 + Math.floor((L + 40) / 44);
        var EasterDay = L + 28 - 31* Math.floor(EasterMonth / 4);
        
        var publicHoliday = [
            new Date(year, 0, 1).getTime(),
            new Date(year, 4, 1).getTime(),
            new Date(year, 4, 8).getTime(),
            new Date(year, 4, 10).getTime(),
            new Date(year, 4, 21).getTime(),
            new Date(year, 6, 14).getTime(),
            new Date(year, 7, 15).getTime(),
            new Date(year, 10, 1).getTime(),
            new Date(year, 10, 11).getTime(),
            new Date(year, 11, 25).getTime(),
            new Date(year, EasterMonth - 1, EasterDay + 1).getTime(),
            new Date(year, EasterMonth - 1, EasterDay + 39).getTime(),
            new Date(year, EasterMonth - 1, EasterDay + 50).getTime()
        ];
        
        return publicHoliday;
    }

Function php

function add_request_time_datelist($request) {
    $end_date = date_create_from_format('d/m/Y', $request["date_end"])->format('m/d/Y');
    $start_date = date_create_from_format('d/m/Y', $request["date_start"])->format('m/d/Y');
    $i = 0;
    $start_date = date('Y-m-d H:i:s', strtotime($start_date). ' + '.$i.' days');
    $end_date = date('Y-m-d H:i:s', strtotime($end_date));
    if ($start_date == $end_date AND !isWeekend($start_date) AND !_publicHoliday($start_date)) {
            $res = event_signal('EVENT_IS_DAY_COMPLETE', array(
                    $request["user_applicant_id"],
                    $start_date,
                    $year,
                    1
            ));

            if (!$res) {
                    trigger_error( plugin_lang_get("error_more_than_one_a_day"), ERROR );
                    return;
            }
            event_signal( 'EVENT_INSERT_DATA_TIME' , array(
                            $request["user_applicant_id"],
                            $request["bug_id"],
                            $start_date,
                            $year,
                            1,
                            $date = date('Y-m-d H:i:s'),
                            0,
                            "",
                    )
            );
            event_signal( 'EVENT_UPDATE_ABCHIFFRAGE' , $request["bug_id"] );
            return;
    }
    while($start_date <= $end_date) {
            if (!isWeekend($start_date) AND !_publicHoliday($start_date)) {
                    $res = event_signal('EVENT_IS_DAY_COMPLETE', array(
                            $request["user_applicant_id"],
                            $start_date,
                            $year,
                            1
                    ));

                    if (!$res) {
                            trigger_error( plugin_lang_get("error_more_than_one_a_day"), ERROR );
                            return;
                    }
            }
            $start_date = date('Y-m-d H:i:s', strtotime($start_date. ' + 1 days'));
            $i++;
    }
    $start_date = date_create_from_format('d/m/Y', $request["date_start"])->format('m/d/Y');
    $i = 0;
    $start_date = date('Y-m-d H:i:s', strtotime($start_date. ' + '.$i.' days'));

    while($start_date <= $end_date) {
            if (!isWeekend($start_date) AND !_publicHoliday($start_date)) {
                    $indice = 1;
                    event_signal( 'EVENT_INSERT_DATA_TIME' , array(
                                    $request["user_applicant_id"],
                                    $request["bug_id"],
                                    $start_date,
                                    $year,
                                    $indice,
                                    $date = date('Y-m-d H:i:s'),
                                    0,
                                    "",
                            )
                    );
            }
            $start_date = date('Y-m-d H:i:s', strtotime($start_date. ' + 1 days'));
            $i++;
    }
    event_signal( 'EVENT_UPDATE_ABCHIFFRAGE' , $request["bug_id"] );

}
Nocktis
  • 125
  • 1
  • 3
  • 12

0 Answers0