예제 #1
0
 public function unlike($type, $id)
 {
     $type = $this->str($type);
     $user = Auth::user();
     $like = $this->get($type, $id, $user->id);
     if ($like) {
         if ($like->delete()) {
             $object = strtolower($type);
             State::whereRaw('object=? and object_id=? and event=\'liked\'', array($object, $id))->delete();
             Notification::whereRaw('object=? and object_id=? and event=\'liked\'', array($object, $id))->get()->each(function ($notification) use($user) {
                 NotificationUser::whereRaw('notification_id=? and user_id=?', array($notification->id, $user->id))->get()->each(function ($notificationsUser) {
                     $notificationsUser->is_removed = 1;
                     $notificationsUser->save();
                 });
                 $notification->is_removed = 1;
                 $notification->save();
             });
             Notification::whereRaw('object=? and event=\'liked\' and is_removed=0 and ' . '(select count(nu.id) from notifications_users nu where nu.notification_id=notifications.id and nu.is_removed=0)=0', array($object))->get()->each(function ($notification) {
                 $notification->is_removed = 1;
                 $notification->save();
             });
             return $this->respondNoContent();
         }
     } else {
         return $this->respondNotFound('Like not found');
     }
     return $this->respondServerError();
 }
예제 #2
0
 private function translateStatesToNotifications($states)
 {
     $data = array();
     foreach ($states as $state) {
         $key = implode(';', array($state->owner_id, $state->object, $state->object_id, $state->event));
         if (!isset($data[$key])) {
             $notification = new Notification();
             $notification->owner_id = $state->owner_id;
             $notification->object = $state->object;
             $notification->object_id = $state->object_id;
             $notification->event = $state->event;
             $notification->timestamp = $state->timestamp;
             $data[$key] = array('notification' => $notification, 'users' => array());
         } else {
             $data[$key]['notification']->timestamp = $state->timestamp;
         }
         $notificationUser = new NotificationUser();
         $notificationUser->subject_id = $state->subject_id;
         $notificationUser->user_id = $state->user_id;
         $notificationUser->timestamp = $state->timestamp;
         if ($state->object == 'post') {
             if ($state->event == 'commented') {
                 $notificationUser->subject = 'comment';
             } else {
                 if ($state->event == 'liked') {
                     $notificationUser->subject = 'like';
                 }
             }
         } else {
             if ($state->object == 'comment') {
                 if ($state->event == 'liked') {
                     $notificationUser->subject = 'like';
                 }
             }
         }
         $data[$key]['users'][] = $notificationUser;
         $this->info("Notification:");
         $this->info("Notification Subject: {$notificationUser->subject_id}");
         $this->info("Notification User: {$notificationUser->user_id}");
         $this->info("Notification Timestamp: {$notificationUser->timestamp}");
     }
     foreach ($data as $notification) {
         $notification['notification']->save();
         foreach ($notification['users'] as $notificationUser) {
             $notificationUser->notification_id = $notification['notification']->id;
             $notificationUser->save();
         }
     }
 }
