我有一个基于网站管理员打开的门票的日历。我们有四种票:
这是我拥有日历的div
:
<div class="col-lg-6 col-md-10 col-sm-11">
<div class="card">
<div class="card-header" data-background-color="blue">
<h4 class="title">Calendario</h4>
</div>
<br>
<section class="content">
<?php
$events = TicketData::getEvents();
foreach($events as $event){
$thejson[] = array("title"=>$event->title,"url"=>"./?view=editticket&id=".$event->id,"start"=>$event->date_at."T".$event->time_at);
}
// print_r(json_encode($thejson));
?>
<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next, today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultDate: jQuery.now(),
editable: false,
eventLimit: true, // allow "more" link when too many events
events: <?php echo json_encode($thejson); ?>
});
});
</script>
<div class="row">
<div class="col-md-12">
<div id="calendar">
</div>
</div>
</div>
</section>
</div>
</div>
故障单的数据库结构很简单:id
,title
,description
,date_at
,time_at
,created_at
,{{ 1}}和tecnico_id
。
我想&#34;着色&#34;使用if脚本的事件:
这是我的代码,但它不起作用。
status_id
This is the calendar generated. These are the colors.
我想让它们与颜色标准相匹配,因此用户可以了解哪些票据是待处理的,不完整的,完整的和取消的。 我是javascript的新手,我不知道如何做到这一点。你们能帮助我或指出我应该怎么做吗?
答案 0 :(得分:2)
您可以在迭代事件数组时设置颜色:
<?php
// helper function to pick the right color
function getColor($id) {
$eventColor = '';
if ($id == 1) {
$eventColor = '#fb8c00';
} else if ($id == 2) {
$eventColor = '#ff0';
} else if ($id == 3) {
$eventColor = '#43a047';
} else {
$eventColor = '#00acc1';
}
return $eventColor;
}
$events = TicketData::getEvents(); //pulls the events from TicketData.php
foreach($events as $event) {
$thejson[] = array(
"title" => $event->title,
"url" => "./?view=editticket&id=".$event->id,
"start" => $event->date_at."T".$event->time_at,
"color" => getColor($event->status_id));
}
?>
然后回复你现在正在做的事件:
<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next, today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultDate: jQuery.now(),
editable: false,
eventLimit: true, // allow "more" link when too many events
events: <?php echo json_encode($thejson); ?>,
});
});
</script>