本文整理汇总了PHP中UserService::getLeaveForUser方法的典型用法代码示例。如果您正苦于以下问题:PHP UserService::getLeaveForUser方法的具体用法?PHP UserService::getLeaveForUser怎么用?PHP UserService::getLeaveForUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserService
的用法示例。
在下文中一共展示了UserService::getLeaveForUser方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: calcAction
/**
* Calculates the leave left for a given user
*/
public function calcAction()
{
$username = $this->_getParam('username');
$user = $this->userService->getUserByField('username', $username);
$type = $this->_getParam('type', 'Annual');
$validTypes = array('Annual', 'Sick', 'Long Service');
if (!in_array($type, $validTypes)) {
return;
}
if ($user == null) {
$this->log->warn("Invalid username");
echo 0;
return;
}
// Calculate how much is left
$leave = $this->userService->getLeaveForUser($user);
$accruedLeave = $this->userService->calculateLeave($user);
$leaveApplications = $this->userService->getLeaveApplicationsForUser($user);
$leaveTotal = 0;
$leaveTotals = array();
foreach ($leaveApplications as $app) {
if ($app->status == LeaveApplication::LEAVE_APPROVED) {
$current = ifset($leaveTotals, $app->leavetype, 0);
$current += $app->days;
$leaveTotals[$app->leavetype] = $current;
}
}
if ($type == 'Annual') {
echo "About " . sprintf("%d", floor($leave->days + $accruedLeave - ifset($leaveTotals, "Annual", 0))) . " days of annual leave available, " . ifset($leaveTotals, "Annual", 0) . " taken";
} else {
echo ifset($leaveTotals, $type, 0) . ' days of ' . $type . ' leave taken';
}
}
示例2: editAction
/**
* Edit a user object.
*
*/
public function editAction()
{
$id = (int) $this->_getParam('id');
$userToEdit = za()->getUser();
// If an ID is passed, we need to have a higher role than that user
// to be able to edit them an admin to be
// able to edit this user
if ($id > 0) {
$selectedUser = $this->userService->getUser($id);
// now, if the selectedUser has a role less than mine, we can
// edit them
if ($selectedUser->getRoleValue() < za()->getUser()->getRoleValue() || za()->getUser()->isPower()) {
$userToEdit = $selectedUser;
}
}
// if the user's an admin, give them the list of contacts
// to bind for this user
if (za()->getUser()->hasRole(User::ROLE_USER)) {
// get all the contacts
$this->view->contacts = $this->clientService->getContacts();
}
$this->view->leave = $this->userService->getLeaveForUser($userToEdit);
$this->view->accruedLeave = $this->userService->calculateLeave($userToEdit);
$this->view->leaveApplications = $this->userService->getLeaveApplicationsForUser($userToEdit);
$this->view->model = $userToEdit;
$this->view->themes = $this->getThemes();
$this->renderView('user/edit.php');
}