コード例 #1
0
 private function parseForm(HTTPRequest $request, AnnouncementPro $announce)
 {
     $title = htmlspecialchars($request->postData('title'));
     $isPublished = $request->postExists('is-published');
     $description = htmlspecialchars($request->postData('description'));
     $pricePublic = htmlspecialchars($request->postData('price-public'));
     if ($request->postExists('has-tips')) {
         $tips = htmlspecialchars($request->postData('tips'));
     } else {
         $tips = '';
     }
     $rawMaterial = htmlspecialchars($request->postData('raw-material'));
     $address1 = htmlspecialchars($request->postData('address1'));
     $address2 = htmlspecialchars($request->postData('address2'));
     $zipCode = htmlspecialchars($request->postData('zip-code'));
     $city = htmlspecialchars($request->postData('city'));
     $country = 'FRANCE';
     $departmentId = htmlspecialchars($request->postData('department'));
     $regionId = $this->_departmentsManager->get($departmentId)->getRegionId();
     $categoryId = htmlspecialchars($request->postData('category'));
     $subCategoryId = htmlspecialchars($request->postData('sub-category'));
     $userId = $this->_user->id();
     //Parsing
     $announce->setTitle($title);
     $announce->setIsPublished($isPublished);
     $announce->setDescription($description);
     $announce->setPricePublic($this->str2num($pricePublic));
     $announce->setTips($tips);
     $announce->setRawMaterial($rawMaterial);
     $announce->setAddress1($address1);
     $announce->setAddress2($address2);
     $announce->setZipCode($zipCode);
     $announce->setCity($city);
     $announce->setCountry($country);
     $announce->setDepartmentId($departmentId);
     $announce->setRegionId($regionId);
     $announce->setCategoryId($categoryId);
     $announce->setSubCategoryId($subCategoryId);
     $announce->setUserId($userId);
     $announce->setAdminComment('');
     // Demande de suppression de photo
     if ($request->postExists('delete-photo-main')) {
         unlink($_SERVER['DOCUMENT_ROOT'] . AnnouncementPro::ANNOUNCEMENT_PRO_DIRECTORY . $announce->id() . '/' . $announce->getPhotoMain());
         unlink($_SERVER['DOCUMENT_ROOT'] . AnnouncementPro::ANNOUNCEMENT_PRO_DIRECTORY . $announce->id() . '/' . AnnouncementPro::THUMBNAILS_PREFIX . $announce->getPhotoMain());
         $announce->setPhotoMain('');
     }
     if ($request->postExists('delete-photo-option-1')) {
         unlink($_SERVER['DOCUMENT_ROOT'] . AnnouncementPro::ANNOUNCEMENT_PRO_DIRECTORY . $announce->id() . '/' . $announce->getPhotoOption1());
         unlink($_SERVER['DOCUMENT_ROOT'] . AnnouncementPro::ANNOUNCEMENT_PRO_DIRECTORY . $announce->id() . '/' . AnnouncementPro::THUMBNAILS_PREFIX . $announce->getPhotoOption1());
         $announce->setPhotoOption1('');
     }
     if ($request->postExists('delete-photo-option-2')) {
         unlink($_SERVER['DOCUMENT_ROOT'] . AnnouncementPro::ANNOUNCEMENT_PRO_DIRECTORY . $announce->id() . '/' . $announce->getPhotoOption2());
         unlink($_SERVER['DOCUMENT_ROOT'] . AnnouncementPro::ANNOUNCEMENT_PRO_DIRECTORY . $announce->id() . '/' . AnnouncementPro::THUMBNAILS_PREFIX . $announce->getPhotoOption2());
         $announce->setPhotoOption2('');
     }
 }