Fix for bug #2050 - a playlist spanning multiple hours is not properly plotted on the DAY VIEW. Added code documentation.

This commit is contained in:
paul 2006-11-29 05:28:38 +00:00
parent 22810e102a
commit 9c3108e75b
2 changed files with 158 additions and 78 deletions

View File

@ -1,7 +1,13 @@
{$SCHEDULER->buildDay()} {$SCHEDULER->buildDay()}
{assign var="_scale" value=$SCHEDULER->getDayTimingScale()} {* get the 24h scale *}
{assign var="_entrys" value=$SCHEDULER->getDayEntrys()} {* get all entrys on given day from scheduler *} {* get the 24h scale *}
{assign var="_day" value=$SCHEDULER->curr} {* to have year, month, day in between_additem.tpl *} {assign var="_scale" value=$SCHEDULER->getDayTimingScale()}
{* get all entrys on given day from scheduler *}
{assign var="_entrys" value=$SCHEDULER->getDayEntrys()}
{* to have year, month, day in between_additem.tpl *}
{assign var="_day" value=$SCHEDULER->curr}
<div class="content"> <div class="content">
<div class="container_elements"> <div class="container_elements">
@ -20,7 +26,7 @@
{foreach from=$_scale item="_hour"} {foreach from=$_scale item="_hour"}
{if isset($_hour) && is_array($_entrys[$_hour])} {if is_array($_entrys[$_hour])}
<tr class="blue1"> <tr class="blue1">
<td style="border-left: 1px solid #ccc; cursor: pointer" {include file="scheduler/day_additem.tpl"}> <td style="border-left: 1px solid #ccc; cursor: pointer" {include file="scheduler/day_additem.tpl"}>
{$_hour|string_format:"%02d"}:00 {$_hour|string_format:"%02d"}:00
@ -53,7 +59,7 @@
<i>{$i.creator}</i> <i>{$i.creator}</i>
{if $i.endshere} {if $i.endshere}
{include file="scheduler/between_additem.tpl"} {include file="scheduler/between_additem.tpl"}
{/if} {/if}
{else} {else}
{$i.start} - ##tomorrow## {$i.end} {$i.start} - ##tomorrow## {$i.end}
<i>{$i.creator}</i> <i>{$i.creator}</i>
@ -62,8 +68,10 @@
{/foreach} {/foreach}
{/if} {/if}
{if $_entrys.span[$_hour]} {if $_entrys[$_hour].span}
span <div {include file="scheduler/removeitem.tpl"}>
...
</div>
{/if} {/if}
</td> </td>
</tr> </tr>

View File

