Skip to content

Commit 23d971b

Browse files
committed
✨ Enhance collected forms with search functionality and additional filters 🎉🔍
- Added search panel for filtering collected forms by department and chat operator. - Implemented date range filters for improved data retrieval 📅. - Updated collected template to include new search options and improved layout. - Enhanced backend to support new search parameters and filtering logic 🔧. - Introduced new search attributes for department and user IDs in the search handler.
1 parent d36017f commit 23d971b

6 files changed

Lines changed: 269 additions & 19 deletions

File tree

lhc_web/design/defaulttheme/tpl/lhform/collected.tpl.php

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<h1 ng-non-bindable><?php echo htmlspecialchars($form)?></h1>
22

33
<div class="row pb-2">
4-
<div class="col-6"><a href="<?php echo erLhcoreClassDesign::baseurl('form/downloadcollected')?>/<?php echo $form->id?>" class="btn btn-secondary"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Download XLS');?></a></div>
54
<?php if ($form->form_type == erLhAbstractModelForm::FORM_TYPE_PUBLIC) : ?>
65
<div class="col-6">
76
<div class="input-group">
@@ -12,16 +11,20 @@
1211
<?php endif; ?>
1312
</div>
1413

14+
<?php include(erLhcoreClassDesign::designtpl('lhform/search_panel.tpl.php')); ?>
15+
1516
<table class="table table-sm" cellpadding="0" cellspacing="0" ng-non-bindable>
1617
<thead>
1718
<tr>
1819
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Name');?></th>
1920
<?php if ($form->form_type == erLhAbstractModelForm::FORM_TYPE_INTERNAL) : ?>
20-
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Operator');?></th>
21+
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Creator');?></th>
2122
<?php else : ?>
2223
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Identifier');?></th>
2324
<?php endif; ?>
2425
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Chat');?></th>
26+
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Chat Operator');?></th>
27+
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Department');?></th>
2528
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Intro');?></th>
2629
<th><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Time');?></th>
2730
<?php if ($form->form_type == erLhAbstractModelForm::FORM_TYPE_PUBLIC) : ?>
@@ -44,26 +47,36 @@
4447
</td>
4548
<?php endif; ?>
4649
<td>
47-
<?php if ($item->chat_id > 0) : ?>
48-
<a onclick="lhc.previewChat(<?php echo $item->chat_id?>)"><span class="material-icons">info_outline</span><?php echo $item->chat_id;?></a>
49-
<?php else : ?>
50-
<i class="material-icons">remove_circle_outline</i>
51-
<?php endif; ?>
50+
<?php if ($item->chat_id > 0) : ?>
51+
<a onclick="lhc.previewChat(<?php echo $item->chat_id?>)"><span class="material-icons">info_outline</span><?php echo $item->chat_id;?></a>
52+
<?php else : ?>
53+
<i class="material-icons">remove_circle_outline</i>
54+
<?php endif; ?>
5255
</td>
56+
<td>
57+
<?php if ($item->chat_id > 0 && is_object($item->chat)) : ?>
58+
<?php echo htmlspecialchars($item->chat->n_official); ?>
59+
<?php else : ?>
60+
n/a
61+
<?php endif; ?>
62+
</td>
63+
<td>
64+
<?php if ($item->chat_id > 0 && is_object($item->chat) && $item->chat->department instanceof erLhcoreClassModelDepartament) : ?>
65+
<?php echo htmlspecialchars($item->chat->department->name); ?>
66+
<?php else : ?>
67+
n/a
68+
<?php endif; ?>
69+
</td>
5370
<td><?php echo $form->intro_attr != '' ? htmlspecialchars($item->getAttrValue($form->intro_attr)) : ''?></td>
5471
<td><?php echo $item->ctime_front?></td>
5572
<?php if ($form->form_type == erLhAbstractModelForm::FORM_TYPE_PUBLIC) : ?>
5673
<td><?php echo htmlspecialchars($item->ip)?></td>
5774
<?php endif; ?>
5875
<td nowrap>
59-
<div style="width:140px">
60-
61-
<div class="btn-group" role="group" aria-label="...">
62-
<a class="btn btn-secondary btn-xs" href="<?php echo erLhcoreClassDesign::baseurl('form/viewcollected')?>/<?php echo $item->id?>"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','View');?></a>
63-
<a class="btn btn-secondary btn-xs" href="<?php echo erLhcoreClassDesign::baseurl('form/downloaditem')?>/<?php echo $item->id?>"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Download');?></a>
64-
</div>
65-
66-
</div>
76+
<div class="btn-group" role="group" aria-label="...">
77+
<a class="btn btn-secondary btn-xs" href="<?php echo erLhcoreClassDesign::baseurl('form/viewcollected')?>/<?php echo $item->id?>"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','View');?></a>
78+
<a class="btn btn-secondary btn-xs" href="<?php echo erLhcoreClassDesign::baseurl('form/downloaditem')?>/<?php echo $item->id?>"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Download');?></a>
79+
</div>
6780
</td>
6881
<?php if (erLhcoreClassUser::instance()->hasAccessTo('lhform', 'delete_collected')) : ?>
6982
<td nowrap><a data-trans="delete_confirm" class="csfr-post csfr-required btn btn-danger btn-xs" href="<?php echo erLhcoreClassDesign::baseurl('form/collected')?>/<?php echo $form->id?>/(action)/delete/(id)/<?php echo $item->id?>"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Delete');?></a></td>
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<form action="<?php echo $input->form_action?>" method="get" name="SearchFormRight" ng-non-bindable autocomplete="off">
2+
3+
<input type="hidden" name="doSearch" value="1">
4+
5+
<div class="row mb-2">
6+
<div class="col-md-3">
7+
<div class="form-group">
8+
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Department');?></label>
9+
<?php echo erLhcoreClassRenderHelper::renderMultiDropdown(array(
10+
'input_name' => 'department_ids[]',
11+
'optional_field' => erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Choose department'),
12+
'selected_id' => $input->department_ids,
13+
'css_class' => 'form-control',
14+
'display_name' => 'name',
15+
'ajax' => 'deps',
16+
'list_function_params' => array_merge(array('sort' => '`name` ASC', 'limit' => 50), erLhcoreClassUserDep::conditionalDepartmentFilter()),
17+
'list_function' => 'erLhcoreClassModelDepartament::getList'
18+
)); ?>
19+
</div>
20+
</div>
21+
<div class="col-md-3">
22+
<div class="form-group">
23+
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Chat operator');?></label>
24+
<?php echo erLhcoreClassRenderHelper::renderMultiDropdown(array(
25+
'input_name' => 'user_ids[]',
26+
'optional_field' => erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Choose operator'),
27+
'selected_id' => $input->user_ids,
28+
'css_class' => 'form-control',
29+
'display_name' => 'name_official',
30+
'ajax' => 'users',
31+
'list_function_params' => array_merge(erLhcoreClassGroupUser::getConditionalUserFilter(), array('sort' => '`name` ASC', 'limit' => 50)),
32+
'list_function' => 'erLhcoreClassModelUser::getUserList'
33+
)); ?>
34+
</div>
35+
</div>
36+
</div>
37+
38+
<div class="row mb-2">
39+
<div class="col-md-2">
40+
<div class="form-group">
41+
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Date from');?></label>
42+
<input type="text" class="form-control form-control-sm" name="timefrom" id="id_timefrom" value="<?php echo htmlspecialchars((string)$input->timefrom)?>" placeholder="<?php echo date('Y-m-d', time() - 7 * 24 * 3600)?>">
43+
</div>
44+
</div>
45+
<div class="col-md-3">
46+
<div class="form-group">
47+
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Hour and minute from');?> <small>[<?php echo date('H:i:s')?>]</small></label>
48+
<div class="row">
49+
<div class="col-4">
50+
<select name="timefrom_hours" class="form-control form-control-sm">
51+
<option value=""><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Select hour');?></option>
52+
<?php for ($i = 0; $i <= 23; $i++) : ?>
53+
<option value="<?php echo $i?>" <?php if (isset($input->timefrom_hours) && $input->timefrom_hours === $i) : ?>selected="selected"<?php endif;?>><?php echo str_pad($i,2, '0', STR_PAD_LEFT);?> h.</option>
54+
<?php endfor;?>
55+
</select>
56+
</div>
57+
<div class="col-4">
58+
<select name="timefrom_minutes" class="form-control form-control-sm">
59+
<option value=""><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Select minute');?></option>
60+
<?php for ($i = 0; $i <= 59; $i++) : ?>
61+
<option value="<?php echo $i?>" <?php if (isset($input->timefrom_minutes) && $input->timefrom_minutes === $i) : ?>selected="selected"<?php endif;?>><?php echo str_pad($i,2, '0', STR_PAD_LEFT);?> m.</option>
62+
<?php endfor;?>
63+
</select>
64+
</div>
65+
<div class="col-4">
66+
<select name="timefrom_seconds" class="form-control form-control-sm">
67+
<option value=""><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Select seconds');?></option>
68+
<?php for ($i = 0; $i <= 59; $i++) : ?>
69+
<option value="<?php echo $i?>" <?php if (isset($input->timefrom_seconds) && $input->timefrom_seconds === $i) : ?>selected="selected"<?php endif;?>><?php echo str_pad($i,2, '0', STR_PAD_LEFT);?> s.</option>
70+
<?php endfor;?>
71+
</select>
72+
</div>
73+
</div>
74+
</div>
75+
</div>
76+
<div class="col-md-2">
77+
<div class="form-group">
78+
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Date to');?></label>
79+
<input type="text" class="form-control form-control-sm" name="timeto" id="id_timeto" value="<?php echo htmlspecialchars((string)$input->timeto)?>" placeholder="<?php echo date('Y-m-d')?>">
80+
</div>
81+
</div>
82+
<div class="col-md-3">
83+
<div class="form-group">
84+
<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Hour and minute to');?> <small>[<?php echo date('H:i:s')?>]</small></label>
85+
<div class="row">
86+
<div class="col-4">
87+
<select name="timeto_hours" class="form-control form-control-sm">
88+
<option value=""><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Select hour');?></option>
89+
<?php for ($i = 0; $i <= 23; $i++) : ?>
90+
<option value="<?php echo $i?>" <?php if (isset($input->timeto_hours) && $input->timeto_hours === $i) : ?>selected="selected"<?php endif;?>><?php echo str_pad($i,2, '0', STR_PAD_LEFT);?> h.</option>
91+
<?php endfor;?>
92+
</select>
93+
</div>
94+
<div class="col-4">
95+
<select name="timeto_minutes" class="form-control form-control-sm">
96+
<option value=""><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Select minute');?></option>
97+
<?php for ($i = 0; $i <= 59; $i++) : ?>
98+
<option value="<?php echo $i?>" <?php if (isset($input->timeto_minutes) && $input->timeto_minutes === $i) : ?>selected="selected"<?php endif;?>><?php echo str_pad($i,2, '0', STR_PAD_LEFT);?> m.</option>
99+
<?php endfor;?>
100+
</select>
101+
</div>
102+
<div class="col-4">
103+
<select name="timeto_seconds" class="form-control form-control-sm">
104+
<option value=""><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Select seconds');?></option>
105+
<?php for ($i = 0; $i <= 59; $i++) : ?>
106+
<option value="<?php echo $i?>" <?php if (isset($input->timeto_seconds) && $input->timeto_seconds === $i) : ?>selected="selected"<?php endif;?>><?php echo str_pad($i,2, '0', STR_PAD_LEFT);?> s.</option>
107+
<?php endfor;?>
108+
</select>
109+
</div>
110+
</div>
111+
</div>
112+
</div>
113+
<div class="col-md-12 d-flex align-items-end">
114+
<div class="btn-group me-2">
115+
<button type="submit" class="btn btn-primary btn-sm" name="doSearch"><span class="material-icons">search</span><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Search');?></button>
116+
<a href="<?php echo erLhcoreClassDesign::baseurl('form/downloadcollected')?>/<?php echo $form->id?>" class="btn btn-outline-secondary btn-sm"><span class="material-icons">file_download</span><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('form/collected','Download XLS');?></a>
117+
</div>
118+
</div>
119+
</div>
120+
121+
</form>
122+
123+
<script>
124+
$(function() {
125+
$('#id_timefrom,#id_timeto').fdatepicker({
126+
format: 'yyyy-mm-dd'
127+
});
128+
$('.btn-block-department').makeDropdown();
129+
});
130+
</script>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
$fieldsSearch = array();
4+
5+
$fieldsSearch['department_ids'] = array(
6+
'type' => 'text',
7+
'trans' => 'Department',
8+
'required' => false,
9+
'valid_if_filled' => false,
10+
'filter_type' => 'filter',
11+
'filter_table_field' => '`lh_chat`.`dep_id`',
12+
'validation_definition' => new ezcInputFormDefinitionElement(
13+
ezcInputFormDefinitionElement::OPTIONAL, 'int', array('min_range' => 0), FILTER_REQUIRE_ARRAY
14+
)
15+
);
16+
17+
$fieldsSearch['user_ids'] = array(
18+
'type' => 'text',
19+
'trans' => 'Chat operator',
20+
'required' => false,
21+
'valid_if_filled' => false,
22+
'filter_type' => 'filter',
23+
'filter_table_field' => '`lh_chat`.`user_id`',
24+
'validation_definition' => new ezcInputFormDefinitionElement(
25+
ezcInputFormDefinitionElement::OPTIONAL, 'int', array('min_range' => 0), FILTER_REQUIRE_ARRAY
26+
)
27+
);
28+
29+
$fieldsSearch['timefrom'] = array(
30+
'type' => 'text',
31+
'trans' => 'Time from',
32+
'required' => false,
33+
'valid_if_filled' => false,
34+
'datatype' => 'datetime',
35+
'filter_type' => 'filtergte',
36+
'filter_table_field' => 'ctime',
37+
'validation_definition' => new ezcInputFormDefinitionElement(
38+
ezcInputFormDefinitionElement::OPTIONAL, 'string'
39+
)
40+
);
41+
42+
$fieldsSearch['timeto'] = array(
43+
'type' => 'text',
44+
'trans' => 'Time to',
45+
'required' => false,
46+
'valid_if_filled' => false,
47+
'datatype' => 'datetime',
48+
'filter_type' => 'filterlte',
49+
'filter_table_field' => 'ctime',
50+
'validation_definition' => new ezcInputFormDefinitionElement(
51+
ezcInputFormDefinitionElement::OPTIONAL, 'string'
52+
)
53+
);
54+
55+
$fieldSortAttr = array(
56+
'field' => false,
57+
'default' => false,
58+
'serialised' => true,
59+
'disabled' => true,
60+
'options' => array()
61+
);
62+
63+
return array(
64+
'filterAttributes' => $fieldsSearch,
65+
'sortAttributes' => $fieldSortAttr
66+
);

