public function addNotification($toUser, $message, $action, $type)
 {
     $userEmp = new User();
     $userEmp->load("employee = ?", array($toUser));
     if (!empty($userEmp->employee) && $userEmp->employee == $toUser) {
         $toUser = $userEmp->id;
     } else {
         return;
     }
     $noti = new Notification();
     $user = $this->baseService->getCurrentUser();
     $noti->fromUser = $user->id;
     $noti->fromEmployee = $user->employee;
     $noti->toUser = $toUser;
     $noti->message = $message;
     if (!empty($noti->fromEmployee)) {
         $employee = $this->baseService->getElement('Employee', $noti->fromEmployee, null, true);
         if (!empty($employee)) {
             $fs = new FileService();
             $employee = $fs->updateEmployeeImage($employee);
             $noti->image = $employee->image;
         }
     }
     if (empty($noti->image)) {
         $noti->image = BASE_URL . "images/user_male.png";
     }
     $noti->action = $action;
     $noti->type = $type;
     $noti->time = date('Y-m-d H:i:s');
     $noti->status = 'Unread';
     $ok = $noti->Save();
     if (!$ok) {
         error_log("Error adding notification: " . $noti->ErrorMsg());
     }
 }
 public function get($req)
 {
     $employee = $this->baseService->getElement('Employee', $this->getCurrentEmployeeId(), $req->map, true);
     $subordinate = new Employee();
     $subordinates = $subordinate->Find("supervisor = ?", array($employee->id));
     $employee->subordinates = $subordinates;
     $fs = new FileService();
     $employee = $fs->updateEmployeeImage($employee);
     if (!empty($employee->birthday)) {
         $employee->birthday = date("F jS, Y", strtotime($employee->birthday));
     }
     if (!empty($employee->driving_license_exp_date)) {
         $employee->driving_license_exp_date = date("F jS, Y", strtotime($employee->driving_license_exp_date));
     }
     if (!empty($employee->joined_date)) {
         $employee->joined_date = date("F jS, Y", strtotime($employee->joined_date));
     }
     if (empty($employee->id)) {
         return new IceResponse(IceResponse::ERROR, $employee);
     }
     return new IceResponse(IceResponse::SUCCESS, $employee);
 }
Пример #3
0
 public function getLatestNotificationsAndCounts($userId)
 {
     $notification = new Notification();
     $listUnread = $notification->Find("toUser = ? and status = ?", array($userId, 'Unread'));
     $unreadCount = count($listUnread);
     $limit = $unreadCount < 10 ? 10 : $unreadCount;
     $list = $notification->Find("toUser = ? order by time desc limit ?", array($userId, $limit));
     $newList = array();
     $fs = new FileService();
     foreach ($list as $noti) {
         if ($noti->fromEmployee > 0) {
             $employee = $this->baseService->getElement('Employee', $noti->fromEmployee, null, true);
             if (!empty($employee)) {
                 $employee = $fs->updateEmployeeImage($employee);
                 $noti->image = $employee->image;
                 if (empty($noti->image)) {
                     if ($employee->gender == 'Male') {
                         $noti->image = BASE_URL . "images/user_male.png";
                     } else {
                         $noti->image = BASE_URL . "images/user_female.png";
                     }
                 }
                 $newList[] = $noti;
             }
         } else {
             $noti->image = BASE_URL . "images/icehrm.png";
             $newList[] = $noti;
         }
     }
     return array($unreadCount, $list);
 }