fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [12068] bkbooking: stavanger update calendar split wh


From: Kjell Arne Espedal
Subject: [Fmsystem-commits] [12068] bkbooking: stavanger update calendar split when event collide with booking/allocation
Date: Mon, 01 Sep 2014 06:14:46 +0000

Revision: 12068
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=12068
Author:   kjell
Date:     2014-09-01 06:14:45 +0000 (Mon, 01 Sep 2014)
Log Message:
-----------
bkbooking: stavanger update calendar split when event collide with 
booking/allocation

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

Modified: branches/stavangerkommune/booking/inc/class.bobooking.inc.php
===================================================================
--- branches/stavangerkommune/booking/inc/class.bobooking.inc.php       
2014-08-28 11:21:34 UTC (rev 12067)
+++ branches/stavangerkommune/booking/inc/class.bobooking.inc.php       
2014-09-01 06:14:45 UTC (rev 12068)
@@ -420,9 +420,10 @@
                 * @return array containing values from $array for the keys in 
$keys.
                 */
 
+//        todo: remove debug kode
         function building_schedule($building_id, $date)
         {
-
+//            echo "debug:\n";
             $from = clone $date;
             $from->setTime(0, 0, 0);
             // Make sure $from is a monday
@@ -472,7 +473,10 @@
             }
 
             $bookings = array_merge($allocations, $bookings);
+//            echo "before rem\n";
             $bookings = $this->_remove_event_conflicts($bookings, $events);
+//            echo "after rem\n";
+
             $bookings = array_merge($events, $bookings);
 
             $resource_ids = $this->so->resource_ids_for_bookings($booking_ids);
@@ -490,6 +494,7 @@
             array_multisort($sort, SORT_ASC, $resources);
             $bookings = $this->_split_multi_day_bookings($bookings, $from, 
$to);
             $results = build_schedule_table($bookings, $resources);
+//            exit;
             return array('total_records'=>count($results), 
'results'=>$results);
         }
 
@@ -966,28 +971,153 @@
                 $e['conflicts'] = array();
             }
             $new_bookings = array();
+            $last = array();
             foreach($bookings as $b)
             {
+                if ($last) {
+                    foreach ($last as $l) {
+//                        echo $l['id']."-".$l['from_']."-".$l['to_']."\n";
+                        $new_bookings[] = $l;
+                    }
+                    $last = array();
+                }
                 $keep = true;
+//                $i = 0;
                 foreach($events as &$e)
                 {
+
+//                    echo $b['id']."\tfrom: ".substr($b['from_'],11,19)." to: 
".substr($b['to_'],11,19)."\n";
+//                    echo $e['id']."\tfrom: ".substr($e['from_'],11,19)." to: 
".substr($e['to_'],11,19)." ".$e['name']."\n";
+
                     if((($b['from_'] >= $e['from_'] && $b['from_'] < 
$e['to_']) ||
                             ($b['to_'] > $e['from_'] && $b['to_'] <= 
$e['to_']) ||
                             ($b['from_'] <= $e['from_'] && $b['to_'] >= 
$e['to_'])) && (array_intersect($b['resources'], $e['resources']) != array()))
                     {
+//                        echo "##$i\n";
                         $keep = false;
                         $e['conflicts'][] = $b;
-                        break;
+
+                        $bf = $b['from_'];
+                        $bt = $b['to_'];
+                        $ef = $e['from_'];
+                        $et = $e['to_'];
+                        $tmp = $b;
+
+                        if ($last) {
+                            $ilast = $last;
+                            $last = array();
+                            foreach ($ilast as $l) {
+                                $lf = $l['from_'];
+                                $lt = $l['to_'];
+                                $tmp = $l;
+                                if ($ef <= $lf && $et >= $lt) {
+//                                    echo "B0: break ef <= bf && et >= 
bt\n\n";
+                                    $last[] = $l;
+                                    break;
+                                } elseif (($ef >= $lf) && ($et > $lt)) {
+//                                    echo "B1: (ef >= lf) && (et > lt)\n";
+                                    $tmp['from_'] = $lf;
+                                    $tmp['to_'] = $ef;
+                                    $last[] = $tmp;
+                                } elseif (($ef <= $lf) && ($et < $lt)) {
+//                                    echo "B2: (ef <= lf) && (et < lt)\n";
+                                    $tmp['from_'] = $et;
+                                    $tmp['to_'] = $lt;
+                                    $last[] = $tmp;
+                                } elseif (($ef > $lf) && ($et < $lt)) {
+//                                    echo "B3: (ef > lf) && (et < lt)\n";
+                                    $tmp['from_'] = $lf;
+                                    $tmp['to_'] = $ef;
+                                    $last[] = $tmp;
+                                    $tmp['from_'] = $et;
+                                    $tmp['to_'] = $lt;
+                                    $last[] = $tmp;
+                                } else {
+//                                    echo "B4: else break\n\n";
+                                    $last[] = $l;
+                                    break;
+                                }
+                            }
+                        } else {
+                            if ($ef <= $bf && $et >= $bt) {
+//                                echo "A0: break ef <= bf && et >= bt\n\n";
+                                break;
+                            } elseif (($ef >= $bf) && ($et > $bt)) {
+//                                echo "A1: (ef >= bf) && (et > bt)\n";
+                                $tmp['from_'] = $bf;
+                                $tmp['to_'] = $ef;
+                                $last[] = $tmp;
+                            } elseif (($ef <= $bf) && ($et < $bt)) {
+//                                echo "A2: (ef <= bf) && (et < bt)\n";
+                                $tmp['from_'] = $et;
+                                $tmp['to_'] = $bt;
+                                $last[] = $tmp;
+                            } elseif (($ef > $bf) && ($et < $bt)) {
+//                                echo "A3: (ef > bf) && (et < bt)\n";
+                                $tmp['from_'] = $bf;
+                                $tmp['to_'] = $ef;
+                                $last[] = $tmp;
+                                $tmp['from_'] = $et;
+                                $tmp['to_'] = $bt;
+                                $last[] = $tmp;
+                            } else {
+//                                echo "A4: else break\n\n";
+                                break;
+                            }
+                        }
+//                        print_r($last);
                     }
+//                    $i+=1;
                 }
+
+                if($last)
+                {
+                    foreach ($last as $l) {
+//                        echo $l['id']."-".$l['from_']."-".$l['to_']."\n";
+                        $new_bookings[] = $l;
+                    }
+                    $last = array();
+                }
+
                 if($keep)
                 {
                     $new_bookings[] = $b;
                 }
             }
