Skip to content

Commit

Permalink
More filtering options
Browse files Browse the repository at this point in the history
  • Loading branch information
remdex committed Feb 22, 2024
1 parent bfba96a commit 049a9b5
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 6 deletions.
4 changes: 4 additions & 0 deletions classes/erlhcoreclassmodelesmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public function getState()
'mb_folder' => $this->mb_folder,
'conv_duration' => $this->conv_duration,
'has_attachment' => $this->has_attachment,
'has_attachment_conv' => $this->has_attachment_conv,
'is_external' => $this->is_external,
'rfc822_body' => $this->rfc822_body,
'delivery_status' => $this->delivery_status,
'undelivered' => $this->undelivered,
Expand Down Expand Up @@ -216,6 +218,8 @@ public function __get($var)
public $customer_address = null;
public $customer_name = null;
public $conversation_id_old = null;
public $has_attachment_conv = null;
public $is_external = null;

// Dynamic attributes
public $subject_id = null;
Expand Down
23 changes: 23 additions & 0 deletions classes/filter/mail_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

$fieldsSearch = array();

$fieldsSearch['has_attachment'] = array (
'type' => 'text',
'trans' => 'Has attachment',
'required' => false,
'valid_if_filled' => false,
'filter_type' => 'none',
'filter_table_field' => 'has_attachment',
'validation_definition' => new ezcInputFormDefinitionElement(
ezcInputFormDefinitionElement::OPTIONAL, 'int', array( 'min_range' => 0,'max_range' => 1000)
)
);

$fieldsSearch['ipp'] = array (
'type' => 'text',
'trans' => 'View',
Expand Down Expand Up @@ -119,6 +131,17 @@
)
);

$fieldsSearch['is_external'] = array (
'type' => 'text',
'trans' => 'Search in e-mail',
'required' => false,
'valid_if_filled' => false,
'filter_type' => 'none',
'validation_definition' => new ezcInputFormDefinitionElement(
ezcInputFormDefinitionElement::OPTIONAL, 'int', array( 'min_range' => 0, 'max_range' => 1)
)
);

