Skip to content

Commit

Permalink
Addressed the review comment to get ids only.
Browse files Browse the repository at this point in the history
  • Loading branch information
shinde-rahul committed Jan 2, 2023
1 parent d13f971 commit ab20d36
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/bundles/LeadBundle/Controller/FrequencyRuleTrait.php
Expand Up @@ -134,7 +134,7 @@ protected function getFrequencyRuleFormData(Lead $lead, array $allChannels = nul

$data['global_categories'] = (isset($frequencyRules['global_categories']))
? $frequencyRules['global_categories']
: $model->getSubscribedAndNewCategories($lead, ['global', 'email']);
: $model->getSubscribedAndNewCategoryIds($lead, ['global', 'email']);

$this->leadLists = $model->getLists($lead, false, false, $isPublic, $isPreferenceCenter);
$data['lead_lists'] = [];
Expand Down
17 changes: 13 additions & 4 deletions app/bundles/LeadBundle/Entity/LeadCategoryRepository.php
Expand Up @@ -32,15 +32,15 @@ public function getLeadCategories(Lead $lead)
/**
* @param string[] $types
*
* @return array<int,array{'id': string, "title": string, "alias": string, "bundle": string}>
* @return array<int, int>
*/
public function getSubscribedAndNewCategories(Lead $lead, array $types): array
public function getSubscribedAndNewCategoryIds(Lead $lead, array $types): array
{
$qb = $this->_em->getConnection()->createQueryBuilder();

// Fetch the records from categories.
$parentQ = clone $qb;
$parentQ->select('c.id, c.title, c.alias, c.bundle');
$parentQ->select('c.id');
$parentQ->from(MAUTIC_TABLE_PREFIX.'categories', 'c');
$parentQ->where('c.is_published = 1');
$parentQ->andWhere($qb->expr()->in('c.bundle', ':bundles'));
Expand All @@ -60,7 +60,16 @@ public function getSubscribedAndNewCategories(Lead $lead, array $types): array
// Add sub-query parameter.
$parentQ->setParameter('leadId', $lead->getId(), Types::INTEGER);

return $parentQ->execute()
$leadCategories = $parentQ->execute()
->fetchAllAssociative();

$leadCategoryList = [];
foreach ($leadCategories as $category) {
$id = (int) $category['id'];

$leadCategoryList[$id] = $id;
}

return $leadCategoryList;
}
}
13 changes: 3 additions & 10 deletions app/bundles/LeadBundle/Model/LeadModel.php
Expand Up @@ -1266,18 +1266,11 @@ public function getLeadCategories(Lead $lead)
/**
* @param string[] $types
*
* @return array<string,string>
* @return array<int, int>
*/
public function getSubscribedAndNewCategories(Lead $lead, array $types): array
public function getSubscribedAndNewCategoryIds(Lead $lead, array $types): array
{
$leadCategories = $this->getLeadCategoryRepository()->getSubscribedAndNewCategories($lead, $types);

$leadCategoryList = [];
foreach ($leadCategories as $category) {
$leadCategoryList[$category['id']] = $category['id'];
}

return $leadCategoryList;
return $this->getLeadCategoryRepository()->getSubscribedAndNewCategoryIds($lead, $types);
}

/**
Expand Down

0 comments on commit ab20d36

Please sign in to comment.