首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PHP:某些时间/日期值没有被标记为冲突(但大多数其他值是冲突)

PHP:某些时间/日期值没有被标记为冲突(但大多数其他值是冲突)
EN

Stack Overflow用户
提问于 2015-11-04 19:01:35
回答 1查看 76关注 0票数 1

摘要:

我有一个应用程序,在页面上有大量的复选框。用户选择他们想要的任何复选框,然后点击submit。

我需要做一些冲突的检查。

我目前的代码状态很好。然而,我发现了逻辑上的一个缺陷,它允许某些“选择”通过,而不被认为是冲突。(但我不清楚他们为什么要溜走,也不知道如何解决)

技术概述:

我接受一个已提交控件/元素的数组,并遍历每个控件/元素,执行以下操作:

1.)checkStartFirst() =查看首先启动的是什么,并将两个“时间”的顺序安排为发送给另一个函数的参数(isConflict())

2.)isConflict() =接受传递给it..and的参数,以查看argumentX启动时间是否大于argumentY的结束时间。然后,我将这些值推入另一个数组中,以便稍后使用。

3.)在上面的循环完成之后。我有另一个函数,它清除数组中的任何陷阱,并将其传回我需要的位置(用于突出显示所述冲突的前端)。

调试一个有问题的选项的输出,这些选项在过去时没有被标记为冲突(其他相同日期/时间的选择确实被标记为冲突)。

发送: 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 B:检查: hours_9_7_reg_session_102_945_1005结束: 09/07/2015 10:05 > hours_9_7_reg_session_101_945_1005 start: 09/07/2015 9:45

因为它在循环中,所以会再次检查它(另一种方式)

发送: 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 A:检查: hours_9_7_reg_session_102_925_945结束: 09/07/2015 9:45 > hours_9_7_reg_session_101_945_1005 start: 09/07/2015 9:45

(再一次,滑过)

我的PHP函数。从调用setConflicts()开始

代码语言:javascript
运行
复制
//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.';    
    }       
}

上述区块引号中的代码/时间选择是如何滑过的?像其他人一样被标记在哪里?

我不确定我是否需要收紧一些条件什么的?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-05 20:19:16

这个解决方案(错误)比我预期的要容易。

基本上在我查日期/时间戳的任何地方。我需要确保我正在将它们转换为strtotme()值.当将值从对象/数组中提取出来时,它将被视为字符串。

为什么每隔一次冲突检查都是没有问题的。我不知道。LOL

但这样做解决了我的问题:

代码语言:javascript
运行
复制
if(strtotime($cf_presX['fullStart']) < strtotime($cf_presY['fullStart'])){


if (strtotime($cc_presX['fullEnd']) > strtotime($cc_presY['fullStart'])) {
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33529964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档