$fieldsSearch['no_user'] = array (
'type' => 'text',
'trans' => 'id',
Expand Down
2 changes: 2 additions & 0 deletions classes/lhelasticsearchindex.php
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,7 @@ public static function indexMails($params) {
$esChat->delivery_status = self::makeKeywords($item->delivery_status_keyed);
$esChat->undelivered = $item->undelivered;
$esChat->priority = $item->priority;
$esChat->is_external = $item->is_external;

// Conversation attributes
if ($item->conversation instanceof erLhcoreClassModelMailconvConversation) {
Expand All @@ -970,6 +971,7 @@ public static function indexMails($params) {
$esChat->phone = $item->conversation->phone;
$esChat->customer_name = $item->conversation->from_name;
$esChat->customer_address = $item->conversation->from_address;
$esChat->has_attachment_conv = $item->conversation->has_attachment;
}

$esChat->subject_id = [];
Expand Down
4 changes: 3 additions & 1 deletion classes/lhelasticsearchstatistic.php
Original file line number Diff line number Diff line change
Expand Up @@ -2414,6 +2414,7 @@ public static function formatFilter($params, & $sparams, $customFields = array()
$field = str_replace('lh_chat.', '', $field);
$field = str_replace('lhc_mailconv_msg.', '', $field);
$field = str_replace('lh_chat_participant.', '', $field);
$field = str_replace('`lhc_mailconv_msg_subject`.`subject_id`', 'subject_id', $field);

if ($field == 'time' || $field == 'itime') {
$value = $value * 1000;
Expand All @@ -2423,6 +2424,8 @@ public static function formatFilter($params, & $sparams, $customFields = array()
$sparams['body']['query']['bool']['must'][]['term'][$field] = $value;
} elseif ($type == 'filterlte') {
$sparams['body']['query']['bool']['must'][]['range'][$field]['lte'] = $value;
} elseif ($type == 'filternotin') {
$sparams['body']['query']['bool']['must_not'][]['terms'][$field] = $value;
} elseif ($type == 'filterlt') {
$sparams['body']['query']['bool']['must'][]['range'][$field]['lt'] = $value;
} elseif ($type == 'filtergte') {
Expand Down Expand Up @@ -2644,7 +2647,6 @@ public static function mailMessagesperintervalprocess($params) {

self::formatFilter($paramsOrig['filter'], $sparams, array('subject_ids' => 'subject_id'));


$response = $elasticSearchHandler->search($sparams);

$valuesResponse = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,18 +415,41 @@
)); ?>
</div>
</div>

<div class="col-md-2">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Attachment');?></label>
<select name="has_attachment" class="form-control form-control-sm">
<option value=""><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Does not matter');?></option>
<option value="1" <?php if ($input->has_attachment === erLhcoreClassModelMailconvConversation::ATTACHMENT_INLINE) : ?>selected="selected"<?php endif;?>><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('pagelayout/pagelayout','Inline');?></option>
<option value="2" <?php if ($input->has_attachment === erLhcoreClassModelMailconvConversation::ATTACHMENT_FILE) : ?>selected="selected"<?php endif;?>><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('pagelayout/pagelayout','As file');?></option>
<option value="3" <?php if ($input->has_attachment === erLhcoreClassModelMailconvConversation::ATTACHMENT_MIX) : ?>selected="selected"<?php endif;?>><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('pagelayout/pagelayout','Inline or as file');?></option>
<option value="5" <?php if ($input->has_attachment === 5) : ?>selected="selected"<?php endif;?>><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('pagelayout/pagelayout','No attachment (inline)');?></option>
<option value="4" <?php if ($input->has_attachment === 4) : ?>selected="selected"<?php endif;?>><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('pagelayout/pagelayout','No attachment (as file)');?></option>
<option value="0" <?php if ($input->has_attachment === erLhcoreClassModelMailconvConversation::ATTACHMENT_EMPTY) : ?>selected="selected"<?php endif;?>><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('pagelayout/pagelayout','No attachment (inline or as file)');?></option>
</select>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Sender');?></label>
<select name="is_external" class="form-control form-control-sm">
<option value=""><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Any');?></option>
<option value="0" <?php if ($input->is_external === 0) : ?>selected="selected"<?php endif; ?>><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','We');?></option>
<option value="1" <?php if ($input->is_external === 1) : ?>selected="selected"<?php endif; ?>><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Visitor');?></option>
</select>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label><input type="checkbox" <?php if ($input->no_user == true) : ?>checked="checked"<?php endif;?> name="no_user" value="on" />&nbsp;<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Has not operator assigned')?></label><br/>
<label><input type="checkbox" <?php if ($input->hvf == true) : ?>checked="checked"<?php endif;?> name="hvf" value="on" />&nbsp;<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Message has an attachment')?></label><br/>
<label><input type="checkbox" name="has_operator" value="1" <?php $input->has_operator == true ? print 'checked="checked"' : ''?> >&nbsp;<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Has operator assigned')?></label>
<label><input type="checkbox" name="has_operator" value="1" <?php $input->has_operator == true ? print 'checked="checked"' : ''?> >&nbsp;<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Has operator assigned')?></label><br/>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label class="col-form-label"><input type="checkbox" name="undelivered" <?php $input->undelivered == 1 ? print ' checked="checked" ' : ''?> value="on" /> <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Undelivered')?></label><br/>
<label class="col-form-label"><input type="checkbox" <?php if ($input->is_followup == true) : ?>checked="checked"<?php endif;?> name="is_followup" value="on" />&nbsp;<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Is followup')?></label>
<label><input type="checkbox" name="undelivered" <?php $input->undelivered == 1 ? print ' checked="checked" ' : ''?> value="on" /> <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Undelivered')?></label><br/>
<label><input type="checkbox" <?php if ($input->is_followup == true) : ?>checked="checked"<?php endif;?> name="is_followup" value="on" />&nbsp;<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Is followup')?></label>
</div>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions doc/structure_elastic.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
"flagged": {
"type": "integer"
},
"has_attachment_conv": {
"type": "integer"
},
"is_external": {
"type": "integer"
},
"msgno": {
"type": "long"
},
Expand Down
36 changes: 36 additions & 0 deletions modules/lhelasticsearch/listmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,38 @@
$sparams['body']['query']['bool']['must'][]['terms']['conversation_id'] = $chat_ids;
}

if (is_numeric($filterParams['input_form']->has_attachment)) {
if ($filterParams['input_form']->has_attachment == erLhcoreClassModelMailconvConversation::ATTACHMENT_MIX) {
$sparams['body']['query']['bool']['must'][]['terms']['has_attachment_conv'] = [
erLhcoreClassModelMailconvConversation::ATTACHMENT_INLINE,
erLhcoreClassModelMailconvConversation::ATTACHMENT_FILE,
erLhcoreClassModelMailconvConversation::ATTACHMENT_MIX
];
} else if ($filterParams['input_form']->has_attachment == erLhcoreClassModelMailconvConversation::ATTACHMENT_INLINE) {
$sparams['body']['query']['bool']['must'][]['terms']['has_attachment_conv'] = [
erLhcoreClassModelMailconvConversation::ATTACHMENT_INLINE,
erLhcoreClassModelMailconvConversation::ATTACHMENT_MIX
];
} else if ($filterParams['input_form']->has_attachment == erLhcoreClassModelMailconvConversation::ATTACHMENT_FILE) {
$sparams['body']['query']['bool']['must'][]['terms']['has_attachment_conv'] = [
erLhcoreClassModelMailconvConversation::ATTACHMENT_FILE,
erLhcoreClassModelMailconvConversation::ATTACHMENT_MIX
];
} else if ($filterParams['input_form']->has_attachment == erLhcoreClassModelMailconvConversation::ATTACHMENT_EMPTY) {
$sparams['body']['query']['bool']['must'][]['term']['has_attachment_conv'] = erLhcoreClassModelMailconvConversation::ATTACHMENT_EMPTY;
} else if ($filterParams['input_form']->has_attachment == 5) { // No attachment (inline)
$sparams['body']['query']['bool']['must_not'][]['terms']['has_attachment_conv'] = [
erLhcoreClassModelMailconvConversation::ATTACHMENT_INLINE,
erLhcoreClassModelMailconvConversation::ATTACHMENT_MIX
];
} else if ($filterParams['input_form']->has_attachment == 4) { // No attachment (as file)
$sparams['body']['query']['bool']['must_not'][]['terms']['has_attachment_conv'] = [
erLhcoreClassModelMailconvConversation::ATTACHMENT_FILE,
erLhcoreClassModelMailconvConversation::ATTACHMENT_MIX
];
}
}

if (trim((string)$filterParams['input_form']->message_id) != '') {
$sparams['body']['query']['bool']['must'][]['term']['id'] = (int)trim($filterParams['input_form']->message_id);
}
Expand Down Expand Up @@ -103,6 +135,10 @@
$sparams['body']['query']['bool']['must'][]['term']['dep_id'] = (int)trim($filterParams['input_form']->department_id);
}

if (is_numeric($filterParams['input_form']->is_external)) {
$sparams['body']['query']['bool']['must'][]['term']['is_external'] = $filterParams['input_form']->is_external;
}

if (trim((string)$filterParams['input_form']->department_group_id) != '') {
$db = ezcDbInstance::get();
$stmt = $db->prepare('SELECT dep_id FROM lh_departament_group_member WHERE dep_group_id = :group_id');
Expand Down
2 changes: 1 addition & 1 deletion modules/lhelasticsearch/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
'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','status_conv_id',
'status_msg_id','mailbox_ids','expression','ipp'
'status_msg_id','mailbox_ids','expression','ipp','has_attachment','is_external'
),
'multiple_arguments' => array(
'search_in',
Expand Down

0 comments on commit 049a9b5

Please sign in to comment.