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; } }
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; } }
public function writeAPostModel() { $responseDTO = new ResponseDTO(WRITE_POST_FORM); $formObjRaw = new FormDTO(WRITE_POST_FORM, NULL); try { $formDataObj = $formObjRaw->getFormData(); $validator = new FormValidator(WRITE_POST_FORM, $formDataObj); $validationError = $validator->checkAll(); if (sizeof($validationError) == 0) { $uploadedPhoto = FileUtils::uploadPhotoModel($formDataObj[WRITE_POST_FORM . PHOTO], NULL, WRITE_POST_FORM, $formDataObj[WRITE_POST_FORM . LATITUDE], $formDataObj[WRITE_POST_FORM . LONGITUDE]); $uploadedPost = $this->saveNewPost($uploadedPhoto, $formDataObj); if (get_class($uploadedPost) === POSTDTO) { return $uploadedPost; } else { $responseDTO->setErrField(ADDRESS, "Errore durante l'inserimento del post"); } return $responseDTO; } else { if (array_key_exists(TEXT, $validationError)) { $responseDTO->setErrField(TEXT, $validationError[TEXT]); } if (array_key_exists(PHOTO, $validationError)) { $responseDTO->setErrField(PHOTO, $validationError[PHOTO]); } if (array_key_exists(ADDRESS, $validationError)) { $responseDTO->setErrField(ADDRESS, $validationError[ADDRESS]); } SessionUtils::setFormValue($formDataObj); } return $responseDTO; } catch (PDOException $pdoe) { throw $pdoe; } catch (UserNotAuthenticatedExceptionDTO $authExp) { throw $authExp; } catch (Exception $e) { throw $e; } }
function changeUserProfilePhoto($photoForm) { $formObjRaw = new FormDTO(PROFILE_SETTINGS_PHOTO_FORM, $photoForm); $responseDTO = new ResponseDTO(PROFILE_SETTINGS_PHOTO_FORM); try { $formDataObj = $formObjRaw->getFormData(); $validator = new FormValidator(PROFILE_SETTINGS_PHOTO_FORM, $formDataObj); $validationError = $validator->checkAll(); if (sizeof($validationError) == 0) { $userLogged = SessionUtils::getUserLogged(); $uploadedPhoto = FileUtils::uploadPhotoModel($formDataObj[PROFILE_SETTINGS_PHOTO_FORM . PHOTO], $userLogged->getDefaultAlbumId(), PROFILE_SETTINGS_PHOTO_FORM); if (get_class($uploadedPhoto) === PHOTODTO) { $photoDAO = new PhotoDAO(); $updateProfilePhoto = $photoDAO->updateProfilePhoto($uploadedPhoto); $userLogged = SessionUtils::getUserLogged(); $userLogged->setProfilePhoto($uploadedPhoto); SessionUtils::setUserLogged($userLogged); return $uploadedPhoto; } else { $responseDTO->setResponseSucc("Errore durante l'inserimento della foto profilo"); } } 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; } }