PHP:某些时间/日期值未被标记为冲突(大多数其他) [英] PHP: certain time/date values not being marked as conflicts (most others are though)
问题描述
总结:
我有一个应用程序在页面上有一些复选框。
用户选择所需的任何复选框,并点击提交。
I have an app with a slew of checkboxes on the page. The user selects whatever checkboxes they want, and hits submit.
我需要进行一些冲突检查。
I need to do some conflict checking.
我现在的代码状态很好,但是我发现这个逻辑似乎有一个缺陷,允许某些选择通过,而不会被注意为冲突。 (但我不清楚为什么他们正在滑倒,也不知道如何解决它)
My current state of the code is working great.. however I discovered a flaw in the logic it seems, that allows for certain 'selections' to pass through without being noted as a conflict. (but I'm not clear as to WHY they are slipping past, nor how to fix it)
技术概述:
我采取一系列提交的控件/元素,并循环执行以下操作:
I take an array of the submitted controls/elements, and loop through each one doing the following:
1)checkStartFirst()=查看哪个启动首先将两个时间的顺序排列为发送给另一个函数的参数(isConflict())
1.) checkStartFirst() = See what one starts first and arrange the order of the two 'times' as arguments sent to another function (isConflict())
2)isConflict()=接受传递给它的参数..并检查参数X的开始时间是否大于argumentY的结束时间。
然后我将这些值推送到另一个数组以供稍后使用。
2.) isConflict() = takes the arguments passed to it..and checks to see if the argumentX start time is greater than argumentY's end time. I then push these values into another array to be used later one.
3。)上述循环完成后我有另一个函数清除排除数组中的任何dups并将其传回我需要它的位置(用于突出显示冲突的前端)
3.) After the above loop is complete.. I have another function that clears out any dups in the array and passes it back where I need it to be (to be used in front end for highlighting said conflicts)
调试输出1个可疑的选择过去并且没有被标记为冲突(其他相同的日期/时间选择被标记为冲突)
debugging output for 1 of the questionable selections that slips past and doesnt get marked as a conflict, (where other same date/time selection DO get flagged as a conflict)
发送:hours_9_7_reg_session_101_945_1005 /
hours_9_7_reg_session_102_945_1005
Sending: hours_9_7_reg_session_101_945_1005 / hours_9_7_reg_session_102_945_1005
收到付款:hours_9_7_reg_session_101_945_1005 /
hours_9_7_reg_session_102_945_1005
Received for checking: hours_9_7_reg_session_101_945_1005 / hours_9_7_reg_session_102_945_1005
B :CHECKING:hours_9_7_reg_session_102_945_1005 [结束:09/07/2015
10:05]> hours_9_7_reg_session_101_945_1005 [开始:09/07/2015 9:45]
B: CHECKING: hours_9_7_reg_session_102_945_1005 [end: 09/07/2015 10:05] > hours_9_7_reg_session_101_945_1005 [start: 09/07/2015 9:45]
由于它是一个循环,它再次被检查(其他方式)
Since it is in a loop, it gets checked again (other way)
发送:hours_9_7_reg_session_102_925_945 /
hours_9_7_reg_session_101_945_1005
Sending: hours_9_7_reg_session_102_925_945 / hours_9_7_reg_session_101_945_1005
已收到检查:hours_9_7_reg_session_102_925_945 /
hours_9_7_reg_session_101_945_1005
Received for checking: hours_9_7_reg_session_102_925_945 / hours_9_7_reg_session_101_945_1005
A:CHECKING:hours_9_7_reg_session_102_925_945 [end:09/07/2015 9:45]>
hours_9_7_reg_session_101_945_1005 [开始:09/07/2015 9:45] / p>
A: CHECKING: hours_9_7_reg_session_102_925_945 [end: 09/07/2015 9:45] > hours_9_7_reg_session_101_945_1005 [start: 09/07/2015 9:45]
(再次滑过)
我的PHP功能..从调用setConflicts()
My PHP functions.. starts with calling setConflicts()
//new (proposed) session conflicts checker
function checkStartFirst($cf_presX, $cf_presY) {
//$cf_presX['fullStart'] < $cf_presY['fullStart'] ? $this->isConflict($cf_presX, $cf_presY) : $this->isConflict($cf_presY, $cf_presX);
echo 'Received for checking: '. $cf_presX['id'] . ' / ' . $cf_presY['id'] .'<br>';
if($cf_presX['fullStart'] < $cf_presY['fullStart']){
echo 'A: ';
$this->isConflict($cf_presX, $cf_presY);
}else{
echo 'B: ';
$this->isConflict($cf_presY, $cf_presX);
}
}
function isConflict ($cc_presX, $cc_presY) {
echo 'CHECKING: ' . $cc_presX['id'] .' [end: ' . $cc_presX['fullEnd'] . '] > ' . $cc_presY['id'] .' [start: ' . $cc_presY['fullStart'] . ']';
if ($cc_presX['fullEnd'] > $cc_presY['fullStart']) {
echo ' -- has conflict <br>';
array_push($this->conflict_output, $cc_presX['id']);
array_push($this->conflict_output, $cc_presY['id']);
//echo 'Found Conflict: ' . $cc_presX['id'] . ' / ' . $cc_presY['id'] . '<br>';
}else{
//only here for debugging readability
echo '<br>';
}
}
function setConflicts() {
$presentations = $this->conflict_list;
for ($i = 0; $i < count($presentations); $i++) {
for ($j = 0; $j < count($presentations); $j++) {
// if it is not the same event
if ($presentations[$i]['id'] != $presentations[$j]['id']) {
echo '<br><br>Sending: '.($presentations[$i]['id'] .' / '. $presentations[$j]['id']) .'<br>';
$this->checkStartFirst($presentations[$i], $presentations[$j]);
}else{
echo '<br><br><br>same session, do not check: ' . ($presentations[$i]['id'] .' / '. $presentations[$j]['id']) . '<br><br><br>';
}
}
}
$this->getConflicts();
}
function getConflicts(){
$presentations = $this->conflict_output;
//remove duplicates in array & re-key (sequentially)
$uniquePresentations = array_unique($presentations);
//re-key array using sequential index #'s
$uniquePresentations = array_values($uniquePresentations);
if(count($uniquePresentations) > 0){
//save conflict (names) to array
$this->conflict_return = $uniquePresentations;
$this->errmsg = 'Please review the form for errors, there are conflicts in the highlighted sessions below. (Possible duplicate or overlapping session times have been selected.) <br>You can not proceed until all conflicts are resolved.';
}
}
上面的blockquote中的代码/时间选择如何正在滑倒过去?哪里有别的 - 被标记?
How can the code/time selections in the blockquote above be slipping past? Where as others -do- get flagged?
我不知道我是否需要收紧某些条件或某事?
I'm not sure if I need to tighten up some conditionals or something?
推荐答案
解决方案(错误)比我预想的容易一些。
Well the solution (error) was easier than I expected.
基本上我正在检查日期/时间戳..我需要确保我正在将它们转换为一个strtotme()值...将对象/数组中的值作为字符串来处理。
Basically anywhere I am checking the date/time stamps.. I need to make sure I am casting/converting them to a strtotme() value ... as pulling the value out of the object/array it is treated as a string.
为什么每隔一个时间冲突检查工作没有问题..我不知道。 LOL
Why every other time conflict checking worked without issue.. I dont know. LOL
但是这样做可以解决我的问题:
But doing this fixed my problems:
if(strtotime($cf_presX['fullStart']) < strtotime($cf_presY['fullStart'])){
if (strtotime($cc_presX['fullEnd']) > strtotime($cc_presY['fullStart'])) {
这篇关于PHP:某些时间/日期值未被标记为冲突(大多数其他)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!