/**
  * Run method with main page logic
  * 
  * Populate template and display form for creating a new album entry. For POST request,
  * validate form data and save information to database. Available to admins only
  * @access public
  */
 public function run()
 {
     $session = Session::getInstance();
     $user = $session->getUser();
     if (!$user || !$user->isAdmin()) {
         $session->setMessage("Do not have permission to access", Session::MESSAGE_ERROR);
         header("Location: " . BASE_URL);
         return;
     }
     $albumDAO = AlbumDAO::getInstance();
     $album = null;
     $form_errors = array();
     $form_values = array("title" => "");
     if (!empty($_POST)) {
         $form_values["title"] = isset($_POST["title"]) ? trim($_POST["title"]) : "";
         if (empty($form_values["title"])) {
             $form_errors["title"] = "No title specified";
         }
         if (empty($form_errors)) {
             $album = new Album();
             $album->setTitle($form_values["title"]);
             if ($albumDAO->insert($album)) {
                 $session->setMessage("Album saved");
                 header("Location: edit_album.php?id={$album->id}");
                 return;
             } else {
                 $session->setMessage("Album not saved");
             }
         }
     }
     $this->template->render(array("title" => "Create Album", "session" => $session, "main_page" => "create_album_tpl.php", "album" => $album, "form_values" => $form_values, "form_errors" => $form_errors));
 }
 /**
  * Run method with main page logic
  * 
  * Read in list of albums and the latest photos for each album. Pagination enabled.
  * Populate template with data and display results in the page.
  * @access public
  */
 public function run()
 {
     $PAGINATION_LIMIT = 10;
     $session = Session::getInstance();
     $user = $session->getUser();
     $albumDAO = AlbumDAO::getInstance();
     $photoDAO = PhotoDAO::getInstance();
     $page = isset($_GET["page"]) && is_numeric($_GET["page"]) ? intval($_GET["page"]) : 1;
     if ($page < 1) {
         $page = 1;
     }
     $count = $paginator = $paginator_page = null;
     $album = $photo_info_array = null;
     $title = "";
     $count = $albumDAO->count();
     $paginator = new Paginator($count, $PAGINATION_LIMIT);
     $paginator_page = $paginator->getPage($page);
     $album_array = $albumDAO->all(array("limit" => $paginator_page));
     $photo_info_array = array();
     foreach ($album_array as $album) {
         $count = $photoDAO->countByAlbum($album);
         if ($count > 0) {
             $tmp_paginator = new Paginator($count, 1);
             $tmp_paginator_page = $paginator->getPage($page);
             // Only get latest item
             list($latest_photo) = $photoDAO->allByAlbum($album, array("order" => "id DESC", "limit" => $tmp_paginator_page));
             $photo_info_array[] = array($count, $latest_photo);
         }
     }
     $this->template->render(array("title" => "Album List", "main_page" => "album_list_tpl.php", "session" => $session, "album_array" => $album_array, "photo_info_array" => $photo_info_array, "paginator_page" => $paginator_page));
 }
 /**
  * Run method with main page logic
  * 
  * Read in album information and photos associated with an album from the database.
  * Populate template and display results in the page. Pagination possible
  * @access public
  */
 public function run()
 {
     $PAGINATION_LIMIT = 10;
     $session = Session::getInstance();
     $user = $session->getUser();
     $albumDAO = AlbumDAO::getInstance();
     $photoDAO = PhotoDAO::getInstance();
     $album = $photo_array = $photo_count = $paginator_page = $queryVars = null;
     $title = "";
     $page = isset($_GET["page"]) && is_numeric($_GET["page"]) ? intval($_GET["page"]) : 1;
     if ($page < 1) {
         $page = 1;
     }
     $id = isset($_GET["id"]) && is_numeric($_GET["id"]) ? intval($_GET["id"]) : 0;
     if ($id <= 0) {
         header("Location: " . BASE_URL);
         return;
     }
     $album = $albumDAO->load($id, array("joins" => true));
     if ($album) {
         $title = $album->getTitle();
         $count = $photoDAO->countByAlbum($album);
         $paginator = new Paginator($count, $PAGINATION_LIMIT);
         $paginator_page = $paginator->getPage($page);
         $photo_array = $photoDAO->allByAlbum($album, array("limit" => $paginator_page));
         $queryVars = array("id" => $id);
     }
     $this->template->render(array("title" => "View Album - {$title}", "session" => $session, "album" => $album, "photo_array" => $photo_array, "paginator_page" => $paginator_page, "queryVars" => $queryVars, "main_page" => "view_album_tpl.php"));
 }
 /**
  * Run method with main page logic
  * 
  * Populate template and display form for editing an album entry. For POST requests,
  * check user credentials, check if album exists and then update entry in database.
  * Available to admins only
  * @access public
  */
 public function run()
 {
     $session = Session::getInstance();
     $user = $session->getUser();
     if (!$user || !$user->isAdmin()) {
         $session->setMessage("Do not have permission to access", Session::MESSAGE_ERROR);
         header("Location: " . BASE_URL);
         return;
     }
     $albumDAO = AlbumDAO::getInstance();
     $album = null;
     $form_errors = array();
     $form_values = array("id" => "", "title" => "");
     if (!empty($_POST)) {
         $form_values["id"] = isset($_POST["id"]) && is_numeric($_POST["id"]) ? intval($_POST["id"]) : "";
         $form_values["title"] = isset($_POST["title"]) ? trim($_POST["title"]) : "";
         if (empty($form_values["id"])) {
             $form_errors["id"] = "No id specified";
         }
         if (empty($form_values["title"])) {
             $form_errors["title"] = "No title specified";
         }
         if (empty($form_errors)) {
             $album = $albumDAO->load($form_values["id"]);
             if ($album) {
                 $album->setTitle($form_values["title"]);
                 if ($albumDAO->save($album)) {
                     $session->setMessage("Album saved");
                     header("Location: edit_album.php?id={$album->id}");
                     return;
                 } else {
                     $session->setMessage("Album not saved");
                 }
             }
         } else {
             if (empty($form_errors["id"])) {
                 $album = $albumDAO->load($form_values["id"]);
             }
         }
     } else {
         if (!empty($_GET)) {
             $form_values["id"] = isset($_GET["id"]) ? $_GET["id"] : "";
             if (empty($form_values["id"])) {
                 header("Location: " . BASE_URL);
                 return;
             } else {
                 $album = $albumDAO->load($form_values["id"]);
                 // Album does not exist. Pass null to template
                 if (!$album) {
                 } else {
                     $form_values["id"] = $album->getId();
                     $form_values["title"] = $album->getTitle();
                 }
             }
         }
     }
     $this->template->render(array("title" => "Edit Album", "session" => $session, "main_page" => "edit_album_tpl.php", "album" => $album, "form_values" => $form_values, "form_errors" => $form_errors));
 }
