예제 #1
0
 /**
  * Send a stomp collaboration event message to all or a single user
  * Always call before sendResponse because the response will be
  * complete and stomp will throw exceptions.
  *
  * @param String $topicId
  *           could be a userId for a forumId
  */
 public static function sendEvent($eventDomain, $topicId, $eventId, $eventDescription, $eventParameters)
 {
     $impulseHeader = array("persistent" => 'false');
     $content = array("sourceUserId" => self::getUserId(), "type" => $eventId, "description" => $eventDescription, "params" => $eventParameters);
     $msg = json_encode($content, JSON_NUMERIC_CHECK);
     if (self::$stompMode) {
         try {
             $stomp = new Stomp('tcp://localhost:61613', 'admin', 'password');
             $stomp->send(self::$topic . $eventDomain . '.' . $topicId, $msg, $impulseHeader);
             unset($stomp);
         } catch (StompException $e) {
             self::logError($e, __METHOD__);
         }
     } else {
         $pdo = new EventServicePDO();
         $pdo->pushEvent(self::getUserId(), $eventDomain . '.' . $topicId, $msg);
     }
 }
예제 #2
0
 /**
  *
  * @see EventServicePDO::unsubscribe()
  */
 public static function unsubscribe($userId, $topic)
 {
     try {
         $pdo = new EventServicePDO();
         $pdo->unsubscribe($userId, $topic);
         AppUtils::sendResponse(array("success" => true, "message" => "User {$userId} unsubscribed from topic {$topic}"));
     } catch (PDOException $e) {
         AppUtils::logError($e, __METHOD__);
         AppUtils::sendError($e->getCode(), "Error unsubscribing to events user {$userId} topic {$topic}", $e->getMessage());
     }
 }
예제 #3
0
 /**
  * Leave forum
  *
  * @see ForumServicePDO::setForumEnrollmentStatus()
  */
 public static function leaveForum($forumId, $userId)
 {
     $app = \Slim\Slim::getInstance();
     try {
         $pdo = new ForumServicePDO();
         $forum = $pdo->getForum($forumId);
         $params = array();
         $params['forumId'] = $forumId;
         $params['userId'] = $userId;
         $params['forumName'] = $forum['name'];
         //         $params['sourceUserId'] = AppUtils::getUserId();
         $params['enrollmentStatus'] = EnrollmentStatus::Left;
         /*
          * When status is set to left (leaving) unsubscribe to the forum events
          * and remove enrollment from the forum users list
          */
         $eventPdo = new EventServicePDO();
         $eventPdo->unsubscribe($userId, ForumEvent::DOMAIN . '.' . $forumId);
         $eStatus = $pdo->setForumEnrollmentStatus($forumId, $userId, $params['enrollmentStatus']);
         // Send the event to the user who left so they can update the
         // UI because they will no longer receive forum events
         AppUtils::sendEvent(UserEvent::DOMAIN, $userId, UserEvent::REMOVED, "Forum removed", $params);
         // Let all other forum members know that this user left the
         // forum
         AppUtils::sendEvent(ForumEvent::DOMAIN, $forumId, ForumEvent::ENROLLMENT, "User has left forum", $params);
         AppUtils::sendResponse($eStatus);
     } catch (Exception $e) {
         AppUtils::logError($e, __METHOD__);
         AppUtils::sendError($e->getCode(), "Error leaving forum for user {$userId} in forum {$forumId}", $e->getMessage());
     }
 }