コード例 #1
0
 public function __construct(array $data, ItemsService $itemsService)
 {
     $this->itemsService = $itemsService;
     $this->listing = $data['listing'];
     $this->items = $data['items'];
     $items = $this->itemsService->prepareDisplayableItemsCollection($this->items);
     $this->entireListingItemsCollection = $this->itemsService->generateEntireTable($items, \DateTime::createFromFormat('!Y-m', $this->listing['l_year'] . '-' . $this->listing['l_month']));
 }
コード例 #2
0
 /**
  * @param Listing $baseListing
  * @param Listing $listingToMerge
  * @param array $selectedCollisionItems
  * @param User $ownerOfOutputListing
  * @return Listing
  * @throws NoCollisionListingItemSelectedException
  * @throws \Exception
  */
 public function mergeListings(Listing $baseListing, Listing $listingToMerge, array $selectedCollisionItems = [], User $ownerOfOutputListing)
 {
     if (!$this->haveListingsSamePeriod($baseListing, $listingToMerge)) {
         throw new RuntimeException('Given Listings must have same Period(Year and Month).');
     }
     try {
         $this->em->beginTransaction();
         $items = $this->itemsService->getMergedListOfItems($this->listingItemsReader->findListingItems($baseListing->getId()), $this->listingItemsReader->findListingItems($listingToMerge->getId()), $selectedCollisionItems);
         $newListing = new Listing($baseListing->year, $baseListing->month, $ownerOfOutputListing);
         $this->em->persist($newListing);
         foreach ($items as $item) {
             /** @var ListingItem $item */
             $item->setListing($newListing);
             $this->em->persist($item);
         }
         $this->em->flush();
         $this->em->commit();
         return $newListing;
     } catch (\Exception $e) {
         $this->em->rollback();
         $this->em->close();
         $this->onError('Merging of listings #id(' . $baseListing->getId() . ') and #id(' . $listingToMerge->getId() . ') failed.', $e, self::class);
         throw $e;
     }
 }
コード例 #3
0
 /**
  * @param Listing $baseListing
  * @param Listing $listing
  * @return array
  */
 public function getMergedListingsItemsForEntireTable(Listing $baseListing, Listing $listing)
 {
     if (!$this->haveListingsSamePeriod($baseListing, $listing)) {
         throw new InvalidArgumentException('Given Listings must have same Period(Year and Month).');
     }
     $items = $this->itemsService->mergeListingItems($this->listingItemsReader->findListingItems($baseListing->getId()), $this->listingItemsReader->findListingItems($listing->getId()));
     $days = $baseListing->getNumberOfDaysInMonth();
     $result = array();
     for ($day = 1; $day <= $days; $day++) {
         if (!array_key_exists($day, $items)) {
             $result[$day][] = new FillingItem(new \DateTime($baseListing->year . '-' . $baseListing->month . '-' . $day));
         } else {
             foreach ($items[$day] as $key => $item) {
                 $itemDec = new MergeableListingItem($item);
                 $itemDec->setAsItemFromBaseListing(true);
                 if ($key != 0) {
                     $itemDec->setAsItemFromBaseListing(false);
                 }
                 $result[$day][] = $itemDec;
             }
         }
     }
     return $result;
 }
コード例 #4
0
 /**
  * @param Listing $listing
  * @return IDisplayableItem[]
  */
 public function generateEntireTable(Listing $listing)
 {
     $listingItems = $this->listingItemsReader->findListingItems($listing);
     $displayableItems = $this->prepareDisplayableItemsCollection($listingItems);
     return $this->itemsService->generateEntireTable($displayableItems, $listing->getPeriod());
 }