public function createQueue(\DateTime $dateFrom, \DateTime $dateTo, $membersData = []) {
    // If Member doesn't specified - get all Member ID, Campaign start, Campaign end to receive visits from CRM.
    if (empty($membersData)) {
      $membersData = $this->getAllMembersDataForQueue();
    }

    // Collect all Master Customer Ids if yesterday date is in the range of Member dates.
    $masterCustomerIds = [];
    $memberIds = [];
    foreach ($membersData as $item) {
      if (!empty($item['master_customer_id']) && ($item['start_date'] <= $dateFrom) && ($item['end_date'] >= $dateTo)) {
        $masterCustomerIds[$item['member_id']] = $item['master_customer_id'];
        $memberIds[$item['master_customer_id']] = $item['member_id'];
      }
    }

    if (empty($masterCustomerIds)) {
      return;
    }

    $queue = $this->queueFactory->get('openy_campaign_updates_member_visits');

    $interval = \DateInterval::createFromDateString('1 day');
    $period = new \DatePeriod($dateFrom, $interval, $dateTo);

    /** @var \DateTime $from */
    foreach ($period as $from) {
      // Foreach by date - for every date in date interval create queue item.
      $to = clone $from;
      $to->setTime(23, 59, 59);
      $data = [
        'date_from' => $from,
        'date_to' => $to,
      ];

      $chunks = array_chunk($masterCustomerIds, 100);
      foreach ($chunks as $chunk) {
        $data['items'] = [];
        foreach ($chunk as $masterCustomerID) {
          $memberID = $memberIds[$masterCustomerID];
          $data['items'][$memberID] = $masterCustomerID;
        }
        // Add data to queue.
        $queue->createItem($data);
      }
    }
  }
public function createQueue(\DateTime $dateFrom, \DateTime $dateTo, $membersData = []) {
    // If Member doesn't specified - get all Member ID, Campaign start, Campaign end to receive visits from CRM.
    if (empty($membersData)) {
      $membersData = $this->getAllMembersDataForQueue();
    }

    // Collect all Master Customer Ids if yesterday date is in the range of Member dates.
    $masterCustomerIds = [];
    $memberIds = [];
    foreach ($membersData as $item) {
      if (!empty($item['master_customer_id']) && ($item['start_date'] <= $dateFrom) && ($item['end_date'] >= $dateTo)) {
        $masterCustomerIds[$item['member_id']] = $item['master_customer_id'];
        $memberIds[$item['master_customer_id']] = $item['member_id'];
      }
    }

    if (empty($masterCustomerIds)) {
      return;
    }

    $queue = $this->queueFactory->get('openy_campaign_updates_member_visits');

    $interval = \DateInterval::createFromDateString('1 day');
    $period = new \DatePeriod($dateFrom, $interval, $dateTo);

    /** @var \DateTime $from */
    foreach ($period as $from) {
      // Foreach by date - for every date in date interval create queue item.
      $to = clone $from;
      $to->setTime(23, 59, 59);
      $data = [
        'date_from' => $from,
        'date_to' => $to,
      ];

      $chunks = array_chunk($masterCustomerIds, 100);
      foreach ($chunks as $chunk) {
        $data['items'] = [];
        foreach ($chunk as $masterCustomerID) {
          $memberID = $memberIds[$masterCustomerID];
          $data['items'][$memberID] = $masterCustomerID;
        }
        // Add data to queue.
        $queue->createItem($data);
      }
    }
  }
public function createQueue ( \ DateTime $ dateFrom , \ DateTime $ dateTo , $ membersData = [ ] ) { // If Member doesn't specified - get all Member ID, Campaign start, Campaign end to receive visits from CRM. if ( empty ( $ membersData ) ) { $ membersData = $ this -> getAllMembersDataForQueue ( ) ; } // Collect all Master Customer Ids if yesterday date is in the range of Member dates. $ masterCustomerIds = [ ] ; $ memberIds = [ ] ; foreach ( $ membersData as $ item ) { if ( ! empty ( $ item [ 'master_customer_id' ] ) && ( $ item [ 'start_date' ] <= $ dateFrom ) && ( $ item [ 'end_date' ] >= $ dateTo ) ) { $ masterCustomerIds [ $ item [ 'member_id' ] ] = $ item [ 'master_customer_id' ] ; $ memberIds [ $ item [ 'master_customer_id' ] ] = $ item [ 'member_id' ] ; } } if ( empty ( $ masterCustomerIds ) ) { return ; } $ queue = $ this -> queueFactory -> get ( 'openy_campaign_updates_member_visits' ) ; $ interval = \ DateInterval :: createFromDateString ( '1 day' ) ; $ period = new \ DatePeriod ( $ dateFrom , $ interval , $ dateTo ) ; /** @var \DateTime $from */ foreach ( $ period as $ from ) { // Foreach by date - for every date in date interval create queue item. $ to = clone $ from ; $ to -> setTime ( 23 , 59 , 59 ) ; $ data = [ 'date_from' => $ from , 'date_to' => $ to , ] ; $ chunks = array_chunk ( $ masterCustomerIds , 100 ) ; foreach ( $ chunks as $ chunk ) { $ data [ 'items' ] = [ ] ; foreach ( $ chunk as $ masterCustomerID ) { $ memberID = $ memberIds [ $ masterCustomerID ] ; $ data [ 'items' ] [ $ memberID ] = $ masterCustomerID ; } // Add data to queue. $ queue -> createItem ( $ data ) ; } } }
Add specified or all Members to queue.

@param \DateTime $dateFrom
@param \DateTime $dateTo
@param array $membersData
Array of items with needed data: Member ID,
Master Customer ID, Start date, End date to get visits.
Add specified or all Members to queue .