Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
remdex committed Feb 1, 2023
1 parent 1bc7b00 commit ce2b689
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 13 deletions.
24 changes: 24 additions & 0 deletions classes/filter/mail_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@

$fieldsSearch = array();

$fieldsSearch['status_conv_id'] = array (
'type' => 'text',
'trans' => 'Conversation status',
'required' => false,
'valid_if_filled' => false,
'filter_type' => 'filterin',
'filter_table_field' => 'status_conv',
'validation_definition' => new ezcInputFormDefinitionElement (
ezcInputFormDefinitionElement::OPTIONAL, 'int', array( 'min_range' => 0), FILTER_REQUIRE_ARRAY
)
);

$fieldsSearch['status_msg_id'] = array (
'type' => 'text',
'trans' => 'Message status',
'required' => false,
'valid_if_filled' => false,
'filter_type' => 'filterin',
'filter_table_field' => 'status',
'validation_definition' => new ezcInputFormDefinitionElement (
ezcInputFormDefinitionElement::OPTIONAL, 'int', array( 'min_range' => 0), FILTER_REQUIRE_ARRAY
)
);

$fieldsSearch['conversation_id'] = array (
'type' => 'text',
'trans' => 'Sort by',
Expand Down
124 changes: 124 additions & 0 deletions classes/lhelasticsearchview.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ public static function updateView($params) {
$dateFilter['gte'] = time() - $params['search']->days * 24 * 3600;
}

if (isset($params['search']->params_array['sparams']['body']['query']['bool']['must'])) {
$mustPresent = $params['search']->params_array['sparams']['body']['query']['bool']['must'];
foreach ($mustPresent as $indexMust => $mustItem) {
if (isset($mustItem['terms']['dep_id']) || isset($mustItem['terms']['user_id'])) {
unset($mustPresent[$indexMust]);
}
}
self::applyDynamicFilter($mustPresent, (object)$params['search']->params_array['input_form'], ['user_attr' => 'user_id']);
}

if (isset($mustPresent) && !empty($mustPresent)) {
$params['search']->params_array['sparams']['body']['query']['bool']['must'] = array_values($mustPresent);
}

$totalRecords = erLhcoreClassModelESChat::getCount($params['search']->params_array['sparams'], array('date_index' => $dateFilter));

$params['search']->updated_at = time();
Expand All @@ -58,6 +72,21 @@ public static function updateView($params) {
$dateFilter['gte'] = time() - $params['search']->days * 24 * 3600;
}

if (isset($params['search']->params_array['sparams']['body']['query']['bool']['must'])) {
$mustPresent = $params['search']->params_array['sparams']['body']['query']['bool']['must'];
foreach ($mustPresent as $indexMust => $mustItem) {
if (isset($mustItem['terms']['dep_id']) || isset($mustItem['terms']['conv_user_id'])) {
unset($mustPresent[$indexMust]);
}
}

self::applyDynamicFilter($mustPresent, (object)$params['search']->params_array['input_form'], ['user_attr' => 'conv_user_id']);
}

if (isset($mustPresent) && !empty($mustPresent)) {
$params['search']->params_array['sparams']['body']['query']['bool']['must'] = array_values($mustPresent);
}

$totalRecords = erLhcoreClassModelESMail::getCount($params['search']->params_array['sparams'], array('date_index' => $dateFilter));

$params['search']->updated_at = time();
Expand All @@ -72,6 +101,72 @@ public static function updateView($params) {

}

public static function applyDynamicFilter( & $termsFilter, $input, $attrOptions)
{
// User ids, group, group ids
if (isset($input->group_ids) && is_array($input->group_ids) && !empty($input->group_ids)) {

erLhcoreClassChat::validateFilterIn($input->group_ids);

$db = ezcDbInstance::get();
$stmt = $db->prepare('SELECT user_id FROM lh_groupuser WHERE group_id IN (' . implode(',',$input->group_ids) .')');
$stmt->execute();
$userIds = $stmt->fetchAll(PDO::FETCH_COLUMN);

if (!empty($userIds)) {
$termsFilter[]['terms'][$attrOptions['user_attr']] = $userIds;
}
}

if (isset($input->user_ids) && is_array($input->user_ids) && !empty($input->user_ids)) {
erLhcoreClassChat::validateFilterIn($input->user_ids);
$termsFilter[]['terms'][$attrOptions['user_attr']] = $input->user_ids;
}

if (isset($input->group_id) && is_numeric($input->group_id) && $input->group_id > 0 ) {
$db = ezcDbInstance::get();
$stmt = $db->prepare('SELECT user_id FROM lh_groupuser WHERE group_id = :group_id');
$stmt->bindValue( ':group_id', $input->group_id, PDO::PARAM_INT);
$stmt->execute();
$userIds = $stmt->fetchAll(PDO::FETCH_COLUMN);

if (!empty($userIds)) {
$termsFilter[]['terms'][$attrOptions['user_attr']] = $userIds;
}
}

if (trim((string)$input->department_group_id) != '') {
$db = ezcDbInstance::get();
$stmt = $db->prepare('SELECT dep_id FROM lh_departament_group_member WHERE dep_group_id = :group_id');
$stmt->bindValue( ':group_id', $input->department_group_id, PDO::PARAM_INT);
$stmt->execute();
$depIds = $stmt->fetchAll(PDO::FETCH_COLUMN);

if (!empty($depIds)) {
$termsFilter[]['terms']['dep_id'] = $depIds;
}
}

if (isset($input->department_group_ids) && is_array($input->department_group_ids) && !empty($input->department_group_ids)) {

erLhcoreClassChat::validateFilterIn($input->department_group_ids);

$db = ezcDbInstance::get();
$stmt = $db->prepare('SELECT dep_id FROM lh_departament_group_member WHERE dep_group_id IN (' . implode(',',$input->department_group_ids) . ')');
$stmt->execute();
$depIds = $stmt->fetchAll(PDO::FETCH_COLUMN);

if (!empty($depIds)) {
$termsFilter[]['terms']['dep_id'] = $depIds;
}
}

if (isset($input->department_ids) && is_array($input->department_ids) && !empty($input->department_ids)) {
erLhcoreClassChat::validateFilterIn($input->department_ids);
$termsFilter[]['terms']['dep_id'] = $input->department_ids;
}
}

// Load view handler
public static function loadView($params)
{
Expand All @@ -87,6 +182,20 @@ public static function loadView($params)
$dateFilter['gte'] = time() - $search->days * 24 * 3600;
}

if (isset($search->params_array['sparams']['body']['query']['bool']['must'])) {
$mustPresent = $search->params_array['sparams']['body']['query']['bool']['must'];
foreach ($mustPresent as $indexMust => $mustItem) {
if (isset($mustItem['terms']['dep_id']) || isset($mustItem['terms']['user_id'])) {
unset($mustPresent[$indexMust]);
}
}
self::applyDynamicFilter($mustPresent, (object)$search->params_array['input_form'], ['user_attr' => 'user_id']);
}

if (isset($mustPresent) && !empty($mustPresent)) {
$search->params_array['sparams']['body']['query']['bool']['must'] = array_values($mustPresent);
}

$total = erLhcoreClassModelESChat::getCount($search->params_array['sparams'], array('date_index' => $dateFilter));

$pages = new lhPaginator();
Expand Down Expand Up @@ -150,6 +259,21 @@ public static function loadView($params)
$dateFilter['gte'] = time() - $search->days * 24 * 3600;
}

