Пример #1
0
 public function saveNewPost(PhotoDTO $photoDTO, $otherData)
 {
     $responseDTO = new ResponseDTO(WRITE_POST_FORM);
     $text = $otherData[WRITE_POST_FORM . TEXT];
     $dashboardid = $otherData[WRITE_POST_FORM . DASHBOARDID];
     $timestamp = date(DATE_FORMAT);
     try {
         $userLogged = SessionUtils::getUserLogged();
         $photoDAO = new PhotoDAO();
         $authorProfilePhoto = $photoDAO->getUserProfilePhoto($userLogged->getUserId());
         $dashboardProfilePhoto = $photoDAO->getUserProfilePhoto($dashboardid);
         $userDAO = new UserDAO();
         $authorUser = $userDAO->getUserByUserId($userLogged->getUserId());
         $dashboardUser = $userDAO->getUserByUserId($dashboardid);
         $postDTO = new PostDTO(NULL, $dashboardUser, $authorUser, $text, $timestamp, $photoDTO);
         $postDAO = new PostDAO();
         $newPostDTO = $postDAO->insertNewPost($postDTO);
         if ($newPostDTO->getPostId() != 0) {
             DataModelUtils::notifyAction($newPostDTO->getPostId() . SEPARATOR . $authorUser->getUserId() . SEPARATOR . $dashboardUser->getUserId() . SEPARATOR . $dashboardUser->getUserName(), WRITE_POST_FORM);
             return $newPostDTO;
         } else {
             $responseDTO->setErrField(POST, "Non è stato possibile inserire il post");
         }
         return $responseDTO;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         throw $authExp;
     } catch (Exception $e) {
         throw $e;
     }
 }