protected function modify(AnnouncementPro $announcementPro) { $q = $this->dao->prepare('UPDATE ' . $this->table() . ' SET TITLE = :title, DESCRIPTION = :description, PRICE_PUBLIC = :pricePublic, PHOTO_MAIN = :photoMain, PHOTO_OPTION_1 = :photoOption1, PHOTO_OPTION_2 = :photoOption2, TIPS = :tips, RAW_MATERIAL = :rawMaterial, ADDRESS_1 = :address1, ADDRESS_2 = :address2, ZIP_CODE = :zipCode, CITY = :city, COUNTRY = :country, REGION_ID =:regionId, DEPARTMENT_ID =:departmentId, IS_PUBLISHED = :isPublished, PUBLICATION_DATE = :publicationDate, CATEGORY_ID = :categoryId, SUB_CATEGORY_ID = :subCategoryId, USER_ID = :userId, STATE_ID = :stateId, ADMIN_COMMENT = :adminComment WHERE ID = :id'); $q->bindValue(':title', $announcementPro->getTitle()); $q->bindValue(':description', $announcementPro->getDescription()); $q->bindValue(':pricePublic', $announcementPro->getPricePublic()); $q->bindValue(':photoMain', $announcementPro->getPhotoMain()); $q->bindValue(':photoOption1', $announcementPro->getPhotoOption1()); $q->bindValue(':photoOption2', $announcementPro->getPhotoOption2()); $q->bindValue(':tips', $announcementPro->getTips()); $q->bindValue(':rawMaterial', $announcementPro->getRawMaterial()); $q->bindValue(':address1', $announcementPro->getAddress1()); $q->bindValue(':address2', $announcementPro->getAddress2()); $q->bindValue(':zipCode', $announcementPro->getZipCode()); $q->bindValue(':city', $announcementPro->getCity()); $q->bindValue(':country', $announcementPro->getCountry()); $q->bindValue(':regionId', $announcementPro->getRegionId()); $q->bindValue(':departmentId', $announcementPro->getDepartmentId()); $q->bindValue(':isPublished', $announcementPro->getIsPublished()); $q->bindValue(':publicationDate', $announcementPro->getPublicationDate()); $q->bindValue(':categoryId', $announcementPro->getCategoryId(), PDO::PARAM_INT); $q->bindValue(':subCategoryId', $announcementPro->getSubCategoryId(), PDO::PARAM_INT); $q->bindValue(':userId', $announcementPro->getUserId(), PDO::PARAM_INT); $q->bindValue(':stateId', $announcementPro->getStateId(), PDO::PARAM_INT); $q->bindValue(':adminComment', $announcementPro->getAdminComment()); $q->bindValue(':id', $announcementPro->id()); $q->execute(); }
private function savePhoto(AnnouncementPro $announce, $target, $file) { if ($file['error'] == 0) { $simpleImage = new SimpleImage(); $thumbnailsSimpleImage = new SimpleImage(); $simpleImage->load($file['tmp_name']); $thumbnailsSimpleImage->load($file['tmp_name']); if (!is_null($simpleImage->image_type)) { $height = $simpleImage->getHeight(); $width = $simpleImage->getWidth(); //Redimensionnement de l'image original en format modéré if ($height > 1200 || $width > 1600) { if ($height > $width) { $simpleImage->resizeToHeight(1200); } else { $simpleImage->resizeToWidth(1600); } } //Redimensionnement de l'image original en miniature if ($height > $width) { $thumbnailsSimpleImage->resizeToHeight(300); } else { $thumbnailsSimpleImage->resizeToWidth(300); } $filename = $target . '-' . time() . '.jpg'; $thumbnails = AnnouncementPro::THUMBNAILS_PREFIX . $filename; $simpleImage->save($_SERVER['DOCUMENT_ROOT'] . AnnouncementPro::ANNOUNCEMENT_PRO_DIRECTORY . $announce->id() . '/' . $filename); $thumbnailsSimpleImage->save($_SERVER['DOCUMENT_ROOT'] . AnnouncementPro::ANNOUNCEMENT_PRO_DIRECTORY . $announce->id() . '/' . $thumbnails); $getMethod = 'get' . $target; $setMethod = 'set' . $target; if ($announce->{$getMethod}() != AnnouncementPro::IMAGE_DEFAULT && $announce->{$getMethod}() != '') { unlink($_SERVER['DOCUMENT_ROOT'] . AnnouncementPro::ANNOUNCEMENT_PRO_DIRECTORY . $announce->id() . '/' . $announce->{$getMethod}()); unlink($_SERVER['DOCUMENT_ROOT'] . AnnouncementPro::ANNOUNCEMENT_PRO_DIRECTORY . $announce->id() . '/' . AnnouncementPro::THUMBNAILS_PREFIX . $announce->{$getMethod}()); } $announce->{$setMethod}($filename); } } }