예제 #1
0
 /**
  *
  * @see ForumPostServicePDO::updateForumPostEntry()
  */
 public static function updateForumPostEntry($forumId, $postId)
 {
     $app = \Slim\Slim::getInstance();
     try {
         $pdo = new ForumPostServicePDO();
         $request = $app->request();
         $body = $request->getBody();
         $forumPost = (array) json_decode($body);
         $id = $forumPost['id'];
         $post = $pdo->getPosting($forumPost['forumId'], $id);
         if (isset($post)) {
             $pdo->updateForumPostEntry($id, $forumPost);
             $eventData = array('postId' => $id, 'changeType' => ForumEvent::UPDATE);
             AppUtils::sendEvent(ForumEvent::DOMAIN, $forumId, ForumEvent::POST_CHANGE, "Posting updated with ID: " . $id, $eventData);
             AppUtils::sendResponse(array("success" => true, "message" => "Forum post with ID {$id} updated."));
         } else {
             AppUtils::sendResponse(array("success" => false, "message" => "Forum post with ID {$id} does not exist!"));
         }
     } catch (Exception $e) {
         AppUtils::logError($e, __METHOD__);
         AppUtils::sendError($e->getCode(), "Error updating forum post with ID {$id}", $e->getMessage());
     }
 }
예제 #2
0
 /**
  *
  * @see ForumServicePDO::deleteForum()
  */
 public static function deleteForum($id)
 {
     $app = \Slim\Slim::getInstance();
     $params = array('forumId' => $id, 'changeType' => ForumEvent::DELETE);
     try {
         $pdo = new ForumServicePDO();
         $pdo->deleteForum($id);
         AppUtils::sendEvent(ForumEvent::DOMAIN, $id, ForumEvent::CHANGE, "Forum deleted: " . $id, $params);
         $app->response()->status(204);
         // NO DOCUMENT STATUS CODE FOR SUCCESS
     } catch (Exception $e) {
         AppUtils::logError($e, __METHOD__);
         AppUtils::sendError($e->getCode(), "Error deleting forum with ID: " . $id, $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());
     }
 }
예제 #4
0
 /**
  *
  * @see ForumServicePDO::deleteFileNode()
  */
 public static function deleteFileNode($forumId, $id)
 {
     $app = \Slim\Slim::getInstance();
     try {
         $pdo = new ForumServicePDO();
         $pdo->deleteFileNode($id);
         $eventParams = array();
         $eventParams['id'] = $id;
         $eventParams['changeType'] = ForumEvent::DELETE;
         AppUtils::sendEvent(ForumEvent::DOMAIN, $forumId, ForumEvent::NODE_CHANGE, "Node deleted id: " . $id, $eventParams);
         $app->response()->setStatus(204);
         // NO DOCUMENT STATUS CODE FOR
         // SUCCESS
     } catch (Exception $e) {
         AppUtils::logError($e, __METHOD__);
         AppUtils::sendError($e->getCode(), "Error deleting file node with ID {$id}", $e->getMessage());
     }
 }
예제 #5
0
 /**
  * Uploads the file specified via HTTP POST
  * This code is based on the PHP examples
  */
 public static function upload()
 {
     $app = \Slim\Slim::getInstance();
     $forumId = $_POST['forumId'];
     $folderId = $_POST['id'];
     $fileName = $_FILES["file"]["name"];
     $tempFileName = $_FILES["file"]["tmp_name"];
     $contentType = $_FILES["file"]["type"];
     // Check for errors
     if ($_FILES['file']['error'] > 0) {
         $errorMsg = 'Upload Error: ';
         // Print a message based upon the error.
         switch ($_FILES['file']['error']) {
             case 1:
                 $errorMsg = $errorMsg . 'The file exceeds the upload_max_filesize setting in php.ini.';
                 break;
             case 2:
                 $errorMsg = $errorMsg . 'The file exceeds the MAX_FILE_SIZE setting in the HTML form.';
                 break;
             case 3:
                 $errorMsg = $errorMsg . 'The file was only partially uploaded.';
                 break;
             case 4:
                 $errorMsg = $errorMsg . 'No file was uploaded.';
                 break;
             case 6:
                 $errorMsg = $errorMsg . 'No temporary folder was available.';
                 break;
             case 7:
                 $errorMsg = $errorMsg . 'Unable to write to the disk.';
                 break;
             case 8:
                 $errorMsg = $errorMsg . 'File upload stopped.';
                 break;
             default:
                 $errorMsg = $errorMsg . 'A system error occurred.';
                 break;
         }
         // End of switch.
         AppUtils::sendError(500, "File Upload Error", $errorMsg);
     } else {
         try {
             $fileNode = array('id' => '', 'forumId' => $forumId, 'parentId' => $folderId, 'name' => $fileName, 'contentType' => $contentType);
             $pdo = new ForumServicePDO();
             $fileNode = $pdo->createFileNode((array) $fileNode);
             $fileId = $fileNode['id'];
             move_uploaded_file($tempFileName, FORUM_UPLOAD_DIR . $fileId);
             $fileNode['changeType'] = ForumEvent::CREATE;
             AppUtils::sendEvent(ForumEvent::DOMAIN, $forumId, ForumEvent::NODE_CHANGE, "Node created: " . $fileNode['name'], $fileNode);
             AppUtils::sendResponse($fileNode);
         } catch (Exception $e) {
             AppUtils::logError($e, __METHOD__);
             AppUtils::sendError($e->getCode(), "Error creating file node for {$fileName}", $e->getMessage());
         }
     }
     // Delete the file if it still exists:
     if (file_exists($_FILES['file']['tmp_name']) && is_file($_FILES['file']['tmp_name'])) {
         unlink($_FILES['file']['tmp_name']);
     }
 }