Skip to content

Commit

Permalink
Allow filter by chat duration and chat wait time
Browse files Browse the repository at this point in the history
  • Loading branch information
remdex committed Nov 16, 2017
1 parent 1c6b329 commit 230e269
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 31 deletions.
99 changes: 92 additions & 7 deletions lhc_web/design/defaulttheme/tpl/lhchat/lists/search_panel.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</div>
</div>

<div class="col-md-3">
<div class="col-md-2">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Date range from');?></label>
<div class="row">
Expand Down Expand Up @@ -78,7 +78,7 @@
</div>
</div>

<div class="col-md-3">
<div class="col-md-2">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Date range to');?></label>
<div class="row">
Expand Down Expand Up @@ -111,13 +111,65 @@
</div>
</div>
</div>
</div>

</div>

<div class="col-md-2">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Wait time');?></label>
<div class="row">
<div class="col-xs-6">
<select class="form-control" name="wait_time_from">
<option>More than</option>
<option value="0" <?php $input->wait_time_from === 0 ? print 'selected="selected"' : ''?>>0 seconds</option>
<option value="5" <?php $input->wait_time_from === 5 ? print 'selected="selected"' : ''?>>5 seconds</option>
<option value="10" <?php $input->wait_time_from === 10 ? print 'selected="selected"' : ''?>>10 seconds</option>
<option value="20" <?php $input->wait_time_from === 20 ? print 'selected="selected"' : ''?>>20 seconds</option>
<option value="30" <?php $input->wait_time_from === 30 ? print 'selected="selected"' : ''?>>30 seconds</option>
<option value="40" <?php $input->wait_time_from === 40 ? print 'selected="selected"' : ''?>>40 seconds</option>
<option value="50" <?php $input->wait_time_from === 50 ? print 'selected="selected"' : ''?>>50 seconds</option>
<option value="60" <?php $input->wait_time_from === 60 ? print 'selected="selected"' : ''?>>60 seconds</option>
<option value="90" <?php $input->wait_time_from === 90 ? print 'selected="selected"' : ''?>>90 seconds</option>

<?php for ($i = 2; $i < 5; $i++) : ?>
<option value="<?php echo $i*60?>" <?php $input->wait_time_from === $i*60 ? print 'selected="selected"' : ''?>><?php echo $i?> m.</option>
<?php endfor ?>

<?php for ($i = 2; $i < 13; $i++) : ?>
<option value="<?php echo $i*5*60?>" <?php $i*60*5 === $input->wait_time_from ? print 'selected="selected"' : ''?>><?php echo $i*5?> m.</option>
<?php endfor ?>
</select>
</div>
<div class="col-xs-6">
<select class="form-control" name="wait_time_till">
<option>Less than</option>
<option value="0" <?php $input->wait_time_till === 0 ? print 'selected="selected"' : ''?>>0 seconds</option>
<option value="5" <?php $input->wait_time_till === 5 ? print 'selected="selected"' : ''?>>5 seconds</option>
<option value="10" <?php $input->wait_time_till === 10 ? print 'selected="selected"' : ''?>>10 seconds</option>
<option value="20" <?php $input->wait_time_till === 20 ? print 'selected="selected"' : ''?>>20 seconds</option>
<option value="30" <?php $input->wait_time_till === 30 ? print 'selected="selected"' : ''?>>30 seconds</option>
<option value="40" <?php $input->wait_time_till === 40 ? print 'selected="selected"' : ''?>>40 seconds</option>
<option value="50" <?php $input->wait_time_till === 50 ? print 'selected="selected"' : ''?>>50 seconds</option>
<option value="60" <?php $input->wait_time_till === 60 ? print 'selected="selected"' : ''?>>60 seconds</option>
<option value="90" <?php $input->wait_time_till === 90 ? print 'selected="selected"' : ''?>>90 seconds</option>

<?php for ($i = 2; $i < 5; $i++) : ?>
<option value="<?php echo $i*60?>" <?php $input->wait_time_till === $i*60 ? print 'selected="selected"' : ''?>><?php echo $i?> m.</option>
<?php endfor ?>

