Find Resource Overlaps in an Array

[email protected] (Don Wieland)
Newsgroups php.general
Message-ID <[email protected]>
Hello,

I have an array:

$lessons = Array
(
    [0] => Array
        (
            [res] => 45
            [start] => 2021-07-14 16:00:00
            [end] => 2021-07-14 16:45:00
            [start_int] => 1626292800
            [end_int] => 1626295500
            [tdur_slot] => 18
        )

    [1] => Array
        (
            [res] => 45
            [start] => 2021-07-14 16:45:00
            [end] => 2021-07-14 17:30:00
            [start_int] => 1626295500
            [end_int] => 1626298200
            [tdur_slot] => 18
        )

    [2] => Array
        (
            [res] => 45
            [start] => 2021-07-14 17:30:00
            [end] => 2021-07-14 18:30:00
            [start_int] => 1626298200
            [end_int] => 1626301800
            [tdur_slot] => 24
        )

    [3] => Array
        (
            [res] => 9
            [start] => 2021-07-14 10:00:00
            [end] => 2021-07-14 10:45:00
            [start_int] => 1626271200
            [end_int] => 1626273900
            [tdur_slot] => 18
        )

)

I am trying to compile two functions to help with scheduling lessons (conflicts and checking for valid availability).

function check_for_overlap($array, $resource, $sourceStart, $sourceEnd, $KeyResource, $tKeyStart, $tKeyEnd){

     I want check for a basic overlap in $array for that resource - 
     
     $resource = $KeyResource
     $sourceStart < $tKeyEnd && $sourceEnd > $tKeyStart

     if overlap return TRUE else FALSE

}

example using above array:

$result = function check_for_overlap($lessons, 9, 1626271200, 1626273900, ‘res’, 'start_int', 'end_int’)
$result would be TRUE

--------

function valid_availability($array, $resource, $sourceStart, $sourceEnd, $KeyResource, $tKeyStart, $tKeyEnd){

     loop every 5 minute interval between $sourceStart and $sourceEnd for that resource, check for an valid overlap
     each 5 minute interval
     $resource = $KeyResource
     $sourceStart < $tKeyEnd && $sourceEnd > $tKeyStart

     if any intervals test are FALSE exit and return FALSE else TRUE

}

example using above array:

$result = function valid_availability($lessons, 45, 1626273900, 1626292800, ‘res’, 'start_int', 'end_int’)
$result would be FALSE

I’d appreciate any assistance on this. Thanks ;-)

Don
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.