pg['trainingschedual'] as $session) { if ($session['day'] == $this->day) { if (!$firstHour || $session['starts'] < $firstHour) { $firstHour = $session['starts']; $lastHour = is_float((float)$session['starts']) ? round($session['starts'] - 1) : $session['starts']; } if (!$lastHour || $session['ends'] > $lastHour) { $lastHour = is_float((float)$session['ends']) ? round($session['ends'] + 1) : $session['ends']; } $session['title'] = $this->pgsportset['branches'][$session['sports_branches_id']]['name']; $sessions[] = $session; } } if (!$sessions) { return; } $schedual = range($firstHour, $lastHour); $fullWidth = 620; $fullHeight = null; // levels * 25 height per session + 35 spacing $sessionHeight = 25; $topPositionMargin = 45; //$widthPerCol = ($fullWidth - count($schedual)) / count($schedual); $widthPerCol = $fullWidth / (count($schedual)-1); $quarterPerCol = ($widthPerCol / 4); //$widthPerCol -= 1; // set colission stepping $colissionStepping = array(); foreach($schedual as $hop => $hour) { foreach(range(0,3) as $q) { $float = $hour + ($q * .15); $colissionStepping[(string)$float] = ''; } } $colissionLevels = array( $colissionStepping ); //function checkColission($c) { // global $colissionLevel; // pr($colissionLevel); // foreach($colissionLevel as & $level) { // $colissionDetected = false; // $dirtyLevel = $level; // // check if the entire range is possible in this level // foreach($level as $stepping => $reservedSpot) { // if ($c['end'] < $stepping) { // break; // } // if ($c['start'] > $stepping) { // if ($reservedSpot) { // $colissionDetected = true; // break; // } // $dirtyLevel[(string)$stepping] = true; // } // } // pr($dirtyLevel); // if ($colissionDetected) { // // next level // } // else { // // range is free, reserve // // reserve range // } // } //} //function setColissionLevels($session, $currentLevel, $index) { // //} foreach($sessions as $sessKey => & $sess) { foreach($colissionLevels as $k => $level) { // setColissionLevels($sess, $level, $k); // if ($sess['name'] == '9' && $k == 2) { //// pr($level); // } $colissionDetected = false; $newLevel = $colissionStepping; $dirtyLevel = $level; // check if the entire range is possible in this level foreach($level as $stepping => $reservedSpot) { if ($stepping >= $sess['ends']) { break; } if ($stepping >= $sess['starts']) { $newLevel[(string)$stepping] = $sessKey; if (strlen($reservedSpot)) { $colissionDetected = true; continue; } $dirtyLevel[(string)$stepping] = $sessKey; } } // if ($sess['name'] == '9' && $k == 2) { // pr($dirtyLevel, 0); // pr($newLevel); // } if ($colissionDetected) { if (!isset($colissionLevels[$k + 1])) { // create new lvl $colissionLevels[] = $newLevel; $sess['inLevel'] = $k + 1; break; } // else { // // iterate over same logic, function wrapper todo // pr($sess); // } } else { $colissionLevels[$k] = $dirtyLevel; $sess['inLevel'] = $k; break; } } } $fullHeight = (count($colissionLevels) * $sessionHeight) + $topPositionMargin; echo '
'; /** * grid drawing * * normal loop draws 1 block too many */ //foreach($schedual as $hop => $hour) foreach(array_slice($schedual, 0, -1) as $hop => $hour) { $pixelHourPos = $widthPerCol * $hop; $attr = array(); if ($hop % 2) { $attr['style']['background'] = '#eee;'; } else { $attr['style']['background'] = '#ddd;'; } $attr['style']['left'] = $pixelHourPos . 'px'; $attr['style']['padding-top'] = '5px'; $attr['class'][] = 'gridBlock'; $attr['style']['height'] = ($fullHeight + 0) . 'px'; $attr['style']['width'] = $widthPerCol .'px'; if (max($schedual) == $hour) { $attr['style']['width'] = '1px'; } $inner = ''; if ($hop != max(array_keys($schedual)) && $hop != min(array_keys($schedual))) { // if ($hour > 12) { // $hourStr = $hour - 12; // $hourSuffix = ' pm'; // } // else { // $hourSuffix = ' am'; // $hourStr = $hour; // } // $cls = $hourStr > 9 ? 'strlen2' : 'strlen1'; // $inner = '
'. $hourStr . $hourSuffix .'
'; $cls = ''; if ($hour == 12) { $cls = 'midday'; } $inner = '
'. str_pad(number_format($hour, 2, ':', ':'), 5, 0, STR_PAD_LEFT) .'
'; } echo $this->ele('div', $inner, $attr); foreach(range(0,3) as $stepping) { $quarterMark = $stepping * .15; $time = $hour + $quarterMark; $pixelPos = $pixelHourPos + ($stepping * $quarterPerCol); foreach($sessions as & $c) { if ($c['starts'] == $time) { $c['startPx'] = $pixelPos; } if ($c['ends'] == $time) { $c['endPx'] = $pixelPos; } unset($c); } } } $colorSets = array(); foreach($this->pgsportset['sports'] as $sport) { $colorSets[$sport['id']] = $sport['colorRange']; } foreach($sessions as $c) { // $height = 100 / count($colissionLevels); $height = 25; $attr = array(); $options = array(); // $options['events']['render'] = 'function(event, api) { // alert("qwer"); // }'; // $options['show']['ready'] = true; // hide: { // fixed: true // } // $options['position'] = array( // 'target' => 'mouse', // 'adjust' => array('mouse' => false) // ); // $options['hide']['target'] = '#trScheduler .session'; $options['position']['at'] = 'top right'; $options['position']['my'] = 'bottom left'; $content = ''; $date1 = new DateTime('1-1-2000 '. number_format($c['starts'], 2, ':', ':')); $date2 = new DateTime('1-1-2000 '. number_format($c['ends'], 2, ':', ':')); $interval = $date1->diff($date2); $content .= "How long?"; if ((int)$interval->format('%h')) { $content .= ' '. $interval->format('%h') .' hours'; } if ((int)$interval->format('%i')) { if ((int)$interval->format('%h')) { $content .= ' and'; } $content .= ' ' .$interval->format('%i') .' minutes.'; } $content .= "\nWhat time? ". number_format($c['starts'], 2, ':', ':') .' to '. number_format($c['ends'], 2, ':', ':') ."\n\n"; if (false) { $content .= $c['description']; } else { $content .= $this->pgsportset['branches'][$c['sports_branches_id']]['description']; } $attr['qtip-hooks'] = 'hoverevents'; $tip = $this->qtip($c['title'], $c['title'], nl2br2($content), $attr, $options); $attr = array(); $attr['class'][] = 'session'; $attr['style']['background-color'] = '#' . array_shift($colorSets[$this->pgsportset['branches'][$c['sports_branches_id']]['sports_id']]); // $attr['style']['background'] = '-moz-linear-gradient(top, #'. array_shift($colorSets[$this->pgsportset['branches'][$c['sports_branches_id']]['sports_id']]) .' 0%, #fff 100%);'; $attr['style']['left'] = $c['startPx'] . 'px'; $attr['style']['width'] = ($c['endPx'] - $c['startPx']) . 'px'; $attr['style']['height'] = $sessionHeight . 'px'; $attr['style']['line-height'] = $height . 'px'; $top = 0; if ($c['inLevel']) { $top = $c['inLevel'] * $sessionHeight; } if ($top) { $top -= $c['inLevel'] * 2; //$top -= 10; } // if ($top) { // $top += 20; // } // else { $top += $topPositionMargin; // } $attr['style']['top'] = $top . 'px'; echo $this->ele('div', $tip, $attr); } echo '
';