<?php for ($i = 2; $i < 13; $i++) : ?>
<option value="<?php echo $i*60*5?>" <?php $i*60*5 === $input->wait_time_till ? print 'selected="selected"' : ''?> ><?php echo $i*5?> m.</option>
<?php endfor ?>
</select>
</div>
</div>
</div>
</div>


</div>

<div class="row">
<div class="col-md-3">
<div class="col-md-2">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Vote status');?></label>
<select name="fbst" class="form-control">
Expand All @@ -128,7 +180,7 @@
</select>
</div>
</div>
<div class="col-md-3">
<div class="col-md-2">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Chat status');?></label>
<select name="chat_status" class="form-control">
Expand All @@ -151,12 +203,45 @@
'list_function' => 'erLhAbstractModelProduct::getList'
)); ?>
</div>
<div class="col-md-3">
<div class="col-md-2">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Chat ID');?></label>
<input type="text" class="form-control" name="chat_id" value="<?php echo htmlspecialchars($input->chat_id)?>" />
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Chat duration');?></label>
<div class="row">
<div class="col-xs-6">
<select class="form-control" name="chat_duration_from" title="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Chat duration from');?>">
<option value=""><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','From');?></option>
<?php for ($i = 1; $i < 10; $i++) : ?>
<option value="<?php echo $i*60?>" <?php $i*60 === $input->chat_duration_from ? print 'selected="selected"' : ''?> ><?php echo $i?> m.</option>
<?php endfor; ?>

<?php for ($i = 2; $i < 19; $i++) : ?>
<option value="<?php echo $i*60*5?>" <?php $i*60*5 === $input->chat_duration_from ? print 'selected="selected"' : ''?> ><?php echo $i*5?> m.</option>
<?php endfor; ?>
</select>
</div>
<div class="col-xs-6">
<select class="form-control" name="chat_duration_till" title="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Chat duration till');?>">
<option value=""><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Till');?></option>
<?php for ($i = 1; $i < 10; $i++) : ?>
<option value="<?php echo $i*60?>" <?php $i*60 === $input->chat_duration_till ? print 'selected="selected"' : ''?> ><?php echo $i?> m.</option>
<?php endfor; ?>

<?php for ($i = 2; $i < 19; $i++) : ?>
<option value="<?php echo $i*60*5?>" <?php $i*60*5 === $input->chat_duration_till ? print 'selected="selected"' : ''?> ><?php echo $i*5?> m.</option>
<?php endfor; ?>
</select>
</div>
</div>
</div>
</div>


</div>

<div class="row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,21 @@
</div>
</div>

<div class="col-md-4">
<div class="col-md-3">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','User');?></label>
<?php echo erLhcoreClassRenderHelper::renderCombobox( array (
'input_name' => 'user_id',
'optional_field' => erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Select user'),
'selected_id' => $input->user_id,
'css_class' => 'form-control',
'display_name' => 'name_official',
'list_function' => 'erLhcoreClassModelUser::getUserList'
)); ?>
</div>
</div>

<div class="col-md-3">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','User group');?></label>
<?php echo erLhcoreClassRenderHelper::renderCombobox( array (
Expand All @@ -106,10 +120,10 @@
'display_name' => 'name',
'list_function' => 'erLhcoreClassModelGroup::getList'
)); ?>
</div>
</div>
</div>

