我对 PHP 非常陌生,对 CakePHP 更陌生,这是我编写代码的目的,但我认为我的问题出在我的一些标准 PHP 代码上。
好的,现在这段代码大部分都在工作,但是当我选择的用户同时使用一天以上时,它似乎给了我一个错误的结果!
好的,所以它的意思是为选定的用户获得多年的服务,它确实可以(我认为,至少没有问题)。然后根据服务年限,我根据服务年限设置病假权利,全天和半天。
一旦我完成了代码应该让选定的用户生病,然后取消他们已经获得的权利,第一次是完整的,然后当它是空的时,把它从一半拿走。但是就像我说的,当用户连续休一天以上时,它仍然只休一天吗?
这可能是我开始我的 foreach 循环并进行计数的地方,不确定这是否正确?
请帮忙??
function sickDay($id = null) {
if($this->CURRENT_USER['User']['role_id'] > 3) { //directors and admins
/*if(empty($this->data) || !isset($this->data['Holiday']['id'])) {
} else {*/
//Caculate if it's a full pay, half pay or nothing
//$data = $this->data['Holiday'];
//Get Holidaytypes
$types = $this->Holiday->find(
'all',
array(
'conditions' => array(
'Holiday.holidaystype_id' => 3,
'Holiday.user_id' => $id
)
)
);
//Get starting date
$contracts = $this->Holiday->User->Contract->find(
'all',
array(
'conditions' => array(
'Contract.user_id' => $id //$data['user_id']
),
'order' => array(
'Contract.startson' => 'ASC'
)
)
);
//Get How Many sick days
foreach ($types as $key => $value) {
$typesDataEnds = strftime ("%u-%d-%Y", $types[$key]['Holiday']['endson']);
$typesDataStarts = strftime ("%u-%d-%Y", $types[$key]['Holiday']['startson']);
$SickTotal = count($typesDataEnds - $typesDataStarts);
//echo $SickTotal;
//Get Contract Start & End Dates
$start = array_shift($contracts);
$end = array_pop($contracts);
$endDate = $end['Contract']['endson'];
$startDate = $start['Contract']['startson'];
if (empty($endDate)) {
$endDate = time('now');
}
if (!empty($startDate)) {
$SortEnd = strftime("%Y", $endDate);
$SortStart = strftime("%Y", $startDate);
$YearsService = $SortEnd - $SortStart;
if ($YearsService <= 1) {
$SetFullEntitlement = 5;
$SetHalfEntitlement = 5;
//echo 'one year';
} elseif ($YearsService <= 2) {
$SetFullEntitlement = 10;
$SetHalfEntitlement = 10;
//echo 'two years';
} elseif ($YearsService <= 5) {
$SetFullEntitlement = 20;
$SetHalfEntitlement = 20;
//echo 'up to five years';
} elseif ($YearsService >= 6) {
$SetFullEntitlement = 30;
$SetHalfEntitlement = 30;
//echo 'five years or more';
} else {
$SetFullEntitlement = 0;
$SetHalfEntitlement = 0;
//echo 'no sick pay';
}
} else {
$YearsService = 0;
//echo 'Sorry No Start Date For You Found!';
}
while ($SickTotal > 0) {
if ($SetFullEntitlement != 0) {
$SetFullEntitlement--;
} elseif ($SetHalfEntitlement != 0) {
$SetHalfEntitlement--;
}
$SickTotal--;
}
echo 'FullPay:';
echo $SetFullEntitlement;
echo '<br/><br/>Halfpay:';
echo $SetHalfEntitlement;
}
//debug($SickTotal);
die();
//$this->render('/artists/holidayslist');
//} //End For if empty check
} // End for if CURRENT_USER
} //End of Function
更新
我理解你所说的,是的,我现在知道 %u 用于我需要它做的事情是错误的。现在我已经按照你说的做了,但是我为选定的用户返回 0,我知道应该有两个?
foreach ($types as $key => $value) {
$typesDataEnds = strtotime($types[$key]['Holiday']['endson']);
$typesDataStarts = strtotime($types[$key]['Holiday']['startson']);
//$typesDataEnds = strftime ("%Y-%m-%d", $types[$key]['Holiday']['endson']);
//$typesDataStarts = strftime ("%Y-%m-%d", $types[$key]['Holiday']['startson']);
$sickTotal = floor(($typesDataEnds - $typesDataStarts) / 86400);
echo 'testing: ';
debug($sickTotal);
die();
does more.....
} //end
我做错了什么吗?
非常感谢您的帮助
格伦。