Skip to content

Commit

Permalink
Chat CSV by group field and date
Browse files Browse the repository at this point in the history
  • Loading branch information
remdex committed Oct 25, 2022
1 parent 2105017 commit c6f7153
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,8 @@ function drawChartPerMonth() {

<?php if (in_array('nickgroupingdatenick',is_array($input->chart_type) ? $input->chart_type : array())) : ?>
<hr>
<h5><?php include(erLhcoreClassDesign::designtpl('lhstatistic/tabs/titles/nickgroupingdatenick.tpl.php'));?></h5>
<h5>
<a class="csv-export" data-scope="cs_nickgroupingdatenick" title="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/statistic','Download CSV')?>"><i class="material-icons mr-0">file_download</i></a><?php include(erLhcoreClassDesign::designtpl('lhstatistic/tabs/titles/nickgroupingdatenick.tpl.php'));?></h5>
<canvas id="chart_nickgroupingdatenick"></canvas>
<?php endif; ?>

Expand Down
33 changes: 26 additions & 7 deletions lhc_web/lib/core/lhchat/lhchatstatistic.php
Original file line number Diff line number Diff line change
Expand Up @@ -3857,15 +3857,34 @@ public static function exportCSV($statistic, $type) {
(is_object($obUser) ? $obUser->name_official : $value['user_id'])
]);
}
} else if ($type == 'nickgroupingdatenick') {
$counter = 0;
foreach ($statistic['nickgroupingdatenick']['labels'] as $date => $value) {
if ($counter == 0) {
fputcsv($fp,array_merge(array('Date'),$value['nick']));
} else if ($type == 'cs_nickgroupingdatenick' || $type == 'nickgroupingdatenick') {

$groupField = 'nickgroupingdatenick';

$dates = ['Entity'];
foreach ($statistic[$groupField]['labels'] as $date => $value) {
$dates[] = date('Y-m-d H:i:s',$date);
}

fputcsv($fp, array_merge($dates,['Total']));
$agents = [];
foreach ($statistic[$groupField]['labels'] as $date => $value) {
$agents = array_unique(array_merge($agents,(isset($value['nick']) ? $value['nick'] : [])));
}

foreach ($agents as $agent) {
$agentRow = [];
foreach ($statistic[$groupField]['labels'] as $date => $value) {
$index = array_search($agent, (isset($value['nick']) ? $value['nick'] : []));
if ($index !== false) {
$agentRow[] = $value['data'][$index];
} else {
$agentRow[] = 0;
}
}
fputcsv($fp,array_merge(array(date('Y-m-d H:i:s',$date)),$value['data']));
$counter++;
fputcsv($fp,array_merge([(string)json_decode($agent)],$agentRow,[array_sum($agentRow)]));
}

} else if ($type == 'unanswered') {
fputcsv($fp, ['Date','Chats number']);
foreach ($statistic['numberOfChatsPerMonth'] as $date => $value) {
Expand Down

0 comments on commit c6f7153

Please sign in to comment.