gpt4 book ai didi

php - 尝试用 PHP 生成一周时间线

转载 作者:可可西里 更新时间:2023-10-31 23:50:07 25 4
gpt4 key购买 nike

我正在编写某种日程表,但在日期中反复无常。

我有一个从 6:00h 到 18:30h 的 5 个工作日生成的时间表,这没问题。我有一个包含用户的表和一个包含日期的表。用户在一周内可以有多个任务。

这是数组:

Array
(
[0] => Array
(
[dateStart] => 2011-09-14 13:00:00
[dateEnd] => 2011-09-15 11:00:00
[eventType] => 1
[data] => test
[taskDescription] => Vakantieverlof
[taskColor] => ff6600
)

[1] => Array
(
[dateStart] => 2011-09-14 15:00:00
[dateEnd] => 2011-09-14 18:00:00
[eventType] => 3
[data] =>
[taskDescription] => ADV
[taskColor] => 336600
)

[2] => Array
(
[dateStart] => 2011-09-15 16:00:00
[dateEnd] => 2011-09-16 10:00:00
[eventType] => 2
[data] =>
[taskDescription] => Ziek
[taskColor] => ff0000
)
)

这是通过数组的循环:

$dat=0;
while($dat<count($row->dates))
{
$color = "cccccc";

if(!empty($row->dates[$dat]['taskColor'])) {
$color = $row->dates[$dat]['taskColor'];
$desc = $row->dates[$dat]['taskDescription'];
} else {
$color = "cccccc";
}
$datNext = $dat+1;
if($datNext >= count($row->dates)) $datNext = $dat;
if($row->dates[$datNext]['dateStart'] >= $hourCons AND $dat >= count($row->dates))
{
$dat++;

} else {
if( $row->dates[$dat]['dateStart'] < $hourConsEnd AND $row->dates[$dat]['dateEnd'] > $hourCons )
{
$wpcal .= "<div class=\"fullCell\" style=\"".$transparent." background-color: #".$color.";\"></div>";

} else {
$wpcal .= "<div class=\"emptyCell\" style=\"\"></div>";


}
}
$dat++;

}

现在我得到 3 个时间线,代表每个计划任务。像这样:

Screenshot

但我想要 1 个包含这些任务中的每一个的时间线......在这种情况下,绿色任务可能与橙色任务重叠。

请帮帮我,我现在已经苦恼了几天...

最佳答案

不是遍历约会数组,而是遍历每一天的小时数。在该循环内,检查任何约会是否与该时间重叠,如果是则绘制填充。

$filled_flag = false;
foreach ($row->dates as $appt) {
if ($appt['dateStart'] < $hourConsEnd && $appt['dateEnd'] > $hourCons) {
$filled_flag = true;
break;
}
}
if ($filled_flag) {
$wpcal .= "<div class=\"fullCell\" style=\"".$transparent." background-color: #".$color.";\"></div>";
} else {
$wpcal .= "<div class=\"emptyCell\" style=\"\"></div>";
}

关于php - 尝试用 PHP 生成一周时间线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7422234/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com