Calendar: Enable filtering by customfield in list view

This commit is contained in:
nathan 2021-10-28 16:07:25 -06:00
parent 134788efe9
commit 88e539f51d
2 changed files with 40 additions and 6 deletions

View File

@ -794,7 +794,37 @@ class calendar_so
$where = array_merge($where, $params['sql_filter']); $where = array_merge($where, $params['sql_filter']);
} }
} }
if(array_filter($where, fn($key) => str_contains($key, '#'), ARRAY_FILTER_USE_KEY))
{
$custom_fields = Api\Storage\Customfields::get('calendar');
foreach($where as $col => $data)
{
if($col[0] == '#' && $data)
{
unset($where[$col]);
$filtermethod = " $this->cal_table.cal_id IN (SELECT DISTINCT cal_id FROM $this->extra_table WHERE ";
if($custom_fields[substr($col, 1)]['type'] == 'select' && $custom_fields[substr($col, 1)]['rows'] > 1)
{
// Multi-select - any entry with the filter value selected matches
$filtermethod .= $this->db->expression($this->extra_table, array(
'cal_extra_name' => substr($col, 1),
$this->db->concat("','", 'cal_extra_value', "','") . ' ' . $this->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE] . ' ' . $this->db->quote('%,' . $data . ',%'),
)) . ')';
}
else
{
$filtermethod .= $this->db->expression($this->extra_table, array(
'cal_extra_name' => substr($col, 1),
'cal_extra_value' => $data,
)) . ')';
}
$where[] = $filtermethod;
}
}
}
$useUnionQuery = $this->db->capabilities['distinct_on_text'] && $this->db->capabilities['union']; $useUnionQuery = $this->db->capabilities['distinct_on_text'] && $this->db->capabilities['union'];
if($users) if($users)
{ {
$users_by_type = array(); $users_by_type = array();

View File

@ -416,6 +416,10 @@ class calendar_uilist extends calendar_ui
{ {
$col_filter['cal_id'] = $val; $col_filter['cal_id'] = $val;
} }
if($name[0] == '#')
{
$search_params['cfs'][] = $name;
}
} }
// Videocalls // Videocalls
if(array_key_exists('include_videocalls',$params['col_filter'])) if(array_key_exists('include_videocalls',$params['col_filter']))