Example #1
0
 function deletePhotoModel($photoId, $filename)
 {
     $responseDTO = new ResponseDTO(DELETE_PHOTO_FORM);
     try {
         $userLogged = SessionUtils::getUserLogged();
         $defaultUserPhotoProfileId = $userLogged->getProfilePhoto()->getPhotoId();
         $photoDAO = new PhotoDAO();
         if ($photoId == $defaultUserPhotoProfileId) {
             $uploadedPhoto = new PhotoDTO(1, DEFAULT_USER_PHOTOPROFILE_URL);
             $updateProfilePhoto = $photoDAO->updateProfilePhoto($uploadedPhoto);
             $userLogged = SessionUtils::getUserLogged();
             $userLogged->setProfilePhoto($uploadedPhoto);
             SessionUtils::setUserLogged($userLogged);
         }
         $deletedPhoto = $photoDAO->deletePhotoInAlbum($photoId);
         $deletedPhoto = $photoDAO->deletePhoto($photoId);
         if ($deletedPhoto != 1) {
             $responseDTO->setErrField(ERROR_RESPONSE, "Errore durante l'eliminazione della foto");
             $responseDTO->setSubElementId($photoId);
         } else {
             FileUtils::deletePhotoOnServer($filename);
             $responseDTO->setResponseSucc("#photo" . $photoId);
         }
         return $responseDTO;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         throw $authExp;
     } catch (Exception $e) {
         throw $e;
     }
 }
Example #2
0
 public static function recursiveUserRemoveDir($filepath)
 {
     if (!file_exists($filepath)) {
         return;
     }
     $files = scandir($filepath);
     foreach ($files as $file) {
         if ($file != "." && $file != "..") {
             $fileTBDeleted = $filepath . $file;
             if (is_dir($fileTBDeleted)) {
                 FileUtils::recursiveRemoveDir($fileTBDeleted . '/');
             } else {
                 if (is_file($fileTBDeleted)) {
                     FileUtils::deletePhotoOnServer($fileTBDeleted);
                 }
             }
         }
     }
     rmdir($filepath);
     reset($files);
 }