Code Duplication    Length = 50-50 lines in 2 locations

calendar/inc/class.calendar_boupdate.inc.php 2 locations

@@ 272-321 (lines=50) @@
269
				$this->debug_message('calendar_boupdate::update() checking for potential overlapping events for users %1 from %2 to %3',false,$users,$event['start'],$event['end']);
270
			}
271
			$max_quantity = $possible_quantity_conflicts = $conflicts = array();
272
			foreach((array) $overlapping_events as $k => $overlap)
273
			{
274
				if ($overlap['id'] == $event['id'] ||	// that's the event itself
275
					$overlap['id'] == $event['reference'] ||	// event is an exception of overlap
276
					$overlap['non_blocking'])			// that's a non_blocking event
277
				{
278
					continue;
279
				}
280
				if ($this->debug > 3 || $this->debug == 'update')
281
				{
282
					$this->debug_message('calendar_boupdate::update() checking overlapping event %1',false,$overlap);
283
				}
284
				// check if the overlap is with a rejected participant or within the allowed quantity
285
				$common_parts = array_intersect($users,array_keys($overlap['participants']));
286
				foreach($common_parts as $n => $uid)
287
				{
288
					$status = $overlap['participants'][$uid];
289
					calendar_so::split_status($status, $q, $r);
290
					if ($status == 'R')
291
					{
292
						unset($common_parts[$n]);
293
						continue;
294
					}
295
					if (is_numeric($uid) || !in_array($uid[0],$types_with_quantity))
296
					{
297
						continue;	// no quantity check: quantity allways 1 ==> conflict
298
					}
299
					if (!isset($max_quantity[$uid]))
300
					{
301
						$res_info = $this->resource_info($uid);
302
						$max_quantity[$uid] = $res_info[$this->resources[$uid[0]]['max_quantity']];
303
					}
304
					$quantity[$uid] += $q;
305
					if ($quantity[$uid] <= $max_quantity[$uid])
306
					{
307
						$possible_quantity_conflicts[$uid][] =& $overlapping_events[$k];	// an other event can give the conflict
308
						unset($common_parts[$n]);
309
						continue;
310
					}
311
					// now we have a quantity conflict for $uid
312
				}
313
				if (count($common_parts))
314
				{
315
					if ($this->debug > 3 || $this->debug == 'update')
316
					{
317
						$this->debug_message('calendar_boupdate::update() conflicts with the following participants found %1',false,$common_parts);
318
					}
319
					$conflicts[$overlap['id'].'-'.$this->date2ts($overlap['start'])] =& $overlapping_events[$k];
320
				}
321
			}
322
			// check if we are withing the allowed quantity and if not add all events using that resource
323
			// seems this function is doing very strange things, it gives empty conflicts
324
			foreach($max_quantity as $uid => $max)
@@ 492-541 (lines=50) @@
489
			{
490
				$this->debug_message(__METHOD__.'() checking for potential overlapping events for users %1 from %2 to %3',false,$users,$startts,$startts+$duration);
491
			}
492
			foreach((array) $overlapping_events as $k => $overlap)
493
			{
494
				if ($overlap['id'] == $event['id'] ||	// that's the event itself
495
					$overlap['id'] == $event['reference'] ||	// event is an exception of overlap
496
					$overlap['non_blocking'])			// that's a non_blocking event
497
				{
498
					continue;
499
				}
500
				if ($this->debug > 3 || $this->debug == 'conflicts')
501
				{
502
					$this->debug_message(__METHOD__.'() checking overlapping event %1',false,$overlap);
503
				}
504
				// check if the overlap is with a rejected participant or within the allowed quantity
505
				$common_parts = array_intersect($users,array_keys($overlap['participants']));
506
				foreach($common_parts as $n => $uid)
507
				{
508
					$status = $overlap['participants'][$uid];
509
					calendar_so::split_status($status, $q, $r);
510
					if ($status == 'R')
511
					{
512
						unset($common_parts[$n]);
513
						continue;
514
					}
515
					if (is_numeric($uid) || !in_array($uid[0],$types_with_quantity))
516
					{
517
						continue;	// no quantity check: quantity allways 1 ==> conflict
518
					}
519
					if (!isset($max_quantity[$uid]))
520
					{
521
						$res_info = $this->resource_info($uid);
522
						$max_quantity[$uid] = $res_info[$this->resources[$uid[0]]['max_quantity']];
523
					}
524
					$quantity[$uid] += $q;
525
					if ($quantity[$uid] <= $max_quantity[$uid])
526
					{
527
						$possible_quantity_conflicts[$uid][] =& $overlapping_events[$k];	// an other event can give the conflict
528
						unset($common_parts[$n]);
529
						continue;
530
					}
531
					// now we have a quantity conflict for $uid
532
				}
533
				if (count($common_parts))
534
				{
535
					if ($this->debug > 3 || $this->debug == 'conflicts')
536
					{
537
						$this->debug_message(__METHOD__.'() conflicts with the following participants found %1',false,$common_parts);
538
					}
539
					$conflicts[$overlap['id'].'-'.$this->date2ts($overlap['start'])] =& $overlapping_events[$k];
540
				}
541
			}
542
		}
543
		//error_log(__METHOD__."() conflict check took ".number_format(microtime(true)-$start, 3).'s');
544
		// check if we are withing the allowed quantity and if not add all events using that resource