From ce2b68915f377b61ecb1bb86a94d657ab9be6719 Mon Sep 17 00:00:00 2001 From: Remigijus Kiminas Date: Wed, 1 Feb 2023 05:59:20 -0500 Subject: [PATCH] Updates --- classes/filter/mail_list.php | 24 ++++ classes/lhelasticsearchview.php | 124 ++++++++++++++++++ .../elasticsearch/parts/filter_mail.tpl.php | 68 ++++++++-- modules/lhelasticsearch/listmail.php | 14 ++ modules/lhelasticsearch/module.php | 5 +- 5 files changed, 222 insertions(+), 13 deletions(-) diff --git a/classes/filter/mail_list.php b/classes/filter/mail_list.php index dc702f0..65abbeb 100644 --- a/classes/filter/mail_list.php +++ b/classes/filter/mail_list.php @@ -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', diff --git a/classes/lhelasticsearchview.php b/classes/lhelasticsearchview.php index 7870d13..f381435 100644 --- a/classes/lhelasticsearchview.php +++ b/classes/lhelasticsearchview.php @@ -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(); @@ -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(); @@ -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) { @@ -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(); @@ -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(); diff --git a/design/elasticsearchtheme/tpl/elasticsearch/parts/filter_mail.tpl.php b/design/elasticsearchtheme/tpl/elasticsearch/parts/filter_mail.tpl.php index 61d4ebc..fb927be 100644 --- a/design/elasticsearchtheme/tpl/elasticsearch/parts/filter_mail.tpl.php +++ b/design/elasticsearchtheme/tpl/elasticsearch/parts/filter_mail.tpl.php @@ -256,24 +256,68 @@
- + '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; + } + )); ?>
- + '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; + } + )); ?>
diff --git a/modules/lhelasticsearch/listmail.php b/modules/lhelasticsearch/listmail.php index 28c31ec..8169261 100644 --- a/modules/lhelasticsearch/listmail.php +++ b/modules/lhelasticsearch/listmail.php @@ -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]; } diff --git a/modules/lhelasticsearch/module.php b/modules/lhelasticsearch/module.php index 6fa31a2..f732009 100644 --- a/modules/lhelasticsearch/module.php +++ b/modules/lhelasticsearch/module.php @@ -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', @@ -71,6 +72,8 @@ 'attr_int_4_multi', 'subject_id', 'lang_ids', + 'status_conv_id', + 'status_msg_id', ), 'functions' => array('use') );