Exemplo n.º 1
0
 /**
  *
  * @see ForumServicePDO::updateForum()
  */
 public static function updateForum($id)
 {
     $app = \Slim\Slim::getInstance();
     try {
         $pdo = new ForumServicePDO();
         $forum = $pdo->getForum($id);
         if (isset($forum)) {
             // get and decode JSON request body
             $request = $app->request();
             $body = $request->getBody();
             $forumData = json_decode($body);
             $params = (array) $forumData;
             $params['id'] = $id;
             $pdo->updateForum($id, $params, AppUtils::getUserId());
             $params['changeType'] = ForumEvent::UPDATE;
             AppUtils::sendEvent(ForumEvent::DOMAIN, $id, ForumEvent::CHANGE, "Forum updated: " . $params['name'], $params);
             AppUtils::sendResponse($forumData);
         } else {
             AppUtils::sendError(AppUtils::USER_ERROR_CODE, "Forum with ID {$id} does not exist!", "Database update failure");
         }
     } catch (Exception $e) {
         AppUtils::logError($e, __METHOD__);
         AppUtils::sendError($e->getCode(), "Error updating forum with ID: " . $id, $e->getMessage());
     }
 }
Exemplo n.º 2
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());
     }
 }