Пример #1
0
 /**
  * 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
0
 /**
  * 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');
 }