<div class="col-md-4">
<div class="col-md-3">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Department');?></label>
<?php echo erLhcoreClassRenderHelper::renderCombobox( array (
Expand All @@ -122,7 +136,7 @@
</div>
</div>

<div class="col-md-4">
<div class="col-md-3">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Department group');?></label>
<?php echo erLhcoreClassRenderHelper::renderCombobox( array (
Expand Down Expand Up @@ -177,7 +191,7 @@
<table class="table" cellpadding="0" cellspacing="0" width="100%">
<thead>
<tr>
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/statistic','Avg. Wait Time');?></th>
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/statistic','Avg. Wait Time');?></a></th>
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/statistic','Chats Started');?></th>
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/statistic','Abandoned Chats');?></th>
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/statistic','% of chats');?></th>
Expand All @@ -187,7 +201,7 @@
<tbody>
<?php foreach ($performanceStatistic['rows'] as $stat) : ?>
<tr>
<td><?php echo htmlspecialchars($stat['tt'])?></td>
<td><a href="<?php echo erLhcoreClassDesign::baseurl('chat/list')?>/(wait_time_from)/<?php echo $stat['from']-1?><?php $stat['to'] !== false ? print '/(wait_time_till)/' . $stat['to'] : ''?>/<?php echo erLhcoreClassSearchHandler::getURLAppendFromInput($input)?>"><?php echo htmlspecialchars($stat['tt'])?></a></td>
<td><?php echo $stat['started']?></td>
<td><?php echo $stat['abandoned']?></td>
<td><?php echo $performanceStatistic['total_chats'] > 0 ? round($stat['started']/$performanceStatistic['total_chats'],4)*100 : 0?> %</td>
Expand Down
19 changes: 11 additions & 8 deletions lhc_web/lib/core/lhchat/lhchatstatistic.php
Original file line number Diff line number Diff line change
Expand Up @@ -1113,11 +1113,10 @@ public static function totalHoursOfChatsDialogsByUser($days = 30, $filter = arra
$filter['filtergt']['user_id'] = 0;
return erLhcoreClassChat::getCount(array_merge_recursive($filter,array('filtergt' => array('chat_duration' => 0),'filter' => array('status' => erLhcoreClassModelChat::STATUS_CLOSED_CHAT))),'lh_chat','SUM(chat_duration)');
}

public static function getPerformanceStatistic($days = 30, $filter = array(), $filterParams = array())
{
// wait_time
$dateRange = array(

public static function getRangeWaitTime()
{
return array(
array(
'from' => 0,
'to' => 5,
Expand Down Expand Up @@ -1189,6 +1188,11 @@ public static function getPerformanceStatistic($days = 30, $filter = array(), $f
'tt' => erTranslationClassLhTranslation::getInstance()->getTranslation('chat/statistic','more than 10 min.')
)
);
}

public static function getPerformanceStatistic($days = 30, $filter = array(), $filterParams = array())
{
$dateRange = self::getRangeWaitTime();

$statusWorkflow = erLhcoreClassChatEventDispatcher::getInstance()->dispatch('statistic.getperformancestatistic',array('ranges' => $dateRange, 'days' => $days, 'filter' => $filter, 'filter_params' => $filterParams));

Expand Down Expand Up @@ -1225,9 +1229,8 @@ public static function getPerformanceStatistic($days = 30, $filter = array(), $f
} elseif (isset($filterParams['input']->timefrom_include_hours) && is_numeric($filterParams['input']->timefrom_include_hours)) {
$filterTimeout['customfilter'][] = 'FROM_UNIXTIME(time,\'%k\') >= '. (int)$filterParams['input']->timefrom_include_hours;
}


$chatStarted = erLhcoreClassChat::getCount(array_merge_recursive($filter, $filterTimeout), 'lh_chat', 'count(id)');

$chatStarted = erLhcoreClassChat::getCount(array_merge_recursive($filter, $filterTimeout), 'lh_chat', 'count(id)');
$abandonedStarted = erLhcoreClassChat::getCount(array_merge_recursive($filter, $filterTimeout, array('filter' => array('user_id' => 0, 'status_sub' => erLhcoreClassModelChat::STATUS_SUB_USER_CLOSED_CHAT))), 'lh_chat', 'count(id)');

$stats['rows'][] = array(
Expand Down
48 changes: 48 additions & 0 deletions lhc_web/lib/core/lhchat/searchattr/chat_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,54 @@
)
);

$fieldsSearch['wait_time_from'] = array (
'type' => 'text',
'trans' => 'id',
'required' => false,
'valid_if_filled' => false,
'filter_type' => 'filtergt',
'filter_table_field' => 'wait_time',
'validation_definition' => new ezcInputFormDefinitionElement (
ezcInputFormDefinitionElement::OPTIONAL, 'int'
)
);

$fieldsSearch['wait_time_till'] = array (
'type' => 'text',
'trans' => 'id',
'required' => false,
'valid_if_filled' => false,
'filter_type' => 'filterlte',
'filter_table_field' => 'wait_time',
'validation_definition' => new ezcInputFormDefinitionElement (
ezcInputFormDefinitionElement::OPTIONAL, 'int'
)
);

$fieldsSearch['chat_duration_from'] = array (
'type' => 'text',
'trans' => 'id',
'required' => false,
'valid_if_filled' => false,
'filter_type' => 'filtergt',
'filter_table_field' => 'chat_duration',
'validation_definition' => new ezcInputFormDefinitionElement (
ezcInputFormDefinitionElement::OPTIONAL, 'int'
)
);

$fieldsSearch['chat_duration_till'] = array (
'type' => 'text',
'trans' => 'id',
'required' => false,
'valid_if_filled' => false,
'filter_type' => 'filterlte',
'filter_table_field' => 'chat_duration',
'validation_definition' => new ezcInputFormDefinitionElement (
ezcInputFormDefinitionElement::OPTIONAL, 'int'
)
);

$fieldsSearch['timefrom'] = array (
'type' => 'text',
'trans' => 'Timefrom',
Expand Down
4 changes: 1 addition & 3 deletions lhc_web/lib/core/lhchat/searchattr/performance_statistic.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,12 @@
'required' => false,
'valid_if_filled' => false,
'filter_type' => 'filter',
'filter_table_field' => 'user_id',
'filter_table_field' => 'lh_chat.user_id',
'validation_definition' => new ezcInputFormDefinitionElement(
ezcInputFormDefinitionElement::OPTIONAL, 'int', array( 'min_range' => 1)
)
);



$fieldSortAttr = array (
'field' => false,
'default' => false,
Expand Down
15 changes: 9 additions & 6 deletions lhc_web/lib/core/lhcore/lhsearchhandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,22 @@ public static function getParams($params = array())
}
}
}
} elseif ($field['filter_type'] == 'filtergte') {

} elseif ($field['filter_type'] == 'filtergte' || $field['filter_type'] == 'filtergt') {

$filterType = $field['filter_type'];

if (isset($field['datatype']) && $field['datatype'] == 'date') {

$dateFormated = self::formatDateToTimestamp($inputParams->$key);
if ($dateFormated != false) {
$filter['filtergte'][$field['filter_table_field']] = $dateFormated;
$filter[$filterType][$field['filter_table_field']] = $dateFormated;
}
} elseif (isset($field['datatype']) && $field['datatype'] == 'date_ymd') {

$dateFormated = self::formatDateToDateYmd($inputParams->$key);

if ($dateFormated != false) {
$filter['filtergte'][$field['filter_table_field']] = $dateFormated;
$filter[$filterType][$field['filter_table_field']] = $dateFormated;
}
} elseif (isset($field['datatype']) && $field['datatype'] == 'datetime') {

Expand Down Expand Up @@ -162,12 +164,13 @@ public static function getParams($params = array())
$minutes = 0;
}

$filter['filtergte'][$field['filter_table_field']] = $dateFormated + $hours + $minutes;
$filter[$filterType][$field['filter_table_field']] = $dateFormated + $hours + $minutes;
}

} else {
$filter['filtergte'][$field['filter_table_field']] = $inputParams->$key;
$filter[$filterType][$field['filter_table_field']] = $inputParams->$key;
}

} elseif ($field['filter_type'] == 'filterlte' || $field['filter_type'] == 'filterlt') {

$filterType = $field['filter_type'];
Expand Down
2 changes: 1 addition & 1 deletion lhc_web/modules/lhchat/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@

$ViewList['list'] = array(
'params' => array(),
'uparams' => array('chat_id','nick','email','timefrom','timeto','department_id','user_id','print','xls','fbst','chat_status','hum','product_id','timefrom','timefrom_minutes','timefrom_hours','timeto','timeto_minutes','timeto_hours'),
'uparams' => array('chat_duration_from','chat_duration_till','wait_time_from','wait_time_till','chat_id','nick','email','timefrom','timeto','department_id','user_id','print','xls','fbst','chat_status','hum','product_id','timefrom','timefrom_minutes','timefrom_hours','timeto','timeto_minutes','timeto_hours'),
'functions' => array( 'use' )
);

Expand Down

0 comments on commit 230e269

Please sign in to comment.