Exemple #1
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());
     }
 }
 /**
  * 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());
     }
 }