예제 #3
0
         if ($evaluation["request_timeout"]) {
             $PROCESSED_REQUEST["request_expires"] = time() + $evaluation["request_timeout"] * 60;
         } else {
             $PROCESSED_REQUEST["request_expires"] = 0;
         }
         $PROCESSED_REQUEST["evaluation_id"] = $RECORD_ID;
         $PROCESSED_REQUEST["proxy_id"] = $ENTRADA_USER->getId();
         $PROCESSED_REQUEST["target_proxy_id"] = $associated_evaluator;
         $PROCESSED_REQUEST["request_created"] = time();
         $PROCESSED_REQUEST["request_fulfilled"] = 0;
         if ($db->AutoExecute("evaluation_requests", $PROCESSED_REQUEST, "INSERT") && ($request_id = $db->Insert_Id())) {
             require_once "Models/notifications/Notification.class.php";
             require_once "Models/notifications/NotificationUser.class.php";
             $notification_user = NotificationUser::get($associated_evaluator, "evaluation_request", $RECORD_ID, $ENTRADA_USER->getId());
             if (!$notification_user) {
                 $notification_user = NotificationUser::add($associated_evaluator, "evaluation_request", $RECORD_ID, $ENTRADA_USER->getId());
             }
             if (Notification::add($notification_user->getID(), $ENTRADA_USER->getId(), $RECORD_ID)) {
                 $notifications_sent++;
             } else {
                 add_error("An issue was encountered while attempting to send a notification to a user [" . get_account_data("wholename", $associated_evaluator) . "] requesting that they complete an evaluation [" . $evaluation_title . "] for you. The system administrator has been notified of this error, please try again later.");
                 application_log("Unable to send notification requesting an evaluation be completed to evaluator [" . $associated_evaluator . "] for evaluation_id [" . $RECORD_ID . "].");
             }
         } else {
             add_error("Unable to create a request entry for this evaluation. The system administrator was notified of this error; please try again later.");
             application_log("Unable to create a request entry for this evaluator [" . $associated_evaluator . "] for evaluation_id [" . $RECORD_ID . "]. Database said: " . $db->ErrorMsg());
         }
     } else {
         add_error("The selected evaluator [" . get_account_data("wholename", $associated_evaluator) . "] has already completed this evaluation [" . $evaluation_title . "] for you, and is unable to attempt it again.");
     }
 } else {
        $recent_notifications = $db->GetAll($query);
        if (!isset($recent_notifications) || !$recent_notifications) {
            Notification::add($notification_user->getID(), $proxy_id, $evaluation_id, isset($pending_evaluation["event_id"]) && $pending_evaluation["event_id"] ? $pending_evaluation["event_id"] : $pending_evaluation["event_id"]);
        }
    }
}
//queue notifications for each user with the evaluations which have closed for them in the last 24 hours.
$query = "SELECT *, '0' AS `event_id` FROM `evaluations` AS a\n\t\t\tJOIN `evaluation_forms` AS b\n\t\t\tON a.`eform_id` = b.`eform_id`\n\t\t\tJOIN `evaluations_lu_targets` AS c\n\t\t\tON b.`target_id` = c.`target_id`\n\t\t\tWHERE a.`evaluation_start` <= " . $db->qstr(strtotime("-1 day")) . "\n\t\t\tAND a.`evaluation_finish` >= " . $db->qstr(strtotime("-10 weeks")) . "\n\t\t\tAND a.`evaluation_finish` <= " . $db->qstr(time()) . "\n\t\t\tAND c.`target_shortname` NOT IN ('preceptor', 'rotation_core', 'rotation_elective')\n\t\t\t\n\t\t\tUNION\n\t\t\t\n\t\t\tSELECT a.*, b.*, c.*, e.`event_id` FROM `evaluations` AS a\n\t\t\tJOIN `evaluation_forms` AS b\n\t\t\tON a.`eform_id` = b.`eform_id`\n\t\t\tJOIN `evaluations_lu_targets` AS c\n\t\t\tON b.`target_id` = c.`target_id`\n\t\t\tAND c.`target_shortname` IN ('preceptor', 'rotation_core', 'rotation_elective')\n\t\t\tJOIN `evaluation_targets` AS d\n\t\t\tON a.`evaluation_id` = d.`evaluation_id`\n\t\t\tAND d.`target_type` = 'rotation_id'\n\t\t\tJOIN `" . CLERKSHIP_DATABASE . "`.`events` AS e\n\t\t\tON d.`target_value` = e.`rotation_id`\n\t\t\tAND a.`evaluation_start` <= e.`event_finish`\n\t\t\tAND a.`evaluation_finish` >= e.`event_finish`\n\t\t\tJOIN `" . CLERKSHIP_DATABASE . "`.`event_contacts` AS f\n\t\t\tON e.`event_id` = f.`event_id`\n\t\t\tJOIN `evaluation_evaluators` AS g\n\t\t\tON a.`evaluation_id` = g.`evaluation_id`\n\t\t\tAND g.`evaluator_type` = 'cohort'\n\t\t\tJOIN `group_members` AS h\n\t\t\tON g.`evaluator_value` = h.`group_id`\n\t\t\tAND h.`proxy_id` = f.`etype_id`\n\t\t\tAND h.`member_active`\n\t\t\tWHERE a.`evaluation_start` <= " . $db->qstr(strtotime("-1 day")) . "\n\t\t\tAND e.`event_finish` >= " . $db->qstr(time() - CLERKSHIP_EVALUATION_LOCKOUT) . "\n\t\t\tAND e.`event_finish` <= " . $db->qstr(time() - CLERKSHIP_EVALUATION_TIMEOUT) . "\n\t\t\t\n\t\t\tUNION\n\t\t\t\n\t\t\tSELECT a.*, b.*, c.*, e.`event_id` FROM `evaluations` AS a\n\t\t\tJOIN `evaluation_forms` AS b\n\t\t\tON a.`eform_id` = b.`eform_id`\n\t\t\tJOIN `evaluations_lu_targets` AS c\n\t\t\tON b.`target_id` = c.`target_id`\n\t\t\tAND c.`target_shortname` IN ('preceptor', 'rotation_core', 'rotation_elective')\n\t\t\tJOIN `evaluation_targets` AS d\n\t\t\tON a.`evaluation_id` = d.`evaluation_id`\n\t\t\tAND d.`target_type` = 'rotation_id'\n\t\t\tJOIN `" . CLERKSHIP_DATABASE . "`.`events` AS e\n\t\t\tON d.`target_value` = e.`rotation_id`\n\t\t\tAND a.`evaluation_start` <= e.`event_finish`\n\t\t\tAND a.`evaluation_finish` >= e.`event_finish`\n\t\t\tJOIN `" . CLERKSHIP_DATABASE . "`.`event_contacts` AS f\n\t\t\tON e.`event_id` = f.`event_id`\n\t\t\tJOIN `evaluation_evaluators` AS g\n\t\t\tON a.`evaluation_id` = g.`evaluation_id`\n\t\t\tAND g.`evaluator_type` = 'cgroup_id'\n\t\t\tJOIN `course_group_audience` AS h\n\t\t\tON g.`evaluator_value` = h.`cgroup_id`\n\t\t\tAND h.`proxy_id` = f.`etype_id`\n\t\t\tAND h.`active` = 1\n\t\t\tWHERE a.`evaluation_start` <= " . $db->qstr(strtotime("-1 day")) . "\n\t\t\tAND e.`event_finish` >= " . $db->qstr(time() - CLERKSHIP_EVALUATION_LOCKOUT) . "\n\t\t\tAND e.`event_finish` <= " . $db->qstr(time() - CLERKSHIP_EVALUATION_TIMEOUT) . "\n\t\t\t\n\t\t\tUNION\n\t\t\t\n\t\t\tSELECT a.*, b.*, c.*, e.`event_id` FROM `evaluations` AS a\n\t\t\tJOIN `evaluation_forms` AS b\n\t\t\tON a.`eform_id` = b.`eform_id`\n\t\t\tJOIN `evaluations_lu_targets` AS c\n\t\t\tON b.`target_id` = c.`target_id`\n\t\t\tAND c.`target_shortname` IN ('preceptor', 'rotation_core', 'rotation_elective')\n\t\t\tJOIN `evaluation_targets` AS d\n\t\t\tON a.`evaluation_id` = d.`evaluation_id`\n\t\t\tAND d.`target_type` = 'rotation_id'\n\t\t\tJOIN `" . CLERKSHIP_DATABASE . "`.`events` AS e\n\t\t\tON d.`target_value` = e.`rotation_id`\n\t\t\tAND a.`evaluation_start` <= e.`event_finish`\n\t\t\tAND a.`evaluation_finish` >= e.`event_finish`\n\t\t\tJOIN `" . CLERKSHIP_DATABASE . "`.`event_contacts` AS f\n\t\t\tON e.`event_id` = f.`event_id`\n\t\t\tJOIN `evaluation_evaluators` AS g\n\t\t\tON a.`evaluation_id` = g.`evaluation_id`\n\t\t\tAND g.`evaluator_type` = 'proxy_id'\n\t\t\tAND g.`evaluator_value` = f.`etype_id`\n\t\t\tWHERE a.`evaluation_start` <= " . $db->qstr(strtotime("-1 day")) . "\n\t\t\tAND e.`event_finish` >= " . $db->qstr(time() - CLERKSHIP_EVALUATION_LOCKOUT) . "\n\t\t\tAND e.`event_finish` <= " . $db->qstr(time() - CLERKSHIP_EVALUATION_TIMEOUT);
$ended_evaluations = $db->GetAll($query);
if ($ended_evaluations) {
    foreach ($ended_evaluations as $evaluation) {
        $overdue_evaluations[$evaluation["evaluation_id"] . (isset($evaluation["event_id"]) && $evaluation["event_id"] ? "-" . $evaluation["event_id"] : "")] = Models_Evaluation::getOverdueEvaluations($evaluation);
    }
}
foreach ($overdue_evaluations as $overdue_evaluation_users) {
    foreach ($overdue_evaluation_users as $overdue_evaluation) {
        $evaluation_id = $overdue_evaluation["evaluation_id"];
        require_once "Models/notifications/NotificationUser.class.php";
        require_once "Models/notifications/Notification.class.php";
        $proxy_id = $overdue_evaluation["user"]["id"];
        $notification_user = NotificationUser::get($proxy_id, "evaluation_overdue", $evaluation_id, $proxy_id);
        if (!$notification_user) {
            $notification_user = NotificationUser::add($proxy_id, "evaluation_overdue", $evaluation_id, $proxy_id);
        }
        $query = "SELECT * FROM `notifications` \n                    WHERE `nuser_id` = " . $db->qstr($notification_user->getID()) . " \n                    AND `proxy_id` = " . $db->qstr($proxy_id) . "\n                    AND (`sent_date` = 0 OR `sent_date` >= " . $db->qstr(strtotime("-7 days")) . ")";
        $recent_notifications = $db->GetAll($query);
        if (!isset($recent_notifications) || !$recent_notifications) {
            Notification::add($notification_user->getID(), $proxy_id, $evaluation_id, isset($overdue_evaluation["event_id"]) && $overdue_evaluation["event_id"] ? $overdue_evaluation["event_id"] : $overdue_evaluation["event_id"]);
        }
    }
}
            $content_type = clean_input($_GET["content_type"], "module");
        } else {
            $content_type = "default";
        }
        $notification_user = NotificationUser::get($ENTRADA_USER->getID(), $content_type, $record_id, $record_proxy_id);
        if ($notification_user && $notification_user->getProxyID() == $ENTRADA_USER->getID()) {
            if ($notification_user->getNotifyActive() != $notify_active) {
                if ($notification_user->setNotifyActive($notify_active)) {
                    echo ($notify_active == 1 ? "Activation" : "Deactivation") . " of notifications for this " . $notification_user->getContentTypeName() . " successful.";
                } else {
                    echo "There was an issue while trying to " . ($notify_active ? "activate" : "deactivate") . " notifications for this " . $notification_user->getContentTypeName() . ".";
                }
            } elseif ($notification_user->getDigestMode() != $digest_mode) {
                if ($notification_user->setDigestMode($digest_mode)) {
                    echo ($digest_mode == 1 ? "Activation" : "Deactivation") . " of digest mode for notifications regarding this " . $notification_user->getContentTypeName() . " successful.";
                } else {
                    echo "There was an issue while trying to " . ($digest_mode ? "activate" : "deactivate") . " digest mode for notifications regarding this " . $notification_user->getContentTypeName() . ".";
                }
            } else {
                echo "Notifications for this " . $notification_user->getContentTypeName() . " are already " . ($notify_active ? "activated" : "deactivated") . " and digest mode is already " . ($digest_mode ? "activated" : "deactivated") . ", no changes were made.";
            }
        } else {
            $notification_user = NotificationUser::add($ENTRADA_USER->getID(), $content_type, $record_id, $record_proxy_id, $notify_active, $digest_mode);
            if ($notification_user) {
                echo ($notify_active == 1 ? "Activation" : "Deactivation") . " of notifications for this " . $notification_user->getContentTypeName() . " successful.";
            } else {
                echo "There was an issue while trying to " . ($notify_active ? "activate" : "deactivate") . " notifications for this " . $notification_user->getContentTypeName() . ".";
            }
        }
    }
}
 /**
  * @see EventListener::execute()
  */
 public function execute($eventObj, $className, $eventName)
 {
     if (MODULE_USER_NOTIFICATION) {
         if ($className === 'PostActionPage') {
             $markedPostIDs = WCF::getSession()->getVar('markedPosts');
             if ($eventObj->post !== null && $eventObj->post->userID != WCF::getUser()->userID) {
                 if ($eventObj->action === 'trash') {
                     if (!THREAD_ENABLE_RECYCLE_BIN || !$eventObj->board->getModeratorPermission('canDeletePost') || $eventObj->post->isDeleted) {
                         return;
                     }
                     NotificationHandler::fireEvent('trashed', 'postDelete', $eventObj->post->postID, $eventObj->post->userID, array('trashedByUserID' => WCF::getUser()->userID, 'trashedByUsername' => WCF::getUser()->username, 'trashReason' => $eventObj->reason, 'threadID' => $eventObj->thread->threadID, 'threadTopic' => $eventObj->thread->topic));
                     return true;
                 } else {
                     if ($eventObj->action === 'delete') {
                         if (!$eventObj->board->getModeratorPermission('canDeletePostCompletely')) {
                             return;
                         }
                         NotificationHandler::revokeEvent(array('trashed'), 'postDelete', $eventObj->post->postID);
                         NotificationHandler::fireEvent('deleted', 'postDelete', $eventObj->post->postID, $eventObj->post->userID, array('deletedByUserID' => WCF::getUser()->userID, 'deletedByUsername' => WCF::getUser()->username, 'threadID' => $eventObj->thread->threadID, 'threadTopic' => $eventObj->thread->topic));
                         return true;
                     } else {
                         if ($eventObj->action === 'recover') {
                             if (!$eventObj->board->getModeratorPermission('canDeletePostCompletely') || !$eventObj->post->isDeleted) {
                                 return;
                             }
                             NotificationHandler::revokeEvent(array('trashed'), 'postDelete', $eventObj->post);
                             return true;
                         }
                     }
                 }
             }
             if ($markedPostIDs !== null && count($markedPostIDs)) {
                 if ($eventObj->action === 'deleteAll') {
                     $trashPosts = array();
                     $trashPostsThreadIDs = array();
                     $deletePosts = array();
                     $deletePostsThreadIDs = array();
                     $sql = "SELECT\t\tpost.*, thread.threadID, thread.topic\n\t\t\t\t\t\t\tFROM\t\twbb" . WBB_N . "_post post\n\t\t\t\t\t\t\tLEFT JOIN\twbb" . WBB_N . "_thread thread\n\t\t\t\t\t\t\tON\t\t(post.threadID = thread.threadID)\n\t\t\t\t\t\t\tWHERE\t\tpost.postID IN (" . implode(',', $markedPostIDs) . ")";
                     $result = WCF::getDB()->sendQuery($sql);
                     while ($row = WCF::getDB()->fetchArray($result)) {
                         if ($row['userID'] != WCF::getUser()->userID) {
                             if ($row['isDeleted'] || !THREAD_ENABLE_RECYCLE_BIN) {
                                 $deletePosts[$row['postID']] = new PostDeleteNotificationObject(null, $row);
                                 $deletePostsThreadIDs[] = $row['threadID'];
                             } else {
                                 $trashPosts[$row['postID']] = new PostDeleteNotificationObject(null, $row);
                                 $trashPostsThreadIDs[] = $row['threadID'];
                             }
                         }
                     }
                     list($trashPostsBoards, $trashPostsBoardIDs) = ThreadEditor::getBoards(implode(',', $trashPostsThreadIDs));
                     list($deletePostsBoards, $deletePostsBoardIDs) = ThreadEditor::getBoards(implode(',', $deletePostsThreadIDs));
                     foreach ($trashPostsBoards as $trashPostsBoard) {
                         $trashPostsBoard->checkModeratorPermission('canDeletePost');
                     }
                     foreach ($deletePostsBoards as $deletePostsBoard) {
                         $deletePostsBoard->checkModeratorPermission('canDeletePostCompletely');
                     }
                     unset($trashPostsThreadIDs, $deletePostsThreadIDs, $trashPostsBoards, $deletePostsBoards, $trashPostsBoardIDs, $deletePostsBoardIDs);
                     foreach ($trashPosts as $trashPost) {
                         NotificationHandler::fireEvent('trashed', 'postDelete', $trashPost, $trashPost->userID, array('trashedByUserID' => WCF::getUser()->userID, 'trashedByUsername' => WCF::getUser()->username, 'trashReason' => $eventObj->reason, 'threadID' => $trashPost->threadID, 'threadTopic' => $trashPost->topic));
                     }
                     foreach ($deletePosts as $deletePost) {
                         NotificationHandler::revokeEvent(array('trashed'), 'postDelete', $deletePost);
                         NotificationHandler::fireEvent('deleted', 'postDelete', $deletePost, $deletePost->userID, array('deletedByUserID' => WCF::getUser()->userID, 'deletedByUsername' => WCF::getUser()->username, 'threadID' => $deletePost->threadID, 'threadTopic' => $deletePost->topic));
                     }
                     return true;
                 } else {
                     if ($eventObj->action === 'recoverAll') {
                         $threadIDs = PostEditor::getThreadIDs(implode(',', $markedPostIDs));
                         $notificationObjectObjects = NotificationHandler::getNotificationObjectTypeObject('postDelete')->getObjects($markedPostIDs);
                         list($boards, $boardIDs) = ThreadEditor::getBoards($threadIDs);
                         foreach ($boards as $board) {
                             $board->checkModeratorPermission('canDeletePostCompletely');
                         }
                         unset($threadIDs, $boards, $boardIDs);
                         foreach ($notificationObjectObjects as $notificationObjectObject) {
                             NotificationHandler::revokeEvent(array('trashed'), 'postDelete', $notificationObjectObject);
                         }
                         return true;
                     }
                 }
             }
         } else {
             if ($className === 'ThreadPage') {
                 $posts = $eventObj->postList->posts;
                 $postIDs = array();
                 $user = new NotificationUser(null, WCF::getUser(), false);
                 $packageID = NotificationHandler::getNotificationObjectTypeObject('postDelete')->getPackageID();
                 foreach ($posts as $post) {
                     if ($post->isDeleted && $post->userID == $user->userID) {
                         $postIDs[] = $post->postID;
                     }
                 }
                 unset($posts);
                 if (isset($user->notificationFlags[$packageID]) && $user->notificationFlags[$packageID] > 0) {
                     $count = NotificationEditor::markConfirmedByObjectVisit($user->userID, array('trashed'), 'postDelete', $postIDs);
                     $user->removeOutstandingNotification($packageID, $count);
                 }
             } else {
                 if ($className === 'PostEditForm' && $eventObj->post->userID != WCF::getUser()->userID && isset($_POST['deletePost']) && isset($_POST['sure'])) {
                     if ((!THREAD_ENABLE_RECYCLE_BIN || THREAD_ENABLE_RECYCLE_BIN && $eventObj->post->isDeleted) && $eventObj->board->getModeratorPermission('canDeletePostCompletely')) {
                         NotificationHandler::revokeEvent(array('trashed'), 'postDelete', $eventObj->post->postID);
                         NotificationHandler::fireEvent('deleted', 'postDelete', $eventObj->post->postID, $eventObj->post->userID, array('deletedByUserID' => WCF::getUser()->userID, 'deletedByUsername' => WCF::getUser()->username, 'threadID' => $eventObj->thread->threadID, 'threadTopic' => $eventObj->thread->topic));
                     } else {
                         if (!$eventObj->post->isDeleted && THREAD_ENABLE_RECYCLE_BIN && $eventObj->board->getModeratorPermission('canDeletePost')) {
                             NotificationHandler::fireEvent('trashed', 'postDelete', $eventObj->post->postID, $eventObj->post->userID, array('trashedByUserID' => WCF::getUser()->userID, 'trashedByUsername' => WCF::getUser()->username, 'trashReason' => $eventObj->deleteReason, 'threadID' => $eventObj->thread->threadID, 'threadTopic' => $eventObj->thread->topic));
                         }
                     }
                 }
             }
         }
     }
 }