if (isset($search->params_array['sparams']['body']['query']['bool']['must'])) {
$mustPresent = $search->params_array['sparams']['body']['query']['bool']['must'];
foreach ($mustPresent as $indexMust => $mustItem) {
if (isset($mustItem['terms']['dep_id']) || isset($mustItem['terms']['conv_user_id'])) {
unset($mustPresent[$indexMust]);
}
}

self::applyDynamicFilter($mustPresent, (object)$search->params_array['input_form'], ['user_attr' => 'conv_user_id']);
}

if (isset($mustPresent) && !empty($mustPresent)) {
$search->params_array['sparams']['body']['query']['bool']['must'] = array_values($mustPresent);
}

$total = erLhcoreClassModelESMail::getCount($search->params_array['sparams'], array('date_index' => $dateFilter));

$pages = new lhPaginator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,24 +256,68 @@
<div class="col-md-2">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('bracket/lists/filter','Conversation status');?></label>
<select name="status_conv" class="form-control form-control-sm">
<option value="">Select</option>
<option value="0" <?php ($input->status_conv === erLhcoreClassModelMailconvConversation::STATUS_PENDING) ? print 'selected="selected"' : null?> >New</option>
<option value="1" <?php ($input->status_conv === erLhcoreClassModelMailconvConversation::STATUS_ACTIVE) ? print 'selected="selected"' : null?> >Active</option>
<option value="2" <?php ($input->status_conv === erLhcoreClassModelMailconvConversation::STATUS_CLOSED) ? print 'selected="selected"' : null?> >Closed</option>
</select>
<?php echo erLhcoreClassRenderHelper::renderMultiDropdown( array (
'input_name' => 'status_conv_id[]',
'optional_field' => erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Choose status'),
'selected_id' => $input->status_conv_id,
'css_class' => 'form-control',
'display_name' => 'name',
'list_function_params' => array(),
'list_function' => function () {
$items = array();

$item = new StdClass();
$item->name = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','New mails');
$item->id = erLhcoreClassModelMailconvConversation::STATUS_PENDING;
$items[] = $item;

$item = new StdClass();
$item->name = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Active mails');
$item->id = erLhcoreClassModelMailconvConversation::STATUS_ACTIVE;
$items[] = $item;

$item = new StdClass();
$item->name = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Closed mails');
$item->id = erLhcoreClassModelMailconvConversation::STATUS_CLOSED;
$items[] = $item;

return $items;
}
)); ?>
</div>
</div>

