/** * @param $entityId * @param $startDate * @param $endDate * @param array $weekdays * @return bool */ public function push($entityId, $startDate, $endDate, $weekdays = [], $entityType = self::ENTITY_TYPE_APARTMENT) { try { /** * @var \DDD\Dao\Queue\InventorySynchronizationQueue $dao */ $dao = $this->getServiceLocator()->get('dao_queue_inventory_synchronization_queue'); $dates = $this->constructDateCollectionFromRange($startDate, $endDate); $queueItem = []; foreach ($dates as $date) { if (is_array($weekdays) && !empty($weekdays) && !in_array(Helper::siftWeekDay($date->format('w')), $weekdays)) { continue; } $formattedDate = $date->format('Y-m-d'); if ($formattedDate < date('Y-m-d')) { continue; } $queueItem[] = ['addition_date' => date('Y-m-d H:i:s'), 'entity_id' => $entityId, 'date' => $formattedDate, 'entity_type' => $entityType]; } /* * Push data into queue table with multi-insert queries of * max. self::MULTI_INSERT_MAX_COUNT records per query. */ $chunkedData = array_chunk($queueItem, self::MULTI_INSERT_MAX_COUNT); foreach ($chunkedData as $chunk) { $dao->multiInsert($chunk, true); } return true; } catch (\Exception $e) { return false; } }