lhc_web/lib/models/lhabstract/erlhabstractmodelformcollected.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ public function __get($var)
7070
}
7171
return $this->user;
7272

73+
case 'chat':
74+
$this->chat = false;
75+
if ($this->chat_id > 0) {
76+
try {
77+
$this->chat = erLhcoreClassModelChat::fetch($this->chat_id,true);
78+
} catch (Exception $e) {
79+
$this->chat = false;
80+
}
81+
}
82+
return $this->chat;
83+
7384
case 'form_content':
7485
return $this->getFormattedContent();
7586
default:

lhc_web/modules/lhform/collected.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@
44

55
$form = erLhAbstractModelForm::fetch((int)$Params['user_parameters']['form_id']);
66

7+
if (isset($_GET['doSearch'])) {
8+
$filterParams = erLhcoreClassSearchHandler::getParams(array('module' => 'form','module_file' => 'collected', 'format_filter' => true, 'use_override' => true, 'uparams' => $Params['user_parameters_unordered']));
9+
$filterParams['is_search'] = true;
10+
} else {
11+
$filterParams = erLhcoreClassSearchHandler::getParams(array('module' => 'form','module_file' => 'collected', 'format_filter' => true, 'uparams' => $Params['user_parameters_unordered']));
12+
$filterParams['is_search'] = false;
13+
}
14+
15+
$append = erLhcoreClassSearchHandler::getURLAppendFromInput($filterParams['input_form']);
16+
17+
$filter = $filterParams['filter'];
18+
$filter['filter']['form_id'] = $form->id;
19+
20+
$departmentIds = $filterParams['input_form']->department_ids;
21+
$userIds = $filterParams['input_form']->user_ids;
22+
23+
$needsJoin = !empty($departmentIds) || !empty($userIds);
24+
25+
if ($needsJoin) {
26+
$filter['leftjoin']['lh_chat'] = array('lh_chat.id', 'lh_abstract_form_collected.chat_id');
27+
}
28+
729
if (is_numeric($Params['user_parameters_unordered']['id']) && $Params['user_parameters_unordered']['action'] == 'delete'){
830

931
// Delete selected canned message
@@ -25,19 +47,23 @@
2547
}
2648