示例#5
0
 public static function uploadPhotoModel($uploadedPhoto, $albumId, $formType, $latitude = NULL, $longitude = NULL)
 {
     $responseDTO = new ResponseDTO($formType);
     try {
         $userLogged = SessionUtils::getUserLogged();
         $fileName = $uploadedPhoto["name"];
         $fileType = $uploadedPhoto["type"];
         $tmpFileName = $uploadedPhoto["tmp_name"];
         $rawImage = FileUtils::getRawImage($fileType, $tmpFileName);
         $fileName = FileUtils::getFileName($fileName, $userLogged->getUserId(), $albumId);
         $redimImage = FileUtils::getRedimensionedImage($tmpFileName, $rawImage);
         if (imagejpeg($redimImage, $fileName, 100)) {
             $photoDAO = new PhotoDAO();
             $newPhotoDTO = new PhotoDTO(NULL, $fileName, $latitude, $longitude);
             $newPhotoDTO = $photoDAO->insertNewPhoto($newPhotoDTO);
             if ($newPhotoDTO->getPhotoId() == 0) {
                 $responseDTO->setErrField(ERROR_RESPONSE, "Errore durante l'inserimento della foto [" . $newPhotoDTO->getPhotoUrl() . "]");
             } else {
                 $albumDAO = new AlbumDAO();
                 if (is_null($albumId)) {
                     $albumId = $albumDAO->getDefaultAlbumId($userLogged->getUserId());
                 }
                 if ($formType !== ADD_ALBUM_FORM) {
                     $photoInAlbumId = $albumDAO->insertNewUserPhotoAlbum($userLogged->getUserId(), $albumId, $newPhotoDTO->getPhotoId());
                 }
                 if (!is_null($latitude) && !is_null($longitude)) {
                     $uploadedAddress = FileUtils::saveAddressModel($latitude, $longitude, $formType);
                 }
                 return $newPhotoDTO;
             }
         } else {
             $responseDTO->setErrField(ERROR_RESPONSE, "Errore durante la copia del file sul server PHP");
         }
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $userAuth) {
         throw $userAuth;
     } catch (Exception $e) {
         throw $e;
     }
 }
 /**
  * Run method with main page logic
  * 
  * Read in albums from the database. Displays an interface to administer album data
  * for allowing bulk deletion of albums, deletion of a single
  * album and links to edit and view each album entry. Pagination enabled.
  * Available to admins only
  * @access public
  */
 public function run()
 {
     $PAGINATION_LIMIT = 10;
     $session = Session::getInstance();
     $user = $session->getUser();
     if (!$user || !$user->isAdmin()) {
         $session->setMessage("Do not have permission to access", Session::MESSAGE_ERROR);
         header("Location: " . BASE_URL);
         return;
     }
     $page = isset($_GET["page"]) && is_numeric($_GET["page"]) ? $_GET["page"] : 1;
     if ($page < 1) {
         $page = 1;
     }
     $action = isset($_GET["action"]) ? trim($_GET["action"]) : "";
     $albumDAO = AlbumDAO::getInstance();
     $album_array = $paginator_page = null;
     $content_title = "";
     // Check for POST request and necessary data for deletion
     if (!empty($_POST) && !empty($_POST["ids"]) && !empty($_POST["action"])) {
         $action = isset($_POST["action"]) ? trim($_POST["action"]) : "";
         if (!strcmp($action, "delete") == 0) {
             header("Location: " . BASE_URL);
             return;
         }
         $status = $albumDAO->deleteByIds($_POST["ids"]);
         if ($status) {
             $session->setMessage("Selected pages deleted");
             header("Location: {$_SERVER["PHP_SELF"]}");
             return;
         } else {
             $session->setMessage("Deletion failed", Session::MESSAGE_ERROR);
             header("Location: {$_SERVER["PHP_SELF"]}");
             return;
         }
     } else {
         if (strcmp($action, "delete") == 0 && !empty($_GET["ids"])) {
             $content_title = "Delete Album";
             $album_array = $albumDAO->allByIds($_GET["ids"]);
         } else {
             if (strcmp($action, "delete") == 0) {
             } else {
                 $count = $albumDAO->count();
                 $paginator = new Paginator($count, $PAGINATION_LIMIT);
                 $paginator_page = $paginator->getPage($page);
                 $album_array = $albumDAO->all(array("limit" => $paginator_page));
             }
         }
     }
     $this->template->render(array("title" => "Admin - Album Options", "main_page" => "album_options_tpl.php", "session" => $session, "album_array" => $album_array, "paginator_page" => $paginator_page, "action" => $action, "content_title" => $content_title));
 }
 public function run()
 {
     $session = Session::getInstance();
     $user = $session->getUser();
     if (!$user || !$user->isAdmin()) {
         $session->setMessage("Do not have permission to access", Session::MESSAGE_ERROR);
         header("Location: " . BASE_URL);
         return;
     }
     $albumDAO = AlbumDAO::getInstance();
     $delete_album = $album_array = $move_album = null;
     $form_errors = array();
     $form_values = array("id" => "", "album_move" => -1);
     if (!empty($_POST)) {
         $id = isset($_POST["id"]) ? trim($_POST["id"]) : "";
         $album_move = isset($_POST["album_move"]) && is_numeric($_POST["album_move"]) ? intval($_POST["album_move"]) : -1;
         if (empty($id)) {
             header("Location: " . BASE_URL);
             return;
         }
         if ($album_move > 0) {
             $move_album = $albumDAO->load($album_move);
         }
         // Move photos to different category
         if (is_numeric($id) && $move_album) {
             $delete_album = $albumDAO->load($id);
             if ($delete_album) {
                 $album_photos = $photoDAO->loadByAlbum($delete_album);
                 if ($albumDAO->delete($delete_album)) {
                     if ($album_photos) {
                         $photoDAO->moveByAlbumId($delete_album, $move_album);
                     }
                     $session->setMessage("Album deleted and photos moved");
                     header("Location: " . BASE_URL);
                     return;
                 } else {
                     $session->setMessage("Could not delete album", Session::MESSAGE_ERROR);
                 }
             }
         } else {
             if (is_numeric($id) && $album_move == 0) {
                 $delete_album = $albumDAO->load($id);
                 if ($delete_album) {
                     $album_photos = $photoDAO->loadByAlbum($delete_album);
                     if ($albumDAO->delete($delete_album)) {
                         if ($album_photos) {
                             $photo_ids = array();
                             foreach ($album_photos as $photo) {
                                 $photo_ids[] = $photo->getId();
                             }
                             $photoDAO->deleteByIds($photo_ids);
                         }
                         $session->setMessage("Album and photos deleted");
                         header("Location: " . BASE_URL);
                         return;
                     } else {
                         $session->setMessage("Could not delete album", Session::MESSAGE_ERROR);
                     }
                 }
             } else {
                 if (is_numeric($id)) {
                     $delete_album = $albumDAO->load($id);
                     if ($delete_album) {
                         if ($albumDAO->delete($delete_album)) {
                             $session->setMessage("Album deleted");
                             header("Location: " . BASE_URL);
                             return;
                         } else {
                             $session->setMessage("Could not delete album", Session::MESSAGE_ERROR);
                         }
                     }
                 }
             }
         }
     } else {
         if (!empty($_GET)) {
             $id = isset($_GET["id"]) ? trim($_GET["id"]) : "";
             if (empty($id)) {
                 header("Location: " . BASE_URL);
                 return;
             } else {
                 if (is_numeric($id)) {
                     $delete_album = $albumDAO->load($id);
                     if ($delete_album) {
                         $form_values["id"] = $delete_album->getId();
                         $album_array = $albumDAO->allExclude($delete_album);
                         //print_r ($album_array);
                         //print_r ($delete_album);
                     }
                 }
             }
         } else {
             header("Location: " . BASE_URL);
             return;
         }
     }
     $this->template->render(array("title" => "Admin - Delete Album", "main_page" => "delete_album_tpl.php", "user" => $user, "session" => $session, "delete_album" => $delete_album, "form_errors" => $form_errors, "form_values" => $form_values, "album_array" => $album_array));
 }
