【问题标题】:Laravel Livewire Detect Overlapping TimeLaravel Livewire 检测重叠时间
【发布时间】:2022-01-20 20:30:25
【问题描述】:

我目前正在尝试为 Schedule Manager 构建冲突检测功能。有冲突的日程表会有红色背景。

问题在于重叠的时间间隔,我也想将其标记为冲突。

根据下表,两个时间表应标记为红色,因为 7:00-8:30 介于 7:00-10:30 之间。

这就是我使用示例数据构建表格的方式。暂时不能重组表格。

房间|天 | c_time|

105 | MW | 7:00-8:30|

105 |W | 7:00-10:30 |

控制器

        foreach($sched->get() as $keyG=>$pG) 
        {
          $pGx=explode("-",$pG->day);

          foreach($pGx as $xKey=>$xx)
          { 
              $classDayTime[]=array('s_id'=>$pG->id,'s_day_time'=>$pGx[$xKey].$pG->c_time.$pG->room);
          }
        }                $conflictRoom=array_count_values(array_column($classDayTime,'s_day_time'));

刀片

foreach($sched->paginate(20) as $key=>$p) 
        { 
          
          $res = explode("-",str_replace([")","("],"",$p->c_time));
                ?>
                
                
               
                <tr class="
                     <?php 
                $e=explode("-",$p->day);
              
                              foreach($e as $dKey=>$d)
                              { 
                                
                                  $dt=$d.$p->c_time.$p->room;
                                  
                              foreach($$conflictRoom as $ky=>$k)
                            
                              {
                         
                                  if($dt==$ky)
                                  {
                                    if($dt==$ky)
                                  
                                         
                                      
                                          if($k != 1)
                                          {
                                           
                                    
                                            echo "divide-y dark:divide-white text-black text-s text-center bg-red-400";  
                                          }
                        
                                          else
                                          
                                          echo " ";  

                                  }     

                              }
                              }
                             
                            ?>
                ">

【问题讨论】:

    标签: laravel laravel-livewire


    【解决方案1】:

    如果你在分解提供的字符串后取 init_time 和 end_time 之类的值

    $explode_first = explode("-", "7:00-8:30");
    $first_init_time = $explode_first[0]; // "7:00" 
    $first_end_time = $explode_first[1]; // "8:30" 
    
    $explode_eval = explode("-", "7:00-10:30");
    $eval_init_time = $explode_eval[0]; // "7:00" 
    $eval_end_time = $explode_eval[1]; // "10:30" 
    
    if($eval_init_time < $first_end_time && $eval_end_time > $first_init_time)
       // it's overlaping
    
    

    在比较它们之前,您肯定必须将值转换为时间对象。

    【讨论】:

    • 感谢@Prospero,现在我到了某个地方。
    • 你能告诉我在哪里可以将它集成到我现有的代码中。
    猜你喜欢
    • 2022-06-11
    • 2021-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多