예제 #1
0
 function addPhotoModel($photoForm, $albumId)
 {
     $formObjRaw = new FormDTO(ADD_PHOTO_FORM, $photoForm);
     $responseDTO = new ResponseDTO(ADD_PHOTO_FORM);
     try {
         $formDataObj = $formObjRaw->getFormData();
         $validator = new FormValidator(ADD_PHOTO_FORM, $formDataObj);
         $validationError = $validator->checkAll();
         if (sizeof($validationError) == 0) {
             $uploadedPhoto = FileUtils::uploadPhotoModel($formDataObj[ADD_PHOTO_FORM . PHOTO], $albumId, ADD_PHOTO_FORM, $formDataObj[ADD_PHOTO_FORM . LATITUDE], $formDataObj[ADD_PHOTO_FORM . LONGITUDE]);
             if (get_class($uploadedPhoto) === PHOTODTO) {
                 DataModelUtils::notifyAction($uploadedPhoto->getPhotoId() . SEPARATOR . $uploadedPhoto->getPhotoUrl() . SEPARATOR . $albumId, ADD_PHOTO_FORM);
                 return $uploadedPhoto;
             } else {
                 $responseDTO->setErrField(ERROR_RESPONSE, "Errore durante l'inserimento della foto");
             }
         } else {
             if (array_key_exists(PHOTO, $validationError)) {
                 $responseDTO->setErrField(PHOTO, $validationError[PHOTO]);
             }
         }
         return $responseDTO;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         throw $authExp;
     } catch (Exception $e) {
         throw $e;
     }
 }
예제 #2
0
 function searchResourceModel($searchCriteriaForm)
 {
     $formObjRaw = new FormDTO(SEARCH_USER_FORM, $searchCriteriaForm);
     $responseDTO = new ResponseDTO(SEARCH_USER_FORM);
     try {
         $formDataObj = $formObjRaw->getFormData();
         $validator = new FormValidator(SEARCH_USER_FORM, $formDataObj);
         $validationError = $validator->checkAll();
         if (sizeof($validationError) == 0) {
             $userDAO = new UserDAO();
             $userDTOList = $userDAO->getUserInfoByCriteria($formDataObj);
             return $userDTOList;
         } else {
             if (array_key_exists(NAME, $validationError)) {
                 $responseDTO->setErrField(NAME, $validationError[NAME]);
             }
             return $responseDTO;
         }
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         throw $authExp;
     } catch (Exception $e) {
         throw $e;
     }
 }
예제 #3
0
 function addAlbumModel($albumForm)
 {
     $formObjRaw = new FormDTO(ADD_ALBUM_FORM, $albumForm);
     $responseDTO = new ResponseDTO(ADD_ALBUM_FORM);
     try {
         $formDataObj = $formObjRaw->getFormData();
         $validator = new FormValidator(ADD_ALBUM_FORM, $formDataObj);
         $validationError = $validator->checkAll();
         //            $validationError = array();
         if (sizeof($validationError) == 0) {
             $userLogged = SessionUtils::getUserLogged();
             $uploadedPhoto = FileUtils::uploadPhotoModel($formDataObj[ADD_ALBUM_FORM . COVER], NULL, ADD_ALBUM_FORM);
             if (get_class($uploadedPhoto) === PHOTODTO) {
                 $userDAO = new UserDAO();
                 $userDTO = $userDAO->getUserByUserId($userLogged->getUserId());
                 $albumDAO = new AlbumDAO();
                 $albumDTO = new AlbumDTO(null, date(DATE_FORMAT), $formDataObj[ADD_ALBUM_FORM . TITLE], $uploadedPhoto, $userDTO);
                 $albumDTO = $albumDAO->insertNewAlbum($albumDTO);
                 if ($albumDTO->getAlbumId() != 0) {
                     $photoAlbumPath = FileUtils::createAlbumDirOnServer($userDTO->getUserId(), $albumDTO->getAlbumId());
                     DataModelUtils::notifyAction($albumDTO->getCover()->getPhotoId() . SEPARATOR . $albumDTO->getCover()->getPhotoUrl() . SEPARATOR . $albumDTO->getAlbumId() . SEPARATOR . $albumDTO->getTitle(), ADD_ALBUM_FORM);
                     return $albumDTO;
                 } else {
                     $responseDTO->setErrField(ERROR_RESPONSE, "Errore durante l'inserimento dell'album");
                 }
             } else {
                 $responseDTO->setErrField(ERROR_RESPONSE, "Errore durante l'inserimento della foto profilo");
             }
         } else {
             if (array_key_exists(TITLE, $validationError)) {
                 $responseDTO->setErrField(TITLE, $validationError[TITLE]);
             }
             if (array_key_exists(PHOTO, $validationError)) {
                 $responseDTO->setErrField(COVER, $validationError[PHOTO]);
             }
             SessionUtils::setFormValue($formDataObj);
         }
         return $responseDTO;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         throw $authExp;
     } catch (Exception $e) {
         throw $e;
     }
 }