<div class="col-md-2">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('bracket/lists/filter','Message status');?></label>
<select name="status" class="form-control form-control-sm">
<option value="">Select</option>
<option value="0" <?php ($input->status === erLhcoreClassModelMailconvMessage::STATUS_PENDING) ? print 'selected="selected"' : null?> >New</option>
<option value="1" <?php ($input->status === erLhcoreClassModelMailconvMessage::STATUS_ACTIVE) ? print 'selected="selected"' : null?> >Active</option>
<option value="2" <?php ($input->status === erLhcoreClassModelMailconvMessage::STATUS_RESPONDED) ? print 'selected="selected"' : null?> >Responded</option>
</select>
<?php echo erLhcoreClassRenderHelper::renderMultiDropdown( array (
'input_name' => 'status_msg_id[]',
'optional_field' => erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Choose status'),
'selected_id' => $input->status_msg_id,
'css_class' => 'form-control',
'display_name' => 'name',
'list_function_params' => array(),
'list_function' => function () {
$items = array();

$item = new StdClass();
$item->name = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','New');
$item->id = erLhcoreClassModelMailconvMessage::STATUS_PENDING;
$items[] = $item;

$item = new StdClass();
$item->name = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Active');
$item->id = erLhcoreClassModelMailconvMessage::STATUS_ACTIVE;
$items[] = $item;

$item = new StdClass();
$item->name = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Responded');
$item->id = erLhcoreClassModelMailconvMessage::STATUS_RESPONDED;
$items[] = $item;

return $items;
}
)); ?>
</div>
</div>

Expand Down
14 changes: 14 additions & 0 deletions modules/lhelasticsearch/listmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,20 @@
}
}

if (isset($filterParams['input']->status_conv_id) && is_array($filterParams['input']->status_conv_id) && !empty($filterParams['input']->status_conv_id)) {
erLhcoreClassChat::validateFilterInString($filterParams['input']->status_conv_id);
if (!empty($filterParams['input']->status_conv_id)) {
$sparams['body']['query']['bool']['must'][]['terms']['status_conv'] = $filterParams['input']->status_conv_id;
}
}

if (isset($filterParams['input']->status_msg_id) && is_array($filterParams['input']->status_msg_id) && !empty($filterParams['input']->status_msg_id)) {
erLhcoreClassChat::validateFilterInString($filterParams['input']->status_msg_id);
if (!empty($filterParams['input']->status_msg_id)) {
$sparams['body']['query']['bool']['must'][]['terms']['status'] = $filterParams['input']->status_msg_id;
}
}

if ($filterParams['input_form']->hvf == 1) {
$sparams['body']['query']['bool']['must'][]['terms']['has_attachment'] = [1,2,3];
}
Expand Down
5 changes: 4 additions & 1 deletion modules/lhelasticsearch/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
'export','view','subject_id', 'department_ids',
'department_group_ids','group_ids','hvf','response_type','status','status_conv',
'sender_host','from_host','sender_address','is_followup','undelivered','lang_ids',
'phone','opened','search_email_in','timefromts','fuzzy','fuzzy_prefix'
'phone','opened','search_email_in','timefromts','fuzzy','fuzzy_prefix','status_conv_id',
'status_msg_id'
),
'multiple_arguments' => array(
'search_in',
Expand All @@ -71,6 +72,8 @@
'attr_int_4_multi',
'subject_id',
'lang_ids',
'status_conv_id',
'status_msg_id',
),
'functions' => array('use')
);
Expand Down

0 comments on commit ce2b689

Please sign in to comment.