public static function notifyAction($object, $context) { $notificationDAO = new NotificationDAO(); $timestamp = date(DATE_FORMAT); $userLoggedFriendList = SessionUtils::getUserLoggedFriendsList(); if ($context === REGISTRATION_FORM) { $user = explode(SEPARATOR, $object); $message = DataModelUtils::getNotificationMessage($object, $context); $notificationDTO = new NotifyDTO(NULL, $user[0], 1, $message, 0, $timestamp, $context, $user[0] . SEPARATOR . $user[1]); $notificationDAO->saveNewNotification($notificationDTO); } else { if ($context === ADD_FRIEND_FORM) { $userLogged = SessionUtils::getUserLogged(); $friend = explode(SEPARATOR, $object); $message = DataModelUtils::getNotificationMessage($object, $context); $notificationDTO = new NotifyDTO(NULL, $userLogged->getUserId(), $friend[0], $message, 0, $timestamp, $context, $userLogged->getUserId() . SEPARATOR . $userLogged->getUserName() . SEPARATOR . $friend[0] . SEPARATOR . $friend[1]); $notificationDAO->saveNewNotification($notificationDTO); } else { if ($context === CONFIRM_FRIENDSHIP_FORM) { $userLogged = SessionUtils::getUserLogged(); $friend = explode(SEPARATOR, $object); $message = DataModelUtils::getNotificationMessage($object, $context, TOMYSELF); $notificationDTO = new NotifyDTO(NULL, $userLogged->getUserId(), $userLogged->getUserId(), $message, 1, $timestamp, $context, $userLogged->getUserId() . SEPARATOR . $userLogged->getUserName() . SEPARATOR . $friend[0] . SEPARATOR . $friend[1]); $result = $notificationDAO->saveNewNotification($notificationDTO); $message = DataModelUtils::getNotificationMessage($object, $context, TOMINENEWFRIEND); $notificationDTO = new NotifyDTO(NULL, $userLogged->getUserId(), $friend[0], $message, 0, $timestamp, $context, $userLogged->getUserId() . SEPARATOR . $userLogged->getUserName() . SEPARATOR . $friend[0] . SEPARATOR . $friend[1]); $result = $notificationDAO->saveNewNotification($notificationDTO); $userLoggedFriendList = SessionUtils::getUserLoggedFriendsList(); SessionUtils::prepareNotificationToFriends($object, $context, $userLoggedFriendList, $timestamp, TOMYFRIENDSLIST); $friendsDAO = new FriendsDAO(); $myfriendFriendList = $friendsDAO->getNewFriendsFriendList($userLogged->getUserId(), $friend[0]); SessionUtils::prepareNotificationToFriends($object, $context, $myfriendFriendList, $timestamp, TOMINENEWFRIENDFRIENDLIST); $message = '<a href="' . URL . PROFILE_CONTROLLER . INDEX . $userLogged->getUserId() . '"><label>' . $userLogged->getUsername() . '</label></a> ha stretto amicizia con <a href="' . URL . PROFILE_CONTROLLER . INDEX . $friend[0] . '"><label>' . $friend[1] . '</label></a>'; $adminNotificationDTO = new NotifyDTO(NULL, $userLogged->getUserId(), 1, $message, 0, $timestamp, $context, $userLogged->getUserId() . SEPARATOR . $userLogged->getUserName() . SEPARATOR . $friend[0] . SEPARATOR . $friend[1]); $notificationDAO->saveNewNotification($adminNotificationDTO); } else { $userLoggedFriendList = SessionUtils::getUserLoggedFriendsList(); SessionUtils::prepareNotificationToFriends($object, $context, $userLoggedFriendList, $timestamp); } } } }
public static function prepareNotificationToFriends($object, $context, $friendList, $timestamp, $direction = NULL, $userId = NULL) { $userLogged = SessionUtils::getUserLogged(); $notificationDao = new NotificationDAO(); if ($context !== CONFIRM_FRIENDSHIP_FORM) { $message = DataModelUtils::getNotificationMessage($object, $context, $direction); $notificationDTO = new NotifyDTO(NULL, $userLogged->getUserId(), 1, $message, 0, $timestamp, $context, $userLogged->getUserId() . SEPARATOR . $userLogged->getUserName() . SEPARATOR . $object); $result = $notificationDao->saveNewNotification($notificationDTO); } if ($friendList != null) { foreach ($friendList as $key => $friendDTO) { $message = DataModelUtils::getNotificationMessage($object, $context, $direction); if ($context === CONFIRM_FRIENDSHIP_FORM) { $friend = explode(SEPARATOR, $object); if ($direction === TOMYFRIENDSLIST) { if ($friend[0] !== $friendDTO->getFriendId()->getUserId()) { $notificationDTO = new NotifyDTO(NULL, $userLogged->getUserId(), $friendDTO->getFriendId()->getUserId(), $message, 0, $timestamp, $context, $userLogged->getUserId() . SEPARATOR . $userLogged->getUserName() . SEPARATOR . $object); $result = $notificationDao->saveNewNotification($notificationDTO); } } else { if ($direction === TOMINENEWFRIENDFRIENDLIST) { if ($friendDTO->getFriendId()->getUserId() !== $userLogged->getUserId()) { $notificationDTO = new NotifyDTO(NULL, $userLogged->getUserId(), $friendDTO->getFriendId()->getUserId(), $message, 0, $timestamp, $context, $userLogged->getUserId() . SEPARATOR . $userLogged->getUserName() . SEPARATOR . $object); $result = $notificationDao->saveNewNotification($notificationDTO); } } } } else { $notificationDTO = new NotifyDTO(NULL, $userLogged->getUserId(), $friendDTO->getFriendId()->getUserId(), $message, 0, $timestamp, $context, $userLogged->getUserId() . SEPARATOR . $userLogged->getUserName() . SEPARATOR . $object); $result = $notificationDao->saveNewNotification($notificationDTO); } } } }