Exemplo n.º 1
0
 public function initSubscriptionsForUser($userId)
 {
     // User Directed Events
     $this->subscribe($userId, 'USER.' . $userId);
     $pdo = new ForumServicePDO();
     $forums = $pdo->getForumsForUser($userId);
     foreach ($forums as $forum) {
         $this->subscribe($userId, 'FORUM.' . $forum['id']);
     }
 }
Exemplo n.º 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());
     }
 }
Exemplo n.º 3
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());
     }
 }
Exemplo n.º 4
0
 /**
  *
  * @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());
     }
 }
Exemplo n.º 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']);
     }
 }