使用不带日期的 FullCalendar
Posted
技术标签:
【中文标题】使用不带日期的 FullCalendar【英文标题】:Use FullCalendar without date 【发布时间】:2017-04-28 04:01:46 【问题描述】:现在,我正在制定课程表。我的想法是将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 |
这就是我想要实现的目标:
我已经阅读了文档,我阅读的越多,我就越不知道该怎么做,而且我真的不知道如何实现这一点,因为 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
]
);
);
【问题讨论】:
请分享一些代码:) 【参考方案1】:此表应该是 html 文档还是 Excel 文档?
我终于做到了。
这是页面的 HTML && JS 代码:
<!DOCTYPE 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>
Date.prototype.getWeek = function(start)
//Calcing the starting point
start = start || 0;
var today = new Date(this.setHours(0, 0, 0, 0));
var day = today.getDay() - start;
var date = today.getDate() - day;
// Grabbing Start/End Dates
var StartDate = new Date(today.setDate(date));
var EndDate = new Date(today.setDate(date + 6));
return [StartDate, EndDate];
// test code
var Dates = new Date().getWeek();
for(i = 0; i < Dates.length; i++)
day = Dates[i].getDate();
month = (Dates[i].getMonth()) + 1;
year = Dates[i].getFullYear();
Dates[i] = year + '-' + month + '-' + day;
$(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( "getevents.php",
'getEvents': 1, 'startDate': Dates[0], 'endDate': Dates[1],
function(data)
var array = JSON.parse(data);
for(i = 0; i < array.length; i ++)
$('#calendar').fullCalendar( 'renderEvent',
title: 'Sometitle',
start: array[i]['date']+'T'+array[i]['start_time'], //what I would like to input
end: array[i]['date']+'T'+array[i]['end_time'],
);
);
);
</script>
<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>
这是 getevents.php 的 PHP 代码:
<?php
$db = new mysqli('localhost', 'root', '', 'calendar'); // connection to db
function formWeekDates($startDate, $endDate)
$startDay = getDay($startDate);
$endDay = getDay($endDate);
$tmp = explode('-', $startDate);
$return = array();
for($i = intval($startDay); $i <= intval($endDay); $i++)
if($i > 0 && $i < 10)
$i = '0'.$i;
$return[] = '\''.$tmp[0].'-'.$tmp[1].'-'.$i.'\'';
return $return;
function getDay($date) //$date in format 'yyyy-mm-dd'
return end(explode('-', $date));
if(isset($_POST['getEvents']) && isset($_POST['startDate']) && isset($_POST['endDate']))
$startDate = $_POST['startDate'];
$endDate = $_POST['endDate'];
$dates = implode(',', formWeekDates($startDate, $endDate));
$result = $db->query("SELECT * FROM `calendar` WHERE `date` IN ($dates)");
$return = array();
while($row = $result->fetch_assoc())
$return[] = $row;
echo json_encode($return);
// echo json_encode($dates);
?>
我还将列“日期”添加到数据库中,并以“yyyy-mm-dd”格式存储日期
附:这段代码可能有点迟钝,但它可以工作
P.S.S 我看到您想在不使用任何日期的情况下创建此日历。但我没有找到任何方法来做到这一点。您可以对用户隐藏日期并在 PHP 代码中处理它们
【讨论】:
我希望它是一个 HTML 文档,因为我希望用户编辑时间表。 好的。我会在 20 分钟内给出一个例子。 谢谢。将等待:-) 将 AJAX 查询添加到数据库中并在日历中插入事件的代码【参考方案2】:如果我了解您的目标,您需要静态周历。事件不会按日期更改,只会按日期名称更改。
所以我重写了以前的解决方案。在这个变体中形成了关联数组,其中包含当前星期的日期,键是日期的名称。可以通过日期名称访问日期,因此您不需要在数据库中存储日期 请看看这个。
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);
这是你需要的吗?还是我又犯错了?
【讨论】:
代码运行良好,但是当开始日期和结束日期在不同月份时,它会中断,您能建议可能是什么问题吗???以上是关于使用不带日期的 FullCalendar的主要内容,如果未能解决你的问题,请参考以下文章
oracle能单独存一个不带时间的日期么?或者是不带日期的时间