/** * @param Channel $channel */ public function scheduleRecalculation(Channel $channel = null) { if ($channel) { $isActiveChannel = $channel->getStatus() === Channel::STATUS_ACTIVE; $channelData = $channel->getData(); $rfmEnabled = !empty($channelData[RFMAwareInterface::RFM_STATE_KEY]); if (!$isActiveChannel || !$rfmEnabled) { return; } } if ($this->getJob()) { return; } $args = []; if ($channel) { $argument = sprintf('--channel=%s', $channel->getId()); $channelJob = $this->getJob($argument); if ($channelJob) { return; } $args = [$argument]; } $job = new Job(CalculateAnalyticsCommand::COMMAND_NAME, $args); $em = $this->doctrineHelper->getEntityManager($job); if (!$channel) { $channelJobs = $this->getJob('--channel'); if ($channelJobs) { foreach ($channelJobs as $channelJob) { $em->remove($channelJob); } } } $em->persist($job); $em->flush($job); }
/** * @param ObjectManager $om */ protected function persistDemoRFM(ObjectManager $om) { $rfmData = ['recency' => [['min' => null, 'max' => 7], ['min' => 7, 'max' => 30], ['min' => 30, 'max' => 90], ['min' => 90, 'max' => 365], ['min' => 365, 'max' => null]], 'frequency' => [['min' => 52, 'max' => null], ['min' => 12, 'max' => 52], ['min' => 4, 'max' => 12], ['min' => 2, 'max' => 4], ['min' => null, 'max' => 2]], 'monetary' => [['min' => 10000, 'max' => null], ['min' => 1000, 'max' => 10000], ['min' => 100, 'max' => 1000], ['min' => 10, 'max' => 100], ['min' => null, 'max' => 10]]]; foreach ($rfmData as $type => $values) { foreach ($values as $idx => $limits) { $category = new RFMMetricCategory(); $category->setCategoryIndex($idx + 1)->setChannel($this->dataChannel)->setCategoryType($type)->setMinValue($limits['min'])->setMaxValue($limits['max'])->setOwner($this->organization); $om->persist($category); } } $data = $this->dataChannel->getData(); $data['rfm_enabled'] = true; $this->dataChannel->setData($data); $om->persist($this->dataChannel); }
/** * {@inheritdoc} */ public function build(Channel $channel, array $ids = []) { $data = $channel->getData(); if (empty($data[RFMAwareInterface::RFM_STATE_KEY]) || !filter_var($data[RFMAwareInterface::RFM_STATE_KEY], FILTER_VALIDATE_BOOLEAN)) { return; } $iterator = $this->getEntityIdsByChannel($channel, $ids); $values = []; $count = 0; foreach ($iterator as $value) { $values[] = $value; $count++; if ($count % self::BATCH_SIZE === 0) { $this->processBatch($channel, $values); $values = []; } } $this->processBatch($channel, $values); }