我的功能为您提供了更新。这现在也可以正常工作,但我需要它来计算出完全生病的情况,根据他们在生病第一天之前的服务年限。希望我已经说清楚了。我已经标记了解决我生病的代码行,但我一直只给我一个,即使我知道那个选定的用户还有更多年的时间。
请帮忙?
格伦·柯蒂斯
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 {*/
//Get the user sick days
$userSickDays = $this->Holiday->find(
'all',
array(
'conditions' => array(
'Holiday.holidaystype_id' => 3,
'Holiday.user_id' => $id
),
'order' => 'Holiday.startson ASC'
));
//Get years of service
$userContracts = $this->Holiday->User->Contract->find(
'all',
array(
'conditions' => array( 'Contract.user_id' => $id), //$data['user_id']),
'order' => array( 'Contract.startson' => 'ASC' )
));
//Loop through the user's sick days
foreach ($userSickDays as $k => $sickDay) {
//Get number of days in the current sick day
$totSickdays = $this->Holiday->getNumberDaysFromHoliday($sickDay['Holiday']['id']);
//Get number of sick days for the past 12 months
if($k > 0) {
for($i=0; $i<$k; $i++) {
if((strtotime(gmdate("Y-m-d", $sickDay['Holiday']['startson'])." -1 year GMT")) <= $userSickDays[$i]['Holiday']['startson']) {
$totSickdays += $this->Holiday->getNumberDaysFromHoliday($userSickDays[$i]['Holiday']['id']);
}
}
}
foreach ($userContracts as $y => $contract) {
THIS LINE HERE->$yearsService = $contract['Contract']['startson'] <= $sickDay['Holiday']['startson'];
if ($contract['Contract']['startson'] <= $sickDay['Holiday']['startson']) {
if ($yearsService <= 1) {
$entitlement = 10;
$remaingDays = $entitlement - $totSickdays;
//echo 'one year';
} elseif ($yearsService <= 2) {
$entitlement = 20;
$remaingDays = $entitlement - $totSickdays;
//echo 'two years';
} elseif ($yearsService <= 4) {
$entitlement = 40;
$remaingDays = $entitlement - $totSickdays;
//echo 'up to five years';
} elseif ($yearsService >= 5) {
$entitlement = 60;
$remaingDays = $entitlement - $totSickdays;
//echo 'five years or more';
} else {
$entitlement = 0;
$remaingDays = 0;
//echo 'no sick pay';
}
} //End of if statement.
} //End of $userContracts Foreach Loop
debug($yearsService);
} //End of Foreach Loop
//$this->render('/artists/holidayslist');
//} //End For if empty check
} // End for if CURRENT_USER
die();
} //End of Function
下面的旧帖子
现在我以前曾就此寻求过帮助,但这超出了我职能的一个选定区域,以获得病假天数。现在可以了,我在我正在处理的网站中找到了一个为我构建的功能。所以我在数据库中输入了病假总数。现在我似乎无法弄清楚为什么我不能将其设置为我多年的服务。
为了让我自己更清楚,这个功能的结果是检查当前用户在选定的一年内生病。但到一年,约定的一年,例如可能到可能。
这就是为什么我有许多 if 语句来设置用户权利,因为它会根据服务年限而改变。然后,当设置好之后,取消用户在该合同年度内休的病假。
我希望我已经解释了我想做什么,如果不清楚,请告诉我,我会尝试更详细地解释。
请帮助,这是为 CakePHP 项目中使用的页面编写的。
非常感谢
格伦·柯蒂斯
function sickDay($id = null) {
if($this->CURRENT_USER['User']['role_id'] > 3) { //directors and admins
//Caculate if it's a full pay, half pay or nothing
//$data = $this->data['Holiday'];
//Get Holidaytypes
$userSickDays = $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'
)
)
);
$start = array_shift($contracts);
$end = array_pop($contracts);
$endDate = $end['Contract']['endson'];
$startDate = $start['Contract']['startson'];
if (empty($endDate)) { $endDate = time('now'); }
$SortEnd = strftime("%Y", $endDate);
$SortStart = strftime("%Y", $startDate);
$YearsService = $SortEnd - $SortStart;
//Get How Many sick days
foreach ($userSickDays as $sickDay) {
$typesDataEnds = strtotime($sickDay['Holiday']['endson']);
$typesDataStarts = $sickDay['Holiday']['startson'];
$DateNow = date('U', strtotime('Now'));
$GetSickDays = $this->Holiday->getNumberDaysFromHoliday($sickDay['Holiday']['id']);
$TotalSick += $GetSickDays;
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';
}
}
//$this->render('/artists/holidayslist');
} // End for if CURRENT_USER
die();
} //End of Function