2749
$pages = new lhPaginator();
28-
$pages->serverURL = erLhcoreClassDesign::baseurl('form/collected').'/'.$form->id;
29-
$pages->items_total = erLhAbstractModelFormCollected::getCount(array('filter' => array('form_id' => $form->id)));
50+
$pages->serverURL = erLhcoreClassDesign::baseurl('form/collected').'/'.$form->id . $append;
51+
$pages->items_total = erLhAbstractModelFormCollected::getCount($filter);
3052
$pages->setItemsPerPage(20);
3153
$pages->paginate();
3254

3355
$items = array();
3456
if ($pages->items_total > 0) {
35-
$items = erLhAbstractModelFormCollected::getList(array('filter' => array('form_id' => $form->id),'offset' => $pages->low, 'limit' => $pages->items_per_page,'sort' => 'id DESC'));
57+
$items = erLhAbstractModelFormCollected::getList(array_merge($filter, array('offset' => $pages->low, 'limit' => $pages->items_per_page, 'sort' => 'id DESC')));
3658
}
3759

3860
$tpl->set('items',$items);
3961
$tpl->set('pages',$pages);
4062

63+
$filterParams['input_form']->form_action = erLhcoreClassDesign::baseurl('form/collected').'/'.$form->id;
64+
$tpl->set('input',$filterParams['input_form']);
65+
$tpl->set('inputAppend',$append);
66+
4167
$tpl->set('form',$form);
4268
$Result['content'] = $tpl->fetch();
4369

lhc_web/modules/lhform/module.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616

1717
$ViewList['collected'] = array(
1818
'params' => array('form_id'),
19-
'uparams' => array('action','id','csfr'),
19+
'uparams' => array('action','id','csfr','department_ids','user_ids','timefrom','timeto','timefrom_hours','timefrom_minutes','timefrom_seconds','timeto_hours','timeto_minutes','timeto_seconds'),
20+
'multiple_arguments' => array(
21+
'department_ids',
22+
'user_ids'
23+
),
2024
'functions' => array( 'manage_fm' )
2125
);
2226

0 commit comments

Comments
 (0)