gpt4 book ai didi

php - 使用没有日期的 FullCalendar

转载 作者:可可西里 更新时间:2023-11-01 09:01:21 24 4
gpt4 key购买 nike

现在,我正在为类(class)表制定时间表。我的想法是设置 FullCalendar仅查看 agendaWeek 并设置其他内容的格式。关于如何获取和添加事件的编程方面是我不知道的,因为我不会为此实例使用任何日期。

这是时间表表:

| schedid | subjectcode | prof_id  | day     | start_time | end_time | duration | room |
-------------------------------------------------------------------------------------------
| 1 | TECHNO | 16-00001 | Monday | 11:00:00 | 14:00:00 | 3 | SL |
| 2 | TECHNO | 16-00001 | Tuesday | 10:30:00 | 13:30:00 | 3 | SL |

这就是我要实现的目标:

enter image description here

我已经阅读了文档,阅读的越多,我就越不知道该怎么做,而且我真的不知道如何实现它,因为 FullCalendar 取决于日期。非常感谢任何建议和帮助。

编辑:

这是我的 FullCalendar 脚本:

$(document).ready(function() {
$("#add-sched").fullCalendar({
header: false,
columnFormat: 'dddd',
allDaySlot: false,
hiddenDays: [0],
defaultView: 'agendaWeek',
minTime: '07:00:00',
maxTime: '21:00:00',
editatble: true,
events: [ // values will be coming from an ajax call so I'm just placing here what inputs I would like
{
title: 'Event',
start: 'MondayT11:00:00', //what I would like to input
end: 'MondayT11:00:00',
// start: '2016-12-12T11:00:00',
// end: '2016-12-12T14:00:00',
editable: true
}
]
});
});

最佳答案

如果我理解你的目标,你需要一周的静态日历。事件不会按日期更改,只会按日期名称更改。

所以我重写了以前的解决方案。在此变体中,形成了关联数组,其中包含当前周的日期,键是日期的名称。可以通过日期名称访问日期,因此您不需要在数据库中存储日期请看看这个。

HTML页面(非重要代码):

<html>
<head>
<meta charset='utf-8' />
<link href='/something/fullcalendar.min.css' rel='stylesheet' />
<link href='/something/fullcalendar.print.min.css' rel='stylesheet' media='print' />
<script src='/something/lib/moment.min.js'></script>
<script src='/something/lib/jquery.min.js'></script>
<script src='/something/fullcalendar.min.js'></script>
<script src='/something/initCalendar.js'></script> <!-- Script with all important stuff-->
<style>
body {
margin: 40px 10px;
padding: 0;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
font-size: 14px;
}

#calendar {
max-width: 900px;
margin: 0 auto;
}

</style>
</head>
<body>

<div id='calendar'></div>

</body>
</html>

initCalendar.js 代码(最重要的部分):

 Date.prototype.getDaysOfCurrentWeek = function(start)
{
// Array of all days of week
var days = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];

// Calculates date of first day of current week
start = start || 0;
var today = new Date(this.setHours(0, 0, 0, 0));
var day = today.getDay() - start;
var date = today.getDate() - day;

// Then we are calculating all dates of current week and then reformat them into ISOO
var daysOfWeek = new Object();
for(i = 0; i < 8; i++) {
tmp = new Date(today.setDate(date+i));
daysOfWeek[days[i]] = tmp.getFullYear()+'-'+(tmp.getMonth()+1)+'-'+tmp.getDate();
}

return daysOfWeek;
}


var days = new Date().getDaysOfCurrentWeek(); // gets array like ('nameOfDay' => 0000-00-00)
$(document).ready(function(){
$('#calendar').fullCalendar({
header: false,
columnFormat: 'dddd',
allDaySlot: false,
hiddenDays: [0],
defaultView: 'agendaWeek',
minTime: '07:00:00',
maxTime: '21:00:00',
editatble: true,
});
$.post( "getevents2.php",
{'getEvents': 1},
function(data) {
var array = JSON.parse(data);
for(i = 0; i < array.length; i++) {
$('#calendar').fullCalendar( 'renderEvent', {
title: 'Sometitle',
start: days[array[i]['day']]+'T'+array[i]['start_time'], // here we are setting needed date from array 'days' by day's name which we got from database
end: days[array[i]['day']]+'T'+array[i]['end_time'] // here's the same
} );
}
}
);
});

getevents2.php的PHP代码:

if(isset($_POST['getEvents'])) {
$result = $db->query("SELECT * FROM `calendar`");
$return = array();
while($row = $result->fetch_assoc()) {
$return[] = $row;
}

echo json_encode($return);
}

这就是您所需要的吗?还是我又做错了?

关于php - 使用没有日期的 FullCalendar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41115235/

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