fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [15658] booking: keep correct schedule for combinatio


From: sigurdne
Subject: [Fmsystem-commits] [15658] booking: keep correct schedule for combination of allocation and booking
Date: Tue, 13 Sep 2016 09:38:16 +0000 (UTC)

Revision: 15658
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=15658
Author:   sigurdne
Date:     2016-09-13 09:38:16 +0000 (Tue, 13 Sep 2016)
Log Message:
-----------
booking: keep correct schedule for combination of allocation and booking

Modified Paths:
--------------
    branches/stavangerkommune/booking/inc/class.bobooking.inc.php
    branches/stavangerkommune/booking/inc/schedule.php

Modified: branches/stavangerkommune/booking/inc/class.bobooking.inc.php
===================================================================
--- branches/stavangerkommune/booking/inc/class.bobooking.inc.php       
2016-09-13 02:11:01 UTC (rev 15657)
+++ branches/stavangerkommune/booking/inc/class.bobooking.inc.php       
2016-09-13 09:38:16 UTC (rev 15658)
@@ -850,11 +850,76 @@
             return array('total_records'=>count($results), 
'results'=>$results);
         }
 
-        /**
+               /**
+                * Sigurd: 13 sept 2016: reworked from split_allocations_old()
+                * Split allocations overlapped by bookings into multiple 
allocations
+                * to avoid overlaps
+                */
+               function split_allocations( $allocations, $all_bookings )
+               {
+
+                       function get_from2( $a )
+                       {
+                               return $a['from_'];
+                       }
+                       ;
+
+                       function get_to2( $a )
+                       {
+                               return $a['to_'];
+                       }
+                       ;
+                       $new_allocations = array();
+                       foreach ($allocations as $allocation)
+                       {
+                               // $ Find all associated bookings
+                               $bookings = array();
+                               foreach ($all_bookings as $b)
+                               {
+                                       if ($b['allocation_id'] == 
$allocation['id'])
+                                       {
+                                               $bookings[] = $b;
+                                       }
+                               }
+                               $times = array($allocation['from_'], 
$allocation['to_']);
+                               $times = array_merge(array_map("get_from2", 
$bookings), $times);
+                               $times = array_merge(array_map("get_to2", 
$bookings), $times);
+                               $times = array_unique($times);
+                               sort($times);
+                               while (count($times) >= 2)
+                               {
+                                       $from_ = $times[0];
+                                       $to_ = $times[1];
+                                       foreach ($all_bookings as $b)
+                                       {
+                                               $found = false;
+
+                        if(($b['from_'] >= $from_ && $b['from_'] <= $to_)
+                                                       || ($b['to_'] > $from_ 
&& $b['to_'] < $to_)
+                                                       || ($b['from_'] <= 
$from_ && $b['to_'] >= $to_))
+                                               {
+                                                       $found = true;
+                                               }
+                                               if (!$found)
+                                               {
+                                                       $a = $allocation;
+                                                       $a['from_'] = $from_;
+                                                       $a['to_'] = $to_;
+                                                       $new_allocations[] = $a;
+                                               }
+                                       }
+                                       array_shift($times);
+                               }
+                       }
+
+                       return $new_allocations;
+               }
+
+               /**
          * Split allocations overlapped by bookings into multiple allocations
          * to avoid overlaps
          */
-        function split_allocations($allocations, $all_bookings)
+        function split_allocations_old($allocations, $all_bookings)
         {
             function get_from2($a) {return $a['from_'];};
             function get_to2($a) {return $a['to_'];};

Modified: branches/stavangerkommune/booking/inc/schedule.php
===================================================================
--- branches/stavangerkommune/booking/inc/schedule.php  2016-09-13 02:11:01 UTC 
(rev 15657)
+++ branches/stavangerkommune/booking/inc/schedule.php  2016-09-13 09:38:16 UTC 
(rev 15658)
@@ -65,9 +65,13 @@
                                        {
                         if(!(($tempbooking[$booking['wday']]['from_'] <= 
$booking['from_']) and ($tempbooking[$booking['wday']]['to_'] == 
$booking['to_']) and ($tempbooking[$booking['wday']]['allocation_id'] == 
$booking['id']) and ($booking['type'] == 'allocation'))){
                                                    $empty = false;
-                                                   $row[$booking['wday']] = 
$booking;
-                        }
-                        if($booking['type'] == 'booking'){
+                                                       //Sigurd: 13 sept 2016: 
do not overwrite booking with allocation
+                                                       
if(empty($row[$booking['wday']]['type']) || $row[$booking['wday']]['type'] != 
'booking')
+                                                       {
+                                                               
$row[$booking['wday']] = $booking;
+                                                       }
+                                               }
+                                               if($booking['type'] == 
'booking'){
                                                $tempbooking[$booking['wday']] 
= $booking;
                         } 
                                        }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]