*/
@set_time_limit(0);
@set_include_path(implode(PATH_SEPARATOR, array(dirname(__FILE__) . "/../core", dirname(__FILE__) . "/../core/includes", dirname(__FILE__) . "/../core/library", get_include_path())));
/**
 * Include the Entrada init code.
 */
require_once "init.inc.php";
if (defined("NOTIFICATIONS_ACTIVE") && NOTIFICATIONS_ACTIVE) {
    require_once "Models/notifications/NotificationUser.class.php";
    require_once "Models/notifications/Notification.class.php";
    $query = "SELECT `nuser_id` FROM `notification_users` \n\t\t\t\tWHERE `next_notification_date` <> 0 \n\t\t\t\tAND `next_notification_date` < " . $db->qstr(time()) . "\n\t\t\t\tAND `notify_active` = 1";
    $nuser_ids = $db->GetAll($query);
    if ($nuser_ids) {
        foreach ($nuser_ids as $nuser_id) {
            $nuser_id = $nuser_id["nuser_id"];
            $notification_user = NotificationUser::getByID($nuser_id);
            if ($notification_user) {
                $query = "SELECT `notification_id` FROM `notifications` \n\t\t\t\t\t\t\tWHERE `nuser_id` = " . $db->qstr($nuser_id) . "\n\t\t\t\t\t\t\tAND `sent` = 0";
                $notification_ids = $db->GetAll($query);
                if ($notification_ids) {
                    if ($notification_user->getDigestMode()) {
                        $notification = Notification::addDigest($nuser_id);
                        $notification->send();
                    } else {
                        foreach ($notification_ids as $notification_id) {
                            $notification_id = $notification_id["notification_id"];
                            $notification = Notification::get($notification_id);
                            $notification->send();
                        }
                    }
                }
예제 #8
0
 /**
  * Remove the specified resource from storage.
  * DELETE /comments/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $validator = $this->validateId($id);
     if ($validator->fails()) {
         return $this->respondInsufficientPrivileges($validator->messages()->all());
     }
     $comment = Comment::find($id);
     if ($comment) {
         $post = $comment->post;
         $category = $post->category;
         if ($comment->delete()) {
             State::whereRaw('object=\'comment\' and object_id=?', array($id))->delete();
             NotificationUser::whereRaw('subject=\'comment\' and subject_id=? and is_removed=0', array($id))->get()->each(function ($notificationsUser) {
                 $notificationsUser->is_removed = 1;
                 $notificationsUser->save();
             });
             Notification::whereRaw('object=\'post\' and event=\'commented\' and is_removed=0 and ' . '(select count(nu.id) from notifications_users nu where nu.notification_id=notifications.id and nu.is_removed=0)=0')->get()->each(function ($notification) {
                 $notification->is_removed = 1;
                 $notification->save();
             });
             return $this->respondNoContent();
         }
     } else {
         return $this->respondNotFound('Comment not found');
     }
     return $this->respondServerError();
 }
예제 #9
0
 /**
  * Remove the specified resource from storage.
  * DELETE /posts/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $post = Post::find($id);
     if (!$post) {
         return $this->respondNotFound();
     }
     $user = Auth::user();
     if (!$user->can('Post.delete', $post)) {
         return $this->respondInsufficientPrivileges();
     }
     if ($post->delete()) {
         $category = $post->category;
         $category->updateCount('posts');
         $commentsIds = array();
         Comment::where('post_id', $id)->get()->each(function ($comment) use($commentsIds) {
             $commentsIds[] = $comment->id;
         });
         if (count($commentsIds) > 0) {
             State::whereRaw('object=\'comment\'')->whereIn('object_id', $commentsIds)->delete();
         }
         $post->comments()->delete();
         $category->updateCount('comments');
         State::whereRaw('object=\'post\' and object_id=?', array($id))->delete();
         Notification::whereRaw('object=\'post\' and object_id=? and is_removed=0', array($id))->get()->each(function ($notification) {
             NotificationUser::where('notification_id', $notification->id)->get()->each(function ($notificationsUser) {
                 $notificationsUser->is_removed = 1;
                 $notificationsUser->save();
             });
             $notification->is_removed = 1;
             $notification->save();
         });
         return $this->respondNoContent();
     }
     return $this->respondServerError();
 }
 /**
  * Creates a new notification and returns its id.
  *
  * @param int $nuser_id
  * @return Notification
  */
 public static function addDigest($nuser_id)
 {
     global $db, $ENTRADA_TEMPLATE;
     require_once "Models/utility/Template.class.php";
     $notification_user = NotificationUser::getByID($nuser_id);
     if ($notification_user) {
         $notifications = self::getAllPending($nuser_id, 1);
         $activity_count = count($notifications);
         if ($notifications && $activity_count) {
             $notification_template = file_get_contents($ENTRADA_TEMPLATE->absolute() . "/email/notification-default-digest.xml");
             $search = array("%UC_CONTENT_TYPE_NAME%", "%CONTENT_TYPE_NAME%", "%COMMENTS_NUMBER_STRING%", "%CONTENT_TITLE%", "%URL%", "%UNSUBSCRIBE_URL%", "%APPLICATION_NAME%", "%ENTRADA_URL%");
             $replace = array(html_encode(ucwords($notification_user->getContentTypeName())), html_encode($notification_user->getContentTypeName()), html_encode($activity_count > 1 ? $activity_count . " new comments have" : "A new comment has"), html_encode($notification_user->getContentTitle()), html_encode($notification_user->getContentURL()), html_encode(ENTRADA_URL . "/profile?section=notifications&id=" . $nuser_id . "&action=unsubscribe"), html_encode(APPLICATION_NAME), html_encode(ENTRADA_URL));
             $notification_body = str_replace($search, $replace, $notification_template);
             $new_notification = array("nuser_id" => $nuser_id, "notification_body" => $notification_body, "proxy_id" => 0, "sent" => false, "sent_date" => 0, "digest" => 1);
             $db->AutoExecute("notifications", $new_notification, "INSERT");
             if (!($notification_id = $db->Insert_Id())) {
                 application_log("error", "There was an issue attempting to add a notification record to the database. Database said: " . $db->ErrorMsg());
             } else {
                 $new_notification["notification_id"] = $notification_id;
                 foreach ($notifications as $processed_notification) {
                     $processed_notification->setSentStatus(true);
                 }
                 $notification = self::fromArray($new_notification);
                 $notification_user->setNextNotificationDate();
                 return $notification;
             }
         }
     }
     return false;
 }
예제 #11
0
                    $query = "SELECT * FROM `events` WHERE `event_id` = " . $db->qstr($EVENT_ID);
                    $result = $db->GetRow($query);
                    if ($result) {
                        $PROCESSED["event_id"] = $EVENT_ID;
                        $PROCESSED["proxy_id"] = $ENTRADA_USER->getID();
                        $PROCESSED["parent_id"] = 0;
                        $PROCESSED["discussion_title"] = "RE: " . $result["event_title"];
                        $PROCESSED["discussion_comment"] = $DISCUSSION_COMMENT;
                        $PROCESSED["discussion_active"] = 1;
                        $PROCESSED["updated_date"] = time();
                        $PROCESSED["updated_by"] = $ENTRADA_USER->getID();
                        if (!$db->AutoExecute("event_discussions", $PROCESSED, "INSERT")) {
                            application_log("error", "Unable to add discussion comment to event id [" . $EVENT_ID . "]");
                        } elseif (($EDISCUSSION_ID = $db->Insert_Id()) && defined("NOTIFICATIONS_ACTIVE") && NOTIFICATIONS_ACTIVE) {
                            require_once "Models/notifications/NotificationUser.class.php";
                            NotificationUser::addAllNotifications("event_discussion", $EVENT_ID, 0, $ENTRADA_USER->getID(), $EDISCUSSION_ID);
                        }
                    }
                }
                header("Location: " . ENTRADA_URL . "/events?" . ($USE_QUERY ? (isset($_GET["drid"]) ? "drid" : "rid") . "=" . $RESULT_ID : "id=" . $EVENT_ID) . "#event_comments");
                exit;
            } else {
                header("Location: " . ENTRADA_URL . "/events");
                exit;
            }
            break;
        default:
            continue;
            break;
    }
}
예제 #12
0
 /**
  * Display a listing of notifications.
  *
  * @param int|null $lastNotificationId Last chat ID
  * @param int $size Response size
  * @return Response
  */
 public function getList($lastNotificationId = null, $size = 20)
 {
     $result = array();
     $size = (int) $size > 0 ? (int) $size : 20;
     $query = sprintf('select max(x.id) as "before" from (select id from notifications n where n.owner_id = %d order by n.timestamp desc offset %d) x;', Auth::user()->id, self::AMOUNT_LIMIT);
     if (($data = DB::select($query)) && !is_null($idBeforeRemove = $data[0]->before)) {
         Notification::whereRaw('owner_id = ? and id < ?', array(Auth::user()->id, $idBeforeRemove))->update(array('is_removed' => 1));
     }
     Notification::whereRaw('owner_id = ? and is_removed = 0 and timestamp > (CURRENT_TIMESTAMP - INTERVAL \'' . self::TIME_LIMIT . ' second\')' . (is_null($lastNotificationId) ? '' : ' and id < ' . (int) $lastNotificationId), array(Auth::user()->id))->orderBy('timestamp', 'desc')->orderBy('id', 'desc')->get()->take($size)->each(function ($notification) use(&$result) {
         $notificationUsers = NotificationUser::whereRaw('notification_id = ? and is_removed = 0', array($notification->id))->orderBy('timestamp', 'desc')->get();
         $usersCount = $notificationUsers->count();
         $type = $notification->object;
         $event = $notification->event;
         $data = array('id' => $notification->id, 'type' => $type, 'amount' => $usersCount, 'timestamp' => $notification->getTimeStamp());
         //						var_dump($type.' '.$event);
         $self = $this;
         if ($type == 'post') {
             $post = Post::find($notification->object_id);
             $data['post_id'] = $post->id;
             $data['post_title'] = $post->text;
             if ($event == 'commented') {
                 $notificationUsers->take(2)->each(function ($user) use(&$data, $self) {
                     $comment = Comment::find($user->subject_id);
                     if ($comment) {
                         $data['comments'][] = $self->collectionTransformer->transformComment($comment);
                     } else {
                         unset($data['id']);
                         unset($data['type']);
                         unset($data['amount']);
                         unset($data['timestamp']);
                         unset($data['post_id']);
                         unset($data['post_title']);
                     }
                 });
             } else {
                 if ($event == 'liked') {
                     $notificationUsers->take(2)->each(function ($user) use(&$data, $self) {
                         $user = User::withTrashed()->find($user->user_id);
                         $data['likes'][] = $self->collectionTransformer->transformUserToSmall($user);
                     });
                 } else {
                     unset($data['id']);
                     unset($data['type']);
                     unset($data['amount']);
                     unset($data['timestamp']);
                     unset($data['post_id']);
                     unset($data['post_title']);
                 }
             }
         } else {
             if ($type == 'comment') {
                 $comment = Comment::find($notification->object_id);
                 if ($comment) {
                     $post = Post::find($comment->post_id);
                     if ($post) {
                         $data['post_id'] = $post->id;
                         $data['post_title'] = $post->text;
                         $data['comment_id'] = $comment->id;
                     }
                     if ($event == 'liked') {
                         $notificationUsers->take(2)->each(function ($user) use(&$data, $self) {
                             $user = User::withTrashed()->find($user->user_id);
                             $data['likes'][] = $self->collectionTransformer->transformUserToSmall($user);
                         });
                     }
                 } else {
                     unset($data['id']);
                     unset($data['type']);
                     unset($data['amount']);
                     unset($data['timestamp']);
                     unset($data['post_id']);
                     unset($data['post_title']);
                 }
             } else {
                 unset($data['id']);
                 unset($data['type']);
                 unset($data['amount']);
                 unset($data['timestamp']);
                 unset($data['post_id']);
                 unset($data['post_title']);
             }
         }
         //						$filter = function ($data) {
         //							return array_filter($data) != [];
         //						};
         //                        $result['notifications'][] = array_filter($data, $filter);
         if (!empty($data)) {
             $result['notifications'][] = $data;
         }
     });
     if (is_null($lastNotificationId)) {
         foreach (Auth::user()->getTokens() as $token) {
             $state = new StateSender($token);
             $state->setAllPostsAsRead();
             $state->setAllCommentsAsRead();
             $state->send();
         }
     }
     return $this->respond($result);
 }
