/**
  * @param array $newValues
  * @param ListingItem|null $listingItem
  * @return ListingItem
  * @throws OtherHoursZeroTimeException
  * @throws NegativeResultOfTimeCalcException
  * @throws ShiftEndBeforeStartException
  */
 public function prepareListingItemByFormsData(array $newValues, ListingItem $listingItem = null)
 {
     $workedHours = new WorkedHours($newValues['workStart'], $newValues['workEnd'], $newValues['lunch'], $newValues['otherHours']);
     $locality = new Locality($newValues['locality'], $newValues['user']);
     if (isset($listingItem)) {
         if (!$listingItem->getWorkedHours()->hasSameValuesAs($workedHours)) {
             $workedHours = $this->workedHoursProvider->setupWorkedHoursEntity($workedHours);
             $listingItem->setWorkedTime($workedHours, $newValues['descOtherHours']);
         }
         if (!$listingItem->getLocality()->isSameAs($locality)) {
             $locality = $this->localityProvider->setupLocalityEntity($locality);
             $listingItem->setLocality($locality);
         }
         $listingItem->setDescription($newValues['description']);
     } else {
         $day = $newValues['day'];
         if (!$newValues['listing'] instanceof Listing) {
             throw new InvalidArgumentException('Argument $newValues must have member "listing " of type ' . Listing::class);
         }
         $listing = $newValues['listing'];
         $locality = $this->localityProvider->setupLocalityEntity($locality);
         $workedHours = $this->workedHoursProvider->setupWorkedHoursEntity($workedHours);
         $listingItem = new ListingItem($day, $listing, $workedHours, $locality, $newValues['description'], $newValues['descOtherHours']);
     }
     return $listingItem;
 }
 /**
  * @param Listing $listing
  * @param WorkedHours $newWorkedHours
  * @param array $daysToChange
  * @return ListingItem[]
  */
 public function changeWorkedHours(Listing $listing, WorkedHours $newWorkedHours, array $daysToChange)
 {
     $workedHours = $this->workedHoursProvider->setupWorkedHoursEntity($newWorkedHours);
     $this->em->createQuery('UPDATE ' . ListingItem::class . ' li
          SET li.workedHours = :workedHours
          WHERE li.listing = :listing AND li.day IN (:days)')->setParameters(['workedHours' => $workedHours, 'listing' => $listing, 'days' => $daysToChange])->execute();
     $updatedItems = $items = $this->listingItemsReader->findListingItems($listing, $daysToChange);
     return $updatedItems;
 }