예제 #4
0
 function searchResourceModel($searchCriteriaForm)
 {
     $formObjRaw = new FormDTO(SEARCH_USER_FORM, $searchCriteriaForm);
     $responseDTO = new ResponseDTO(SEARCH_USER_FORM);
     try {
         $formDataObj = $formObjRaw->getFormData();
         $userDAO = new UserDAO();
         $userDTOList = $userDAO->getUserInfoByCriteria($formDataObj);
         return $userDTOList;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         throw $authExp;
     } catch (Exception $e) {
         throw $e;
     }
 }
예제 #5
0
 public function forgotPasswordModel($forgotPasswordForm)
 {
     $formObjRaw = new FormDTO(FORGOT_PWD_FORM, $forgotPasswordForm);
     $responseDTO = new ResponseDTO(FORGOT_PWD_FORM);
     try {
         $formDataObj = $formObjRaw->getFormData();
         $validator = new FormValidator(FORGOT_PWD_FORM, $formDataObj);
         $validationError = $validator->checkAll();
         if (sizeof($validationError) == 0) {
             $userDAO = new UserDAO();
             $userDTO = $userDAO->getUserByEmail($formDataObj[FORGOT_PWD_FORM . EMAIL]);
             if (is_null($userDTO)) {
                 $responseDTO->setErrField(ERROR_RESPONSE, "Nessun user presente con questa mail");
             } else {
                 $newPassword = PasswordUtils::createRandomicPassword();
                 $userDTO->setPassword($newPassword);
                 $resultMail = DataModelUtils::sendMail($userDTO, FORGOT_PWD_FORM);
                 $hashedPwd = PasswordUtils::getPassword($newPassword);
                 $userDTO->setPassword($hashedPwd);
                 $result = $userDAO->updateUserPassword($userDTO);
                 if ($result != 1) {
                     $responseDTO->setErrField(ERROR_RESPONSE, "Problema nel cambio della password");
                 } else {
                     $responseDTO->setResponseSucc("Verra mandata una mail con una nuova password all'indirizzo " . $userDTO->getEmail());
                 }
             }
         } else {
             if (array_key_exists(EMAIL, $validationError)) {
                 $responseDTO->setErrField(EMAIL, $validationError[EMAIL]);
             }
             SessionUtils::setFormValue($formDataObj);
         }
         return $responseDTO;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (Exception $e) {
         throw $e;
     }
 }
예제 #6
0
 public function commentAPostModel($commentForm, $postId)
 {
     $responseDTO = new ResponseDTO(WRITE_COMMENT_FORM);
     $formObjRaw = new FormDTO(WRITE_COMMENT_FORM, $commentForm);
     $formObjRaw->setSubElementId($postId);
     try {
         $formDataObj = $formObjRaw->getFormData();
         $responseDTO->setSubElementId($formDataObj[WRITE_COMMENT_FORM . POSTID]);
         $validator = new FormValidator(WRITE_COMMENT_FORM, $formDataObj);
         $validationError = $validator->checkAll();
         if (sizeof($validationError) == 0) {
             $timestamp = date(DATE_FORMAT);
             $userLogged = SessionUtils::getUserLogged();
             $newCommentDTO = new CommentDTO(NULL, $formDataObj[WRITE_COMMENT_FORM . TEXT], $timestamp, $formDataObj[WRITE_COMMENT_FORM . POSTID], $userLogged);
             $postDAO = new PostDAO();
             $commentDTO = $postDAO->insertNewComment($newCommentDTO);
             if ($commentDTO->getCommentid() == 0) {
                 $errorDTO = new ErrDTO(WRITE_COMMENT_FORM);
                 $responseDTO->setResponseErr("Non è stato possibile inserire il commento del post");
                 $responseDTO->setSubElementId($formDataObj[WRITE_COMMENT_FORM . POSTID]);
                 return $errorDTO;
             } else {
                 DataModelUtils::notifyAction($commentDTO->getCommentid() . SEPARATOR . $formDataObj[WRITE_COMMENT_FORM . POSTID] . SEPARATOR . $userLogged->getUserId() . SEPARATOR . SessionUtils::getDashboardId(), WRITE_COMMENT_FORM);
                 return $commentDTO;
             }
         } else {
             if (array_key_exists(TEXT, $validationError)) {
                 $responseDTO->setErrField(TEXT, $validationError[TEXT]);
             }
             return $responseDTO;
         }
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (Exception $e) {
         throw $e;
     }
 }
예제 #7
0
 public function denyFriendshipModel($notificationId, $userForm)
 {
     $formObjRaw = new FormDTO(DENY_FRIENDSHIP_FORM, $userForm);
     $formObjRaw->setSubElementId($notificationId);
     try {
         $formDataObj = $formObjRaw->getFormData();
         $friendDAO = new FriendsDAO();
         $friendId = $friendDAO->deleteFriend($formDataObj[DENY_FRIENDSHIP_FORM . FRIENDID]);
         $notificationDAO = new NotificationDAO();
         $notificationDAO->deleteNotificationByNotificationId($notificationId);
         $responseDTO = new ResponseDTO(DENY_REGISTRATION_FORM);
         $responseDTO->setResponseSucc($notificationId);
         return $notificationId;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (Exception $e) {
         throw $e;
     }
 }
예제 #8
0
 function changeUserPwdModel($pwdForm)
 {
     $formObjRaw = new FormDTO(CHANGE_PWD_FORM, $pwdForm);
     $responseDTO = new ResponseDTO(CHANGE_PWD_FORM);
     try {
         $formDataObj = $formObjRaw->getFormData();
         $validator = new FormValidator(CHANGE_PWD_FORM, $formDataObj);
         $validationError = $validator->checkAll();
         if (sizeof($validationError) == 0) {
             $userLogged = SessionUtils::getUserLogged();
             $hashedPwd = PasswordUtils::getPassword($formDataObj[CHANGE_PWD_FORM . PASSWORD]);
             $userDTO = new UserDTO($userLogged->getUserId(), NULL, $hashedPwd, NULL, NULL, NULL, NULL, NULL);
             $userDAO = new UserDAO();
             $userLoggedDTO = $userDAO->checkPassword($userDTO);
             if (is_null($userLoggedDTO)) {
                 $responseDTO->setResponseSucc("Questa password non esiste");
                 return $responseDTO;
             }
             $hashedPwd = PasswordUtils::getPassword($formDataObj[CHANGE_PWD_FORM . NEW_PASSWORD]);
             $userDTO->setPassword($hashedPwd);
             $userPwdUpdated = $userDAO->updateUserPassword($userDTO);
             return $userDTO;
         } else {
             if (array_key_exists(PASSWORD, $validationError)) {
                 $responseDTO->setErrField(PASSWORD, $validationError[PASSWORD]);
             }
             if (array_key_exists(NEW_PASSWORD, $validationError)) {
                 $responseDTO->setErrField(NEW_PASSWORD, $validationError[NEW_PASSWORD]);
             }
             if (array_key_exists(CONFIRM_PASSWORD, $validationError)) {
                 $responseDTO->setErrField(CONFIRM_PASSWORD, $validationError[CONFIRM_PASSWORD]);
             }
             //                var_dump($validationError);
             //                var_dump($responseDTO);die;
         }
         return $responseDTO;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         throw $authExp;
     } catch (Exception $e) {
         throw $e;
     }
 }