dongpo0409 2015-06-26 00:02
浏览 31

AJAX disabledDates Fullcalendar计算机/用户

i have multiple jquery fullcalendars on a page which is used for machine scheduling in our software. each calender will make a ajax call once a specific input for the workload changes. In my AJAX script i need to calculate the dates that will be disabled in the calendar based upon the already planned time of the machine and whether or not there are workers with enough time avail on that day.

so here is what i got so far:

$retval = Array();
$objectid = $_REQUEST["objectid"];
$type = $_REQUEST["type"];
$amount = $_REQUEST["amount"];
$date = $_REQUEST["date"];
$month = date("m",strtotime($date));
$year = date("Y",strtotime($date));
if ($month == date("m") && $year == date("Y"))
{
    $start = mktime(0,0,0,date("m"),date("d"),date("Y"));
} else {
    $mktime1 = mktime(0,0,0,$month,24,$year);
    $start = strtotime('-1 month',$mktime1);
}
$mktime2 = mktime(0,0,0,$month,6,$year);
$end = strtotime('+2 month',$mktime2);



$job_arr = Array();
$jobs = PlanningJob::getAllJobs(" AND start>".$start." AND end<".$end);
foreach ($jobs as $job)
{
    $date = mktime(0,0,0,date("m",$job->getDate()),date("d",$job->getDate()),date("Y",$job->getDate()));
    $job_arr[$date] = 0;
    if ($job->getTime()>0)
        $job_arr[$date] += $job->getTime();
    elseif ($job->getPlannedTime()>0)
        $job_arr[$date] += $job->getPlannedTime();
}

if ($type == "ME"){
    $me = new Machineentry($objectid);
    $machine = $me->getMachine();
    for ( $i = $start; $i <= $end; $i = $i + 86400 ) {
        $date = mktime(0,0,0,date("m",$i),date("d",$i),date("Y",$i));
        $total_seconds = $machine->getRunningtimeForDay($date);
        if (isset($job_arr[$date]))
        {
            $total_seconds -= ($job_arr[$date]*60*60);
        }
        if ($total_seconds < ($amount*60*60))
            $retval[] = date("d.m.Y",$date);
    }
} else if ($type == "OP")
{
    $op = new Orderposition($objectid);
    $jobart = new Article($op->getObjectid());
}

now i wonder if there is a better approach to calculating for so many dates (date range) at once - performance wise. as this one is quite heavy and takes a couple of seconds which really slows down our scheduling process.

i would appreciate any help/advice!

Kind Regards,

Alex

[EDIT] some more info's on what i need to output:

One Array containing: all dates within the range
and within this array per date:
1. all users having spare time on that day and the specific amount of time
2. total time scheduled on the machine that day

Second Array
Per date: if not enough 'free' time on the machine only the date so it can be disabled in the calendar

  • 写回答

1条回答 默认 最新

  • dssk35460 2015-06-26 00:11
    关注

    Here is a function I wrote a while back which will take two dates and return an array of the range between them. I use this function on a variety of things and it's very fast.

    Dates provided for $dateFrom and $dateTo should be in YYYY-MM-DD format.

    function createDateRangeArray($dateFrom,$dateTo)
    {
        $arrayRange=array();
    
        $dateFrom=mktime(1,0,0,substr($dateFrom,5,2), substr($dateFrom,8,2),substr($dateFrom,0,4));
        $dateTo=mktime(1,0,0,substr($dateTo,5,2), substr($dateTo,8,2),substr($dateTo,0,4));
    
        if ($dateTo>=$dateFrom)
        {
            array_push($arrayRange,date('Y-m-d',$dateFrom));
            while ($dateFrom<$dateTo)
            {
                $dateFrom+=86400;
                array_push($arrayRange,date('Y-m-d',$dateFrom));
            }
        }
        return $arrayRange;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思