Skip to content

Commit

Permalink
Merge branch '65367-fix-stats-group-multilingual' into 'master'
Browse files Browse the repository at this point in the history
ref #65367: make stats group selection multilingual

See merge request chameleon-system-oss/chameleon-shop!56
  • Loading branch information
pixeljunkie committed Jan 3, 2025
2 parents 3a7492e + 9f698ac commit 3bf3a98
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function Accept(\IMapperVisitorRestricted $oVisitor, $bCachingEnabled, \I
$showChange = '1' === $this->GetUserInput('showChange', '0');
$viewName = $this->GetUserInput('viewName', null);
$currencyId = $this->GetUserInput('currency', $this->statsCurrencyService->getCurrencyIdByIsoCode(self::STANDARD_CURRENCY_ISO_CODE));
$selectedStatsGroup = $this->GetUserInput('statsGroup', self::ALL_STATS_FILTER_NAME);
$selectedStatsGroupId = $this->GetUserInput('statsGroup', self::ALL_STATS_FILTER_NAME);

/** @var string $portalId */
$portalId = $this->GetUserInput('portalId', '');
Expand All @@ -80,7 +80,7 @@ public function Accept(\IMapperVisitorRestricted $oVisitor, $bCachingEnabled, \I
$showChange,
$portalId,
$currencyId,
$selectedStatsGroup
$selectedStatsGroupId
);
$oVisitor->SetMappedValue('tableData', $tableData);
}
Expand All @@ -101,7 +101,7 @@ public function Accept(\IMapperVisitorRestricted $oVisitor, $bCachingEnabled, \I
$oVisitor->SetMappedValue('selectedPortalId', $portalId);
$oVisitor->SetMappedValue('currencyList', $currencyList);
$oVisitor->SetMappedValue('currencyId', $currencyId);
$oVisitor->SetMappedValue('selectedStatsGroup', $selectedStatsGroup);
$oVisitor->SetMappedValue('selectedStatsGroupId', $selectedStatsGroupId);
$oVisitor->SetMappedValue('statsGroupsSelection', $this->statsProviderCollection->fetchAllStatisticGroupsNames());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function getFilters(): array
'chameleon_system_ecommerce_stats_format_number',
[$this, 'formatNumber'],
['is_safe' => ['html']]
)
),
];
}

Expand Down Expand Up @@ -101,12 +101,13 @@ public function generateColor(int $index, int $total): string
$g = (1 - $factor) * $startColor[1] + $factor * $endColor[1];
$b = (1 - $factor) * $startColor[2] + $factor * $endColor[2];

return sprintf('#%02x%02x%02x', (int)$r, (int)$g, (int)$b);
return sprintf('#%02x%02x%02x', (int) $r, (int) $g, (int) $b);
}

