Although i have found some general answers to my question, i couldn't find any which solves my specific problem.
虽然我已经找到了一些我的问题的一般答案,但我找不到任何解决我的具体问题的方法。
I have developed a backend for some users, where they can view/edit the availability of their hotel rooms for the whole selected year. I am using HTML/PHP/MySQL to display the availability values of the year they want. There are 365 inputs in this form (each input represents a single day. That means that there are 365 inputs, depending on the selected year). Then i use the daterangepicker jQuery plugin, so he can selecte date ranges and change the availability values. They can only view/edit availabilities for the current and the next year.
我为一些用户开发了一个后端,他们可以查看/编辑整个选定年份的酒店房间的可用性。我正在使用HTML / PHP / MySQL来显示他们想要的年份的可用性值。这种形式有365个输入(每个输入代表一天。这意味着有365个输入,具体取决于所选的年份)。然后我使用daterangepicker jQuery插件,这样他就可以选择日期范围并更改可用性值。他们只能查看/编辑当前和下一年的可用性。
I let them switch from current year to next year and backwards with this code:
我让他们从当前年份切换到明年,并使用以下代码向后切换:
<a class="btn btn-primary" href="https://domain.com/backend/availability/edit_availability/11/0">2016</a>
<a class="btn btn-default" href="https://domain.com/backend/availability/edit_availability/11/1">2017</a>
For the record, i check the last href parameter to understand the selected year. Current year is /0 and next year is /1. I want to display only current and next year.
为了记录,我检查最后一个href参数以了解所选年份。当前年份为/ 0,明年为/ 1。我想只显示当前和明年。
With the below code they select a date range, set the availability number and 'Fill' the calendar with the given availability number:
使用以下代码,他们选择日期范围,设置可用性编号,并使用给定的可用性编号“填充”日历:
<input id="availability_dates" class="form-control" type="text" required="required" value="" name="availability_dates">
<input id="availability_number" class="form-control col-md-7 col-xs-12" type="text" name="availability_number">
<button id="fill-availabilities" class="btn btn-success" type="submit">Fill</button>
<script>
$('#availability_dates').daterangepicker(
{
format: 'DD/MM/YYYY'
}, function (start, end, label) {
console.log(start.toISOString(), end.toISOString(), label);
});
</script>
I grab his desired year like this:
我像这样抓住他想要的一年:
<?php
if ($year == '0') {
$display_year = date('Y');
$other_year = date('Y', strtotime('+1 year'));
} else {
$display_year = date('Y', strtotime('+1 year'));
$other_year = date('Y');
}
?>
Anyway, that's a sort briefing. What i am trying to do is, set the minimum and maximum dates to the daterangepicker just for the selected year. If they view 2016, i want to limit the daterangepicker to 1st of January - 31st December of 2016 only. Same for the next year 2017 and so on.
无论如何,这是一个简短的介绍。我想要做的是,为所选年份设置daterangepicker的最小和最大日期。如果他们查看2016年,我想将daterangepicker限制为2016年1月1日至12月31日。明年2017年相同,依此类推。
As you can see, years are grabbed dynamically, so i need a "script" where the daterangepicker will work even if we are in 2018 or 2020 etc.
正如你所看到的,动态抓住了几年,所以我需要一个“脚本”,即使我们在2018年或2020年等,daterangepicker仍然有效。
I'm sorry for the long post, i've tried to explain a lot more than needed in case someone has a better solution/idea.
对于这篇长篇文章我很抱歉,如果有人有更好的解决方案/想法,我试图解释的不仅仅是需要的。
Thank you in advance
先谢谢你
1 个解决方案
#1
1
I personally would recommend you using some sort of library for that. Usually is a mess to manually do that (in my personal experience) and the libraries available are usually quite good.
我个人会建议你使用某种类型的库。通常手动执行此操作(根据我的个人经验)并且可用的库通常非常好。
#1
1
I personally would recommend you using some sort of library for that. Usually is a mess to manually do that (in my personal experience) and the libraries available are usually quite good.
我个人会建议你使用某种类型的库。通常手动执行此操作(根据我的个人经验)并且可用的库通常非常好。