/** * * @see ForumPostServicePDO::createForumPostEntry() */ public static function createForumPostEntry($forumId) { $app = \Slim\Slim::getInstance(); try { // get and decode JSON request body $request = $app->request(); $body = $request->getBody(); $forumPost = (array) json_decode($body); $forumPost['userId'] = AppUtils::getUserId(); $pdo = new ForumPostServicePDO(); $forumPostId = $pdo->createForumPostEntry($forumPost); $eventData = array('postId' => $forumPostId, 'changeType' => ForumEvent::CREATE); AppUtils::sendEvent(ForumEvent::DOMAIN, $forumId, ForumEvent::POST_CHANGE, "Posting created with ID: " . $forumPostId, $eventData); AppUtils::sendResponse($forumPostId); } catch (Exception $e) { AppUtils::logError($e, __METHOD__); AppUtils::sendError($e->getCode(), "Error creating forum post entry", $e->getMessage()); } }
/** * * @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()); } }
/** * * @see ForumServicePDO::getForumsForUser() */ public static function getForumsForUser() { try { $pdo = new ForumServicePDO(); $userId = AppUtils::getUserId(); $forums = $pdo->getForumsForUser($userId); AppUtils::sendResponse($forums); } catch (PDOException $e) { AppUtils::logError($e, __METHOD__); AppUtils::sendError($e->getCode(), "Error getting forums for user {$userId}", $e->getMessage()); } }
/** * * @see UserServicePDO::getAccess() */ public static function getAccess() { $id = AppUtils::getUserId(); try { $pdo = new UserServicePDO(); $access = $pdo->getAccess($id); AppUtils::sendResponse($access); } catch (PDOException $e) { AppUtils::logError($e, __METHOD__); AppUtils::sendError($e->getCode(), "Error getting access level for user with ID {$id}", $e->getMessage()); } }
/** * Sets the forum enrollment status and will add the record to the * forum_user table if necessary. * * * @param string $forumId * Forum ID * @param string $userId * Forum Member User ID * @param string $enrollmentStatus * Enrollment status code * @throws Exception */ public function setForumEnrollmentStatus($forumId, $userId, $enrollmentStatus) { try { // Verify enrollment status code is valid if (!in_array($enrollmentStatus, ForumServicePDO::$ENROLLMENT_CODES)) { throw new Exception("Invalid enrollment status code [{$enrollmentStatus}]!"); } $newForumUser = array(); $newForumUser['forumId'] = $forumId; $newForumUser['userId'] = $userId; $newForumUser['enrollmentStatus'] = $enrollmentStatus; $newForumUser['updateUserId'] = AppUtils::getUserId(); $forumUser = $this->db->forum_user()->where("forumId=? AND userId=?", $forumId, $userId); if ($forumUser->fetch()) { $forumUser->update($newForumUser); } else { $this->db->forum_user()->insert($newForumUser); } } catch (Exception $e) { throw $e; } }