src/Services/ProcessEditRoomForm.php line 18

Open in your IDE?
  1. <?php 
  2. namespace App\Services;
  3. use App\Services\Util;
  4. use App\Services\ConfigService;
  5. use App\Services\AddressToCoordinates;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use App\Entity\Room;
  8. class ProcessEditRoomForm{
  9.     private $em;
  10.     private $imArray;
  11.     private $user;
  12.     private $roomId;
  13.     public function __construct(EntityManagerInterface $em$imagesArray = array(), $user$roomId){
  14.         $this->em $em;
  15.         $this->imArray $imagesArray;
  16.         $this->user $user;
  17.         $this->roomId $roomId;
  18.     }
  19.     public function editRoom($formData): bool{
  20.         //get google api keys
  21.         $config = new ConfigService($this->em);
  22.         $apiKey $config->getMapsApiKey();
  23.         //get lat long
  24.         $address $formData->get('street')->getData() . ' ' .
  25.                     $formData->get('streetnomber')->getData() . ' ' .
  26.                     $formData->get('city')->getData() . ' ' .
  27.                     $formData->get('country')->getData();
  28.         $latLong AddressToCoordinates::latLong($address$apiKey);
  29.         //make rental contidions
  30.         $rt Util::jsonToArray($formData->get('rentalconditions')->getData());
  31.         //var_dump($rt);die();
  32.         $room $this->em->getRepository(Room::class)->findOneBy(['user_id'=>$this->user->getId(),
  33.                                                                  'id'=>$this->roomId]);
  34.         //make latlong
  35.         if($latLong != NULL){
  36.             $room->setLatLong($latLong);
  37.         }
  38.         $room->setStreet($formData->get('street')->getData());
  39.         $room->setStrNomber($formData->get('streetnomber')->getData());
  40.         $room->setFloor($formData->get('floor')->getData());
  41.         $room->setDoor($formData->get('door')->getData());
  42.         $room->setCity\ucfirst\strtolower($formData->get('city')->getData()) ) );
  43.         //$room->setPostalCode($formData->get('street')->getData());
  44.         $room->setCountry(\ucfirst\strtolower($formData->get('country')->getData()) ) );
  45.         $room->setTotalRooms($formData->get('totalrooms')->getData());
  46.         $room->setTotalBathrooms($formData->get('totalbathrooms')->getData());
  47.         $room->setBedSize($formData->get('bed_size')->getData());
  48.         $room->setLift($formData->get('lift')->getData());
  49.         $room->setDoorMan($formData->get('door_man')->getData());
  50.         $room->setRoomSize($formData->get('room_size')->getData());
  51.         $room->setWindowType($formData->get('window_type')->getData());
  52.         $room->setInnerOuterPosition($formData->get('inner_outer_position')->getData());
  53.         
  54.         $room->setTitle($formData->get('title')->getData());
  55.         $room->setDescriptionUtil::removeHtml($formData->get('description')->getData(), 10000) );
  56.         $room->setInternalRef($formData->get('internalref')->getData());
  57.         $room->setPrice($formData->get('price')->getData());
  58.         $room->setDeposit($formData->get('deposit')->getData());
  59.         $room->setRentalConditions($rt);
  60.         $room->setImages(array_merge($this->imArray$room->getImages()));
  61.         $room->setLastUpdate(\time());  
  62.         $room->setLang($formData->get('language')->getData());
  63.         //$room->setActive('1');
  64.         $room->setWifi($formData->get('wifi')->getData());
  65.         $room->setLivingRoom($formData->get('livingroom')->getData());
  66.         $room->setAvailableFrom\strtotime($formData->get('availablefrom')->getData()) );
  67.         $room->setUserId($this->user);
  68.         $this->em->persist($room);
  69.         $this->em->flush();
  70.         return $room->getId() != NULL true false;
  71.     }
  72.     
  73.     
  74. }