@ -1,41 +1,91 @@
<?php <?php
/** /**
* @author Sebastian Gobel <sebastian.goebel@web.de>
* @author Paul Baranowski <paul@paulbaranowski.org>
* @package Campcaster * @package Campcaster
* @subpackage htmlUI * @subpackage htmlUI
* @version $Revision$ * @version $Revision$
* @copyright 2006 MDLF, Inc.
* @license http://www.gnu.org/licenses/gpl.txt
* @link http://www.campware.org
*/ */
class uiCalendar class uiCalendar
{ {
/**
* An array of 10 array, one for each year, centered around the
* current year. Each year array consists of:
* ["year"] => int
* ["isSelected"] => boolean
*
* @var array
*/
public $Decade; public $Decade;
/**
* An array of 12 arrays, each representing a month of the year.
* Each array consists of:
* ["month"] => int : numeric representation of the month
* ["label"] => string : name of the month
* ["isSelected"] => boolean : TRUE if the month is selected
*
* @var array
*/
public $Year; public $Year;
/**
* An array of 30 arrays, one for each day of the month.
*
* @var array
*/
public $Month; public $Month;
/**
* An array of 7 arrays, one for each day of the week.
*
* @var array
*/
public $Week; public $Week;
/**
* An array of 24 arrays, one for each hour in the day.
*
* @var array
*/
public $Day; public $Day;
/**
* An array of 60 arrays, one for each minute in the hour.
*
* @var array
*/
public $Hour; public $Hour;
public function __construct() public function __construct() { }
{
}
/**
* Create the internal "Decade" array, an array of 10 arrays,
* one for each year centered around the current year.
*
* @return void
*/
function buildDecade() function buildDecade()
{ {
// Return if already created.
if (is_array($this->Decade)) { if (is_array($this->Decade)) {
return; return;
} }
for ($Year = $this->curr['year']-5; $Year<=$this->curr['year']+5; $Year++) { for ($Year = $this->curr['year'] - 5; $Year <= ($this->curr['year'] + 5); $Year++) {
$this->Decade[] = array( $this->Decade[] = array('year' => $Year,
'year' => $Year, 'isSelected' => ($Year==$this->curr['year']) ? TRUE : FALSE);
'isSelected' => $Year==$this->curr['year'] ? TRUE : FALSE
);
} }
} }
function buildYear() function buildYear()
{ {
// Return if already created.
if (is_array($this->Year)) { if (is_array($this->Year)) {
return; return;
} }
@ -44,23 +94,22 @@ class uiCalendar
require_once('Calendar/Month.php'); require_once('Calendar/Month.php');
$Year = new Calendar_Year($this->curr['year']); $Year = new Calendar_Year($this->curr['year']);
# mark current month // mark current month
$sel = new Calendar_Month($this->curr['year'], $this->curr['month']); $sel = new Calendar_Month($this->curr['year'], $this->curr['month']);
$selections = array($sel); $selections = array($sel);
$Year->build($selections, UI_SCHEDULER_FIRSTWEEKDAY); $Year->build($selections, UI_SCHEDULER_FIRSTWEEKDAY);
while ($Month = $Year->fetch()) { while ($Month = $Year->fetch()) {
$this->Year[] = array( $this->Year[] = array('month' => sprintf('%02d', $Month->thisMonth()),
'month' => sprintf('%02d', $Month->thisMonth()), 'label' => uiCalendar::_getMonthName($Month),
'label' => $this->_getMonthName($Month), 'isSelected' => $Month->isSelected());
'isSelected' => $Month->isSelected()
);
} }
} }
function buildMonth() function buildMonth()
{ {
// Return if already created.
if (is_array($this->Month)) { if (is_array($this->Month)) {
return; return;
} }
@ -73,22 +122,25 @@ class uiCalendar
$Month->build($this->_scheduledDays('month')); $Month->build($this->_scheduledDays('month'));
while ($Day = $Month->fetch()) { while ($Day = $Month->fetch()) {
// Next 2 lines are due to a bug in Calendar_Month_Weekdays // Next 2 lines are due to a bug in Calendar_Month_Weekdays
$corrMonth = $Day->thisMonth()<=12 ? sprintf('%02d', $Day->thisMonth()) : '01'; $corrMonth = ($Day->thisMonth() <= 12) ? sprintf('%02d', $Day->thisMonth()) : '01';
$corrYear = $Day->thisMonth()<=12 ? $Day->thisYear() : $Day->thisYear()+1; $corrYear = ($Day->thisMonth() <= 12) ? $Day->thisYear() : $Day->thisYear() + 1;
$isCurrent = ($Day->thisDay() == $this->curr['day']
&& $Day->thisMonth() == $this->curr['month']) ? TRUE : FALSE;
$isToday = ($Day->thisDay() == strftime("%d")
&& $Day->thisMonth()==strftime("%m")) ? TRUE : FALSE;
$this->Month[] = array( $this->Month[] = array(
'day' => sprintf('%02d', $Day->thisDay()), 'day' => sprintf('%02d', $Day->thisDay()),
'week' => $this->_getWeekNr($Day), 'week' => uiCalendar::_getWeekNr($Day),
'month' => $corrMonth, 'month' => $corrMonth,
'year' => $corrYear, 'year' => $corrYear,
'label' => $this->_getDayName($Day), 'label' => $this->_getDayName($Day),
'isEmpty' => $Day->isEmpty(), 'isEmpty' => $Day->isEmpty(),
'isFirst' => $Day->isFirst(), 'isFirst' => $Day->isFirst(),
'isLast' => $Day->isLast(), 'isLast' => $Day->isLast(),
'isSelected' => $Day->isSelected(), 'isSelected' => $Day->isSelected(),
'isCurrent' => $Day->thisDay()==$this->curr['day'] && $Day->thisMonth()==$this->curr['month'] ? TRUE : FALSE, 'isCurrent' => $isCurrent,
'isToday' => $Day->thisDay()==strftime("%d") && $Day->thisMonth()==strftime("%m") ? TRUE : FALSE, 'isToday' => $isToday,
'timestamp' => $Day->thisDay(TRUE) 'timestamp' => $Day->thisDay(TRUE));
);
} }
} }
@ -104,19 +156,21 @@ class uiCalendar
$Week = new Calendar_Week($this->curr['year'], $this->curr['month'], $this->curr['day'], UI_SCHEDULER_FIRSTWEEKDAY); $Week = new Calendar_Week($this->curr['year'], $this->curr['month'], $this->curr['day'], UI_SCHEDULER_FIRSTWEEKDAY);
$Week->build($this->_scheduledDays('week')); $Week->build($this->_scheduledDays('week'));
while ($Day = $Week->fetch()) { while ($Day = $Week->fetch()) {
$corrMonth = $Day->thisMonth()<=12 ? sprintf('%02d', $Day->thisMonth()) : '01'; ## due to bug in // Next 2 lines are due to a bug in Calendar_Month_Weekdays
$corrYear = $Day->thisMonth()<=12 ? $Day->thisYear() : $Day->thisYear()+1; ## Calendar_Month_Weekdays $corrMonth = ($Day->thisMonth() <= 12) ? sprintf('%02d', $Day->thisMonth()) : '01';
$corrYear = ($Day->thisMonth() <= 12) ? $Day->thisYear() : $Day->thisYear()+1;
$isToday = ($Day->thisDay()==strftime("%d")
&& $Day->thisMonth()==strftime("%m")) ? TRUE : FALSE;
$this->Week[] = array( $this->Week[] = array(
'day' => sprintf('%02d', $Day->thisDay()), 'day' => sprintf('%02d', $Day->thisDay()),
'week' => $this->_getWeekNr($Day), 'week' => uiCalendar::_getWeekNr($Day),
'month' => $corrMonth, 'month' => $corrMonth,
'year' => $corrYear, 'year' => $corrYear,
'label' => $this->_getDayName($Day), 'label' => $this->_getDayName($Day),
'isSelected' => $Day->isSelected(), 'isSelected' => $Day->isSelected(),
'isCurrent' => $Day->thisDay()==$this->curr['day'] ? TRUE : FALSE, 'isCurrent' => $Day->thisDay()==$this->curr['day'] ? TRUE : FALSE,
'isToday' => $Day->thisDay()==strftime("%d") && $Day->thisMonth()==strftime("%m") ? TRUE : FALSE, 'isToday' => $isToday,
'timestamp' => $Day->thisDay(TRUE) 'timestamp' => $Day->thisDay(TRUE));
);
} }
} }
@ -133,20 +187,18 @@ class uiCalendar
$Day->build(); $Day->build();
while ($Hour = $Day->fetch()) { while ($Hour = $Day->fetch()) {
// Next two lines are due to a bug in Calendar_Month_Weekdays // Next two lines are due to a bug in Calendar_Month_Weekdays
$corrMonth = $Hour->thisMonth()<=12 ? sprintf('%02d', $Hour->thisMonth()) : '01'; $corrMonth = ($Hour->thisMonth() <= 12) ? sprintf('%02d', $Hour->thisMonth()) : '01';
$corrYear = $Hour->thisMonth()<=12 ? $Day->thisYear() : $Hour->thisYear()+1; $corrYear = ($Hour->thisMonth() <= 12) ? $Day->thisYear() : $Hour->thisYear()+1;
$this->Day[] = array( $this->Day[] = array(
'day' => sprintf('%02d', $Hour->thisDay()), 'day' => sprintf('%02d', $Hour->thisDay()),
'week' => $this->_getWeekNr($Hour), 'week' => uiCalendar::_getWeekNr($Hour),
'month' => $corrMonth, 'month' => $corrMonth,
'year' => $corrYear, 'year' => $corrYear,
'hour' => $Hour->thisHour(), 'hour' => $Hour->thisHour(),
'isSelected' => $Hour->isSelected(), 'isSelected' => $Hour->isSelected(),
'isCurrent' => $Hour->thisDay()==$this->curr['day'] ? TRUE : FALSE, 'isCurrent' => $Hour->thisDay()==$this->curr['day'] ? TRUE : FALSE,
'timestamp' => $Hour->thisHour(TRUE) 'timestamp' => $Hour->thisHour(TRUE));
);
} }
} }
@ -161,41 +213,61 @@ class uiCalendar
$Hour = new Calendar_Hour($this->curr['year'], $this->curr['month'], $this->curr['day'], $this->curr['hour']); $Hour = new Calendar_Hour($this->curr['year'], $this->curr['month'], $this->curr['day'], $this->curr['hour']);
$Hour->build(); $Hour->build();
while ($Min = $Hour->fetch()) { while ($Min = $Hour->fetch()) {
$isCurrent = ($Min->thisDay() == $this->curr['hour']) ? TRUE : FALSE;
$this->Hour[] = array( $this->Hour[] = array(
'day' => sprintf('%02d', $Min->thisDay()), 'day' => sprintf('%02d', $Min->thisDay()),
'week' => $this->_getWeekNr($Min), 'week' => uiCalendar::_getWeekNr($Min),
'month' => sprintf('%02d', $Min->thisMonth()), 'month' => sprintf('%02d', $Min->thisMonth()),
'year' => $Min->thisYear(), 'year' => $Min->thisYear(),
'hour' => $Min->thisHour(), 'hour' => $Min->thisHour(),
'minute' => $Min->thisMinute(), 'minute' => $Min->thisMinute(),
'isSelected' => $Min->isSelected(), 'isSelected' => $Min->isSelected(),
'isCurrent' => $Min->thisDay()==$this->curr['hour'] ? TRUE : FALSE 'isCurrent' => $isCurrent);
);
} }
} }
## some data which PEAR::Calendar does not provide ########################################################################################## /**
function _getMonthName(&$date) { * Get the name of the month.
*
* @param Calendar_Month $date
* @return array
* With keys:
* ['short'] => short name of the month
* ['full'] => complete name of the month
*/
private static function _getMonthName(&$date) {
$timestamp = mktime($date->thisHour(), $date->thisMinute(), $date->thisSecond(), $date->thisMonth(), $date->thisDay(), $date->thisYear()); $timestamp = mktime($date->thisHour(), $date->thisMinute(), $date->thisSecond(), $date->thisMonth(), $date->thisDay(), $date->thisYear());
#echo $date->thisHour().$date->thisMinute().$date->thisSecond().$date->thisYear().$date->thisMonth().$date->thisDay().$timestamp."<br>";
return array('short' => strftime("%b", $timestamp), return array('short' => strftime("%b", $timestamp),
'full' => strftime("%B", $timestamp)); 'full' => strftime("%B", $timestamp));
} }
function _getWeekNr(&$date) { /**
* Get the week number (1 to 53)
*
* @param Calendar_Day|Calendar_Hour|Calendar_Minute $date
* @return int
*/
private static function _getWeekNr(&$date) {
$timestamp = mktime($date->thisHour(), $date->thisMinute(), $date->thisSecond(), $date->thisMonth(), $date->thisDay(), $date->thisYear()); $timestamp = mktime($date->thisHour(), $date->thisMinute(), $date->thisSecond(), $date->thisMonth(), $date->thisDay(), $date->thisYear());
#echo $date->thisHour().$date->thisMinute().$date->thisSecond().$date->thisYear().$date->thisMonth().$date->thisDay().$timestamp."<br>";
return strftime("%V", $timestamp); return strftime("%V", $timestamp);
} }
function _getDayName(&$date) { /**
* Get the name of the day.
*
* @param Calendar_Day $date
* @return array
* With keys:
* ['short'] => short version of day name
* ['full'] => day name
*/
private static function _getDayName(&$date) {
$timestamp = mktime($date->thisHour(), $date->thisMinute(), $date->thisSecond(), $date->thisMonth(), $date->thisDay(), $date->thisYear()); $timestamp = mktime($date->thisHour(), $date->thisMinute(), $date->thisSecond(), $date->thisMonth(), $date->thisDay(), $date->thisYear());
#echo $date->thisHour().$date->thisMinute().$date->thisSecond().$date->thisYear().$date->thisMonth().$date->thisDay().$timestamp."<br>";
return array('short' => strftime("%a", $timestamp), return array('short' => strftime("%a", $timestamp),
'full' => strftime("%A", $timestamp)); 'full' => strftime("%A", $timestamp));
} }
} } // class uiCalendar
?> ?>