예제 #13
0
 }
 if (isset($evaluation_request) && $evaluation_request && !$db->AutoExecute("evaluation_requests", array("request_fulfilled" => 1), "UPDATE", "`erequest_id` = " . $db->qstr($evaluation_request["erequest_id"]))) {
     application_log("error", "Unable to mark evaluation request as completed [" . $progress_record["evaluation_id"] . "]. Database said: " . $db->ErrorMsg());
 }
 if ($evaluation_record["threshold_notifications_type"] != "disabled") {
     $is_below_threshold = Models_Evaluation::responsesBelowThreshold($evaluation_record["evaluation_id"], $eprogress_id);
     if ($is_below_threshold) {
         if (defined("NOTIFICATIONS_ACTIVE") && NOTIFICATIONS_ACTIVE) {
             require_once "Models/notifications/NotificationUser.class.php";
             require_once "Models/notifications/Notification.class.php";
             $threshold_notification_recipients = Models_Evaluation::getThresholdNotificationRecipients($evaluation_record["evaluation_id"], $eprogress_id, $PROCESSED["eevaluator_id"]);
             if (isset($threshold_notification_recipients) && $threshold_notification_recipients) {
                 foreach ($threshold_notification_recipients as $threshold_notification_recipient) {
                     $notification_user = NotificationUser::get($threshold_notification_recipient["proxy_id"], "evaluation_threshold", $evaluation_record["evaluation_id"], $ENTRADA_USER->getID());
                     if (!$notification_user) {
                         $notification_user = NotificationUser::add($threshold_notification_recipient["proxy_id"], "evaluation_threshold", $evaluation_record["evaluation_id"], $ENTRADA_USER->getID());
                     }
                     Notification::add($notification_user->getID(), $ENTRADA_USER->getID(), $eprogress_id);
                 }
             }
         }
     }
 }
 if (array_search($PROCESSED["target_shortname"], array("preceptor", "rotation_core", "rotation_elective")) !== false) {
     if (!$db->AutoExecute("evaluation_progress_clerkship_events", $PROCESSED_CLERKSHIP_EVENT, "INSERT")) {
         $db->Execute("UPDATE `evaluation_progress` SET `progress_value` = 'inprogress' WHERE `eprogress_id` = " . $db->qstr($PROCESSED["eprogress_id"]));
         application_log("error", "Unable to record the final clerkship event details for eprogress_id [" . $eprogress_id . "] in the evaluation_progress_clerkship_events table. Database said: " . $db->ErrorMsg());
         $ERROR++;
         $ERRORSTR[] = "We were unable to record the final results for this evaluation at this time. Please be assured that your responses are saved, but you will need to come back to this evaluation to re-submit it. This problem has been reported to a system administrator; please try again later.";
     } else {
         /**
예제 #14
0
 if ($STEP == 2) {
     if (isset($_POST["discussion_comment"]) && ($new_comments = clean_input($_POST["discussion_comment"], array("trim", "notags")))) {
         $PROCESSED["comments"] = $new_comments;
         $PROCESSED["clerk_id"] = $PROXY_ID;
         $PROCESSED["proxy_id"] = $ENTRADA_USER->getID();
         $PROCESSED["rotation_id"] = $rotation_id;
         $PROCESSED["updated_date"] = time();
         if ($db->AutoExecute(CLERKSHIP_DATABASE . ".logbook_rotation_comments", $PROCESSED, "INSERT")) {
             if (defined("NOTIFICATIONS_ACTIVE") && NOTIFICATIONS_ACTIVE) {
                 $lrcomment_id = $db->Insert_Id();
                 require_once "Models/notifications/NotificationUser.class.php";
                 $notification_user = NotificationUser::get($PROXY_ID, "logbook_rotation", $rotation_id, $PROXY_ID);
                 if (!$notification_user) {
                     $notification_user = NotificationUser::add($PROXY_ID, "logbook_rotation", $rotation_id, $PROXY_ID);
                 }
                 NotificationUser::addAllNotifications("logbook_rotation", $rotation_id, $PROXY_ID, $ENTRADA_USER->getID(), $lrcomment_id);
             }
             $SUCCESS++;
             $SUCCESSSTR[] = "You have succesfully added a comment to this rotation" . ($student ? "" : " for " . get_account_data("firstlast", $PROXY_ID)) . ".";
         } else {
             $ERROR++;
             $ERRORSTR[] = "There was an issue while attempting to add your comment to the system. <br /><br />If you if this error persists, please contact <a href=\"mailto:" . html_encode($AGENT_CONTACTS["administrator"]["email"]) . "\">" . html_encode($AGENT_CONTACTS["administrator"]["name"]) . "</a> for assistance.";
             application_log("error", "There was an error adding a clerkship rotation comment entry. Database said: " . $db->ErrorMsg());
         }
     }
     $STEP = 1;
 }
 // Display Content
 switch ($STEP) {
     case 2:
         break;