+//            print_r($new_bookings);
             return $new_bookings;
+//            exit;
         }
 
+      function _remove_event_conflicts_org($bookings, &$events)
+      {
+          foreach($events as &$e)
+          {
+              $e['conflicts'] = array();
+          }
+          $new_bookings = array();
+          foreach($bookings as $b)
+          {
+              $keep = true;
+              foreach($events as &$e)
+              {
+                  if((($b['from_'] >= $e['from_'] && $b['from_'] < $e['to_']) 
||
+                          ($b['to_'] > $e['from_'] && $b['to_'] <= $e['to_']) 
||
+                          ($b['from_'] <= $e['from_'] && $b['to_'] >= 
$e['to_'])) && (array_intersect($b['resources'], $e['resources']) != array()))
+                  {
+                      $keep = false;
+                      $e['conflicts'][] = $b;
+                      break;
+                  }
+              }
+              if($keep)
+              {
+                  $new_bookings[] = $b;
+              }
+          }
+          return $new_bookings;
+      }
+
                public function complete_expired(&$bookings) {
                        $this->so->complete_expired($bookings);
                }

Modified: branches/stavangerkommune/bookingfrontend/inc/class.uibuilding.inc.php
===================================================================
--- branches/stavangerkommune/bookingfrontend/inc/class.uibuilding.inc.php      
2014-08-28 11:21:34 UTC (rev 12067)
+++ branches/stavangerkommune/bookingfrontend/inc/class.uibuilding.inc.php      
2014-09-01 06:14:45 UTC (rev 12068)
@@ -20,6 +20,8 @@
             $this->resource_bo = CreateObject('booking.boresource');
         }
 
+//        TODO: remove debug kode
+
                public function information_screen()
                {
             $today = new DateTime(phpgw::get_var('date', 'GET'), new 
DateTimeZone('Europe/Oslo'));
@@ -52,8 +54,10 @@
                 "Sun" => "Søndag"
             );
 
+            echo "<pre>\n";
             $bookings = 
$this->booking_bo->building_infoscreen_schedule(phpgw::get_var('id', 'GET'), 
$date, $res);
-
+            print_r($bookings);
+            exit;
             $from = clone $date;
             $from->setTime(0, 0, 0);
             // Make sure $from is a monday
@@ -188,9 +192,11 @@
             exit;
                }
 
+//    TODO:  remove debug kode
+
                public function schedule()
                {
-                       $backend = phpgw::get_var('backend', 'GET');
+            $backend = phpgw::get_var('backend', 'GET');
                        $building = 
$this->bo->get_schedule(phpgw::get_var('id', 'GET'), 
'bookingfrontend.uibuilding');
                        if ($building['deactivate_application'] == 0) { 
                                $building['application_link'] = 
self::link(array(
@@ -218,7 +224,7 @@
                        {
                                $building['date'] = phpgw::get_var('date', 
'GET');
                        }
-            
+
                        self::add_javascript('booking', 'booking', 
'schedule.js');
                        self::render_template('building_schedule', 
array('building' => $building, 'backend' => $backend));
                }




reply via email to

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