private function hexToRgb(string $hex): array
{
$hex = ltrim($hex, '#');

return [
hexdec(substr($hex, 0, 2)),
hexdec(substr($hex, 2, 2)),
Expand Down
6 changes: 4 additions & 2 deletions src/EcommerceStatsBundle/Controllers/CsvExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace ChameleonSystem\EcommerceStatsBundle\Controllers;

use ChameleonSystem\EcommerceStatsBundle\Bridge\Chameleon\BackendModule\EcommerceStatsBackendModule;
use ChameleonSystem\EcommerceStatsBundle\Library\DataModel\CsvResponse;
use ChameleonSystem\EcommerceStatsBundle\Library\Interfaces\CsvExportServiceInterface;
use ChameleonSystem\EcommerceStatsBundle\Library\Interfaces\StatsProviderInterface;
use ChameleonSystem\EcommerceStatsBundle\Library\Interfaces\StatsTableServiceInterface;
Expand All @@ -23,7 +25,6 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use ChameleonSystem\EcommerceStatsBundle\Library\DataModel\CsvResponse;

class CsvExportController
{
Expand Down Expand Up @@ -51,10 +52,11 @@ public function exportStatistics(Request $request): Response
$dateGroupType = $request->get('dateGroupType', StatsProviderInterface::DATA_GROUP_TYPE_DAY);
$showChange = $request->request->getBoolean('showChange');
$selectedPortalId = $request->get('portalId', '');
$selectedStatsGroupId = EcommerceStatsBackendModule::ALL_STATS_FILTER_NAME;
$startDate = $this->getRequiredDate($request, 'startDate')->setTime(0, 0, 0);
$endDate = $this->getRequiredDate($request, 'endDate')->setTime(23, 59, 59);

$statsTable = $this->statsTableService->evaluate($startDate, $endDate, $dateGroupType, $showChange, $selectedPortalId);
$statsTable = $this->statsTableService->evaluate($startDate, $endDate, $dateGroupType, $showChange, $selectedPortalId, $selectedStatsGroupId);
$csvData = $this->csvExportService->getCsvDataFromStatsTable($statsTable);
$fileName = $this->getCsvFilename('stats', $startDate, $endDate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ interface StatsCurrencyServiceInterface
public function getAllCurrencies();

public function getCurrencyById(string $currencyId): ?StatsCurrencyDataModel;

public function getCurrencyIdByIsoCode(string $isoCode): ?string;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public function addStatsToTable(
string $dateGroupType,
string $portalId,
string $currencyId,
string $selectedStatsGroup
string $selectedStatsGroupId
): StatsTableDataModel;

/**
* @return String[]
* @return string[]
*/
public function fetchAllStatisticGroupsNames(): array;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public function evaluate(
bool $showDiffColumn,
string $portalId = '',
string $currencyId = '',
string $selectedStatsGroup = ''
string $selectedStatsGroupId = ''
): StatsTableDataModel;
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@
{{ 'chameleon_system_ecommerce_stats.form_stats_group'|trans }}:
</label>
<select class="form-control" name="{{ moduleSpotName }}[statsGroup]" data-param="statsGroup">
<option value="allStats" {% if selectedStatsGroup == 'allStats' %} selected="selected" {% endif %}>{{ 'chameleon_system_ecommerce_stats.form_all_stats_label'|trans }}</option>
{% for group in statsGroupsSelection %}
<option value="{{ group.name }}" {% if group.name == selectedStatsGroup %} selected="selected"{% endif %}>{{ group.name }}</option>
<option value="allStats" {% if selectedStatsGroupId == 'allStats' %} selected="selected" {% endif %}>{{ 'chameleon_system_ecommerce_stats.form_all_stats_label'|trans }}</option>
{% for groupId, groupName in statsGroupsSelection %}
<option value="{{ groupId }}" {% if groupId == selectedStatsGroupId %} selected="selected"{% endif %}>{{ groupName }}</option>
{% endfor %}
</select>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/EcommerceStatsBundle/Service/StatsTableService.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public function evaluate(
bool $showDiffColumn,
string $portalId = '',
string $currencyId = '',
string $selectedStatsGroup = ''): StatsTableDataModel
string $selectedStatsGroupId = ''): StatsTableDataModel
{
$statsTable = new StatsTableDataModel();
$statsTable->setShowDiffColumn($showDiffColumn);

foreach ($this->statsProviders as $provider) {
$statsTable = $provider->addStatsToTable($statsTable, $startDate, $endDate, $dateGroupType, $portalId, $currencyId, $selectedStatsGroup);
$statsTable = $provider->addStatsToTable($statsTable, $startDate, $endDate, $dateGroupType, $portalId, $currencyId, $selectedStatsGroupId);
}

$blocks = $statsTable->getBlocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public function addStatsToTable(
string $dateGroupType,
string $portalId,
string $currencyId,
string $selectedStatsGroup
string $selectedStatsGroupId
): StatsTableDataModel {
foreach ($this->fetchStatistics($selectedStatsGroup) as $group) {
foreach ($this->fetchStatistics($selectedStatsGroupId) as $group) {
[$conditionList, $params] = $this->getBaseConditions($group, $startDate, $endDate, $portalId);
$dateQueryPart = $this->getDateQueryPart($dateGroupType, $group->fieldDateRestrictionField ?? 'datecreated');

Expand All @@ -82,20 +82,24 @@ public function addStatsToTable(

public function fetchAllStatisticGroupsNames(): array
{
$query = "SELECT `name` FROM `pkg_shop_statistic_group`";
$groupNames = [];
$groupList = \TdbPkgShopStatisticGroupList::GetList();
while ($group = $groupList->Next()) {
$groupNames[$group->id] = $group->fieldName;
}

return $this->connection->fetchAllAssociative($query);
return $groupNames;
}

/**
* @return \Generator<\TdbPkgShopStatisticGroup>
*/
private function fetchStatistics(string $selectedStatsGroup): \Generator
private function fetchStatistics(string $selectedStatsGroupId): \Generator
{
if (EcommerceStatsBackendModule::ALL_STATS_FILTER_NAME === $selectedStatsGroup || '' === $selectedStatsGroup) {
if (EcommerceStatsBackendModule::ALL_STATS_FILTER_NAME === $selectedStatsGroupId || '' === $selectedStatsGroupId) {
$groups = \TdbPkgShopStatisticGroupList::GetList();
} else {
$query = 'SELECT * FROM `pkg_shop_statistic_group` WHERE `pkg_shop_statistic_group`.`name` = '."'$selectedStatsGroup'";
$query = 'SELECT * FROM `pkg_shop_statistic_group` WHERE `pkg_shop_statistic_group`.`id` = '."'$selectedStatsGroupId'";

$groups = \TdbPkgShopStatisticGroupList::GetList($query);
}
Expand Down

0 comments on commit 3bf3a98

Please sign in to comment.