示例#8
0
 /**
  * Parse the options array for limit clauses and order by clauses. The valid keys and value types are specified below.
  * limit - Page object. Will take values from a Paginator Page object and
  * set LIMIT and OFFSET portions of database query accordingly
  *
  * joins - bool. If true, an INNER JOIN will be done to retrieve the
  * Album associated with the page
  * 
  * order - string. Concatenate string with ORDER BY operator.
  * Will add table name to field if only associated with current table.
  * @access private
  * @param array &$options
  */
 protected function parseOptions(&$options)
 {
     if (!is_array($options)) {
         throw new InvalidArgumentException("Options for a database access function must be in an array");
     }
     if (array_key_exists("limit", $options) && $options["limit"] instanceof Page) {
         $this->query_limit .= $this->getLimitClause($options["limit"]);
     }
     if (array_key_exists("joins", $options) && $options["joins"] == true) {
         $albumDAO = AlbumDAO::getInstance();
         $this->query_select .= ", " . $albumDAO->buildColumnString();
         $this->query_joins .= " INNER JOIN (" . $albumDAO->getTableName() . ") ON (" . $albumDAO->getTableName() . ".id = " . $this->getTableName() . ".albumId) ";
         $this->select_columns = array_merge($this->select_columns, $albumDAO->buildColumnArray());
         $this->joins = true;
     }
     if (array_key_exists("order", $options) && is_string($options["order"])) {
         // Reference to album member
         if (strpos($options["order"], ".") === false) {
             $this->query_order = "ORDER BY " . $this->tableName . "." . $options["order"];
         } else {
             if (strpos($options["order"], "albums.") === 0 && $this->joins) {
                 $this->query_order = "ORDER BY " . $options["order"];
             } else {
                 throw new InvalidArgumentException("Invalid configuration for order option");
             }
         }
     }
 }
 /**
  * Run method with main page logic
  * 
  * Populate template and display form for editing an photo entry. For POST requests,
  * check user credentials, check if photo exists and then update entry in database.
  * Available to admins only
  * @access public
  */
 public function run()
 {
     $session = Session::getInstance();
     $user = $session->getUser();
     if (!$user || !$user->isAdmin()) {
         $session->setMessage("Do not have permission to access", Session::MESSAGE_ERROR);
         header("Location: " . BASE_URL);
         return;
     }
     $photoDAO = PhotoDAO::getInstance();
     $albumDAO = AlbumDAO::getInstance();
     $photo = null;
     $form_errors = array();
     $form_values = array("id" => "", "albumid" => "", "title" => "", "description" => "");
     if (!empty($_POST)) {
         $form_values["id"] = isset($_POST["id"]) && is_numeric($_POST["id"]) ? intval($_POST["id"]) : "";
         $form_values["albumid"] = isset($_POST["albumid"]) && is_numeric($_POST["albumid"]) ? intval($_POST["albumid"]) : "";
         $form_values["title"] = isset($_POST["title"]) ? trim($_POST["title"]) : "";
         $form_values["description"] = isset($_POST["description"]) ? trim($_POST["description"]) : "";
         if (empty($form_values["id"])) {
             $form_errors["id"] = "No id specified";
         }
         $photo = $photoDAO->load($form_values["id"]);
         if (!$photo) {
             $form_errors["id"] = "Photo does not exist";
         }
         if (empty($form_values["albumid"])) {
             $form_errors["albumid"] = "No albumid specified";
         } else {
             if (!$albumDAO->load($form_values["albumid"])) {
                 $form_errors["albumid"] = "Album does not exist";
             }
         }
         if (empty($form_values["title"])) {
             $form_errors["title"] = "No title specified";
         }
         if (empty($form_values["description"])) {
             $form_errors["description"] = "No description specified";
         }
         // Check if image will be changed
         $upload_path = "";
         if (!empty($_FILES["imagefile"]) && $_FILES["imagefile"]["error"] != UPLOAD_ERR_NO_FILE) {
             if ($_FILES["imagefile"]["error"] != UPLOAD_ERR_OK) {
                 $form_errors["imagefile"] = "File upload failed";
             } else {
                 $info = getimagesize($_FILES["imagefile"]["tmp_name"]);
                 $path = pathinfo($_FILES["imagefile"]["name"]);
                 $upload_path = joinPath(Photo::UPLOAD_DIR, strftime("%Y_%m"), basename($_FILES['imagefile']['name']));
                 $thumbLoc = joinPath(Photo::THUMBNAIL_DIR, strftime("%Y_%m"), $path["filename"] . "_thumb.jpg");
                 $smallThumbLoc = joinPath(Photo::THUMBNAIL_DIR, strftime("%Y_%m"), $path["filename"] . "_thumb_small.jpg");
                 if (!$info || !(strtolower($path["extension"]) != ".png" && strtolower($path["extension"]) != ".jpg" && strtolower($path["extension"]) != ".jpeg")) {
                     $form_errors["imagefile"] = "An invalid file was uploaded";
                 } else {
                     if (file_exists($upload_path)) {
                         unlink($upload_path);
                         if (file_exists($thumbLoc)) {
                             unlink($thumbLoc);
                         }
                         if (file_exists($smallThumbLoc)) {
                             unlink($smallThumbLoc);
                         }
                         //$form_errors["imagefile"] = "Filename already exists.  Please choose different name or delete file first";
                     }
                 }
             }
         }
         if (empty($form_errors)) {
             $photo->setAlbumId($form_values["albumid"]);
             $photo->setTitle($form_values["title"]);
             $photo->setDescription($form_values["description"]);
             // New image has been uploaded
             if (!empty($_FILES["imagefile"]) && $_FILES["imagefile"]["error"] != UPLOAD_ERR_NO_FILE) {
                 if (!file_exists(dirname($upload_path))) {
                     mkdir(dirname($upload_path));
                 }
                 if (move_uploaded_file($_FILES["imagefile"]["tmp_name"], $upload_path)) {
                     $photo->setFileLoc($upload_path);
                     // Reset thumbnail location in case new image does not need a thumbnail
                     $photo->setThumbLoc("");
                     // Create thumbnail
                     if ($info[0] > Photo::MAX_WIDTH) {
                         $phpThumb = new phpThumb();
                         $phpThumb->setSourceFilename($photo->getFileLoc());
                         $phpThumb->setParameter('w', Photo::MAX_WIDTH);
                         $phpThumb->setParameter('config_output_format', 'jpeg');
                         if (!file_exists(dirname($thumbLoc))) {
                             mkdir(dirname($thumbLoc));
                         }
                         if ($phpThumb->GenerateThumbnail() && $phpThumb->RenderToFile($thumbLoc)) {
                             $photo->setThumbLoc($thumbLoc);
                             $phpThumb = new phpThumb();
                             $phpThumb->setSourceFilename($photo->getFileLoc());
                             $phpThumb->setParameter('h', Photo::SMALL_THUMB_HEIGHT);
                             $phpThumb->setParameter('config_output_format', 'jpeg');
                             $phpThumb->GenerateThumbnail();
                         } else {
                             if (file_exists($photo->getFileLoc())) {
                                 unlink($photo->getFileLoc());
                             }
                             $form_errors["imagefile"] = "Image larger than " . Photo::MAX_WIDTH . "x" . Photo::MAX_HEIGHT . " and thumbnail generation failed";
                         }
                     }
                 } else {
                     $form_errors["imagefile"] = "File could not be moved";
                 }
             }
             if (empty($form_errors["imagefile"])) {
                 if ($photoDAO->save($photo)) {
                     $session->setMessage("Photo saved");
                     header("Location: edit_photo.php?id={$photo->getId()}");
                     return;
                 } else {
                     $session->setMessage("Photo not saved");
                 }
             }
         } else {
             if (empty($form_errors["id"])) {
                 $photo = $photoDAO->load($form_values["id"]);
             }
         }
     } else {
         if (!empty($_GET)) {
             $form_values["id"] = isset($_GET["id"]) ? $_GET["id"] : "";
             if (empty($form_values["id"])) {
                 header("Location: " . BASE_URL);
                 return;
             } else {
                 $photo = $photoDAO->load($form_values["id"]);
                 if ($photo) {
                     $form_values["id"] = $photo->getId();
                     $form_values["albumid"] = $photo->getAlbumId();
                     $form_values["title"] = $photo->getTitle();
                     $form_values["description"] = $photo->getDescription();
                 }
             }
         }
     }
     $album_array = $albumDAO->all();
     $this->template->render(array("title" => "Edit Photo", "session" => $session, "main_page" => "edit_photo_tpl.php", "photo" => $photo, "form_values" => $form_values, "form_errors" => $form_errors, "album_array" => $album_array));
 }
