PHP:某些 time/date 值未被标记为冲突(但大多数其他值是)
PHP: certain time/date values not being marked as conflicts (most others are though)
总结:
我有一个页面上有大量复选框的应用程序。
用户选择他们想要的任何复选框,然后点击提交。
我需要做一些冲突检查。
我当前的代码状态运行良好。但是我发现它似乎在逻辑中存在缺陷,它允许某些 'selections' 通过而不会被标记为冲突。 (但我不清楚为什么他们会溜走,也不清楚如何解决)
技术概述:
我获取提交的数组 controls/elements,并循环执行以下操作:
1.) checkStartFirst() = 查看哪个先开始,然后安排两个 'times' 作为参数发送到另一个函数 (isConflict())
2.) isConflict() = 获取传递给它的参数..并检查参数 X 的开始时间是否大于参数 Y 的结束时间。
然后我将这些值推入另一个数组以备后用。
3.) 上面的循环完成后..我有另一个函数清除数组中的所有重复项并将其传递回我需要的地方(用于前端突出显示所述冲突)
调试 1 个有问题的选择的输出,这些选择被忽略并且没有被标记为冲突,(其他相同的 date/time 选择确实被标记为冲突)
Sending: 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 [end: 09/07/2015
10:05] > hours_9_7_reg_session_101_945_1005 [start: 09/07/2015 9:45]
因为它在循环中,它会再次检查(其他方式)
Sending: 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 [start: 09/07/2015 9:45]
(再次,溜过去)
我的 PHP 函数..从调用 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 中的 code/time 选项怎么会被忽略?其他人在哪里被标记?
我不确定我是否需要收紧一些条件或其他东西?
好吧,解决方案(错误)比我预期的要容易。
基本上在我检查 date/time 邮票的任何地方.. 我需要确保我 casting/converting 他们的 strtotme() 值...从 [= 中提取值21=] 它被视为一个字符串。
为什么每次冲突检查都没有问题。我不知道。哈哈
但是这样做解决了我的问题:
if(strtotime($cf_presX['fullStart']) < strtotime($cf_presY['fullStart'])){
if (strtotime($cc_presX['fullEnd']) > strtotime($cc_presY['fullStart'])) {
总结:
我有一个页面上有大量复选框的应用程序。 用户选择他们想要的任何复选框,然后点击提交。
我需要做一些冲突检查。
我当前的代码状态运行良好。但是我发现它似乎在逻辑中存在缺陷,它允许某些 'selections' 通过而不会被标记为冲突。 (但我不清楚为什么他们会溜走,也不清楚如何解决)
技术概述:
我获取提交的数组 controls/elements,并循环执行以下操作:
1.) checkStartFirst() = 查看哪个先开始,然后安排两个 'times' 作为参数发送到另一个函数 (isConflict())
2.) isConflict() = 获取传递给它的参数..并检查参数 X 的开始时间是否大于参数 Y 的结束时间。 然后我将这些值推入另一个数组以备后用。
3.) 上面的循环完成后..我有另一个函数清除数组中的所有重复项并将其传递回我需要的地方(用于前端突出显示所述冲突)
调试 1 个有问题的选择的输出,这些选择被忽略并且没有被标记为冲突,(其他相同的 date/time 选择确实被标记为冲突)
Sending: 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 [end: 09/07/2015 10:05] > hours_9_7_reg_session_101_945_1005 [start: 09/07/2015 9:45]
因为它在循环中,它会再次检查(其他方式)
Sending: 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 [start: 09/07/2015 9:45]
(再次,溜过去)
我的 PHP 函数..从调用 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 中的 code/time 选项怎么会被忽略?其他人在哪里被标记?
我不确定我是否需要收紧一些条件或其他东西?
好吧,解决方案(错误)比我预期的要容易。
基本上在我检查 date/time 邮票的任何地方.. 我需要确保我 casting/converting 他们的 strtotme() 值...从 [= 中提取值21=] 它被视为一个字符串。
为什么每次冲突检查都没有问题。我不知道。哈哈
但是这样做解决了我的问题:
if(strtotime($cf_presX['fullStart']) < strtotime($cf_presY['fullStart'])){
if (strtotime($cc_presX['fullEnd']) > strtotime($cc_presY['fullStart'])) {