예제 #1
0
 public function addNotification($toUser, $message, $action, $type)
 {
     $profileVar = SIGN_IN_ELEMENT_MAPPING_FIELD_NAME;
     $profileClass = ucfirst(SIGN_IN_ELEMENT_MAPPING_FIELD_NAME);
     $userEmp = new User();
     $userEmp->load("profile = ?", array($toUser));
     if (!empty($userEmp->{$profileVar}) && $userEmp->{$profileVar} == $toUser) {
         $toUser = $userEmp->id;
     } else {
         return;
     }
     $noti = new Notification();
     $user = $this->baseService->getCurrentUser();
     $noti->fromUser = $user->id;
     $noti->fromProfile = $user->{$profileVar};
     $noti->toUser = $toUser;
     $noti->message = $message;
     if (!empty($noti->fromProfile)) {
         $profile = $this->baseService->getElement($profileClass, $noti->fromProfile, null, true);
         if (!empty($profile)) {
             $fs = new FileService();
             $profile = $fs->updateProfileImage($profile);
             $noti->image = $profile->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) {
         LogManager::getInstance()->info("Error adding notification: " . $noti->ErrorMsg());
     }
 }