示例#10
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;
     }
 }
示例#11
0
 public function getUserAlbumList($userProfile)
 {
     try {
         $albumDAO = new AlbumDAO();
         $albumListDTO = $albumDAO->getUserAlbumList($userProfile);
         return $albumListDTO;
     } catch (PDOException $pdoe) {
         throw $pdoe;
     } catch (UserNotAuthenticatedExceptionDTO $authExp) {
         throw $authExp;
     } catch (Exception $e) {
         throw $e;
     }
 }
示例#12
0
 /**
  * Retrieve instance of an AlbumDAO or create one if it does
  * not exist.
  *
  * @access public
  * @static
  * @return AlbumDAO
  */
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new self();
     }
     return self::$instance;
 }
示例#13
0
 public function signUpModel($registrationForm)
 {
     $formObjRaw = new FormDTO(REGISTRATION_FORM, $registrationForm);
     $responseDTO = new ResponseDTO(REGISTRATION_FORM);
     try {
         $formDataObj = $formObjRaw->getFormData();
         $validator = new FormValidator(REGISTRATION_FORM, $formDataObj);
         $validationError = $validator->checkAll();
         if (sizeof($validationError) == 0) {
             $hashedPwd = PasswordUtils::getPassword($formDataObj[REGISTRATION_FORM . PASSWORD]);
             $userDTO = new UserDTO(NULL, $formDataObj[REGISTRATION_FORM . USERNAME], $hashedPwd, NULL, USER, NULL, $formDataObj[REGISTRATION_FORM . EMAIL], NULL);
             $userDAO = new UserDAO();
             $existingUser = $userDAO->checkIfUserExist($userDTO);
             if (!is_null($existingUser)) {
                 $responseDTO->setErrField(ERROR_RESPONSE, "Utente gi&agrave; presente con questa mail: " . $userDTO->getEmail() . " o con questo username: "******"Verrà inviata una mail a questo indirizzo: " . $userDTO->getEmail());
                         //                            } else {
                         //                                $responseDTO->setErrField(ERROR_RESPONSE, "Errore durante l'invio della mail");
                         //                            }
                     } else {
                         $responseDTO->setErrField(ERROR_RESPONSE, "Errore durante l'inserimento dell'album");
                     }
                 } else {
                     $responseDTO->setErrField(ERROR_RESPONSE, "Errore durante l'inserimento dello user");
                 }
             }
         } else {
             if (array_key_exists(USERNAME, $validationError)) {
                 $responseDTO->setErrField(USERNAME, $validationError[USERNAME]);
             }
             if (array_key_exists(PASSWORD, $validationError)) {
                 $responseDTO->setErrField(PASSWORD, $validationError[PASSWORD]);
             }
             if (array_key_exists(CONFIRM_PASSWORD, $validationError)) {
                 $responseDTO->setErrField(CONFIRM_PASSWORD, $validationError[CONFIRM_PASSWORD]);
             }
             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;
     }
 }