Commit 44cdde4b authored by jaapjansma's avatar jaapjansma
Browse files

Added current user to contact filter

parent ec4c5f89
......@@ -12,6 +12,7 @@
* Added documentation generator to the API output.
* Added default sort configuration for a data processor (#26).
* Added Age field.
* Added current user to contact filter.
# Version 1.3.0
......
......@@ -130,6 +130,29 @@ class ContactFilter extends AbstractFieldFilterHandler {
return $configuration;
}
/**
* File name of the template to add this filter to the criteria form.
*
* @return string
*/
public function getTemplateFileName() {
return "CRM/Dataprocessor/Form/Filter/ContactFilter.tpl";
}
/**
* Apply the submitted filter
*
* @param $submittedValues
* @throws \Exception
*/
public function applyFilterFromSubmittedFilterParams($submittedValues) {
if (isset($submittedValues['op']) && $submittedValues['op'] == 'current_user') {
$submittedValues['op'] = 'IN';
$submittedValues['value'] = [\CRM_Core_Session::getLoggedInContactID()];
}
parent::applyFilterFromSubmittedFilterParams($submittedValues);
}
/**
* Add the elements to the filter form.
*
......@@ -223,6 +246,7 @@ class ContactFilter extends AbstractFieldFilterHandler {
'IN' => E::ts('Is one of'),
'NOT IN' => E::ts('Is not one of'),
'null' => E::ts('Is empty'),
'current_user' => E::ts('Is current user'),
);
}
......
{crmScope extensionKey='dataprocessor'}
{assign var=fieldOp value=$filter.alias|cat:"_op"}
{assign var=filterVal value=$filter.alias|cat:"_value"}
{assign var=filterMin value=$filter.alias|cat:"_min"}
{assign var=filterMax value=$filter.alias|cat:"_max"}
<tr>
<td class="label">{$filter.title}</td>
<td>
{if $form.$fieldOp.html}
<span class="filter-processor-element {$filter.alias}">{$form.$fieldOp.html}</span>
<span class="filter-processor-show-close {$filter.alias}">&nbsp;</span>
{/if}
</td>
<td>
{if $filter.type == 'Date' || $filter.type == 'Timestamp'}
{include file="CRM/Dataprocessor/Form/Filter/DateRange.tpl" fieldName=$filter.alias from='_from' to='_to'}
{else}
<span id="{$filterVal}_cell">{$form.$filterVal.label}&nbsp;{$form.$filterVal.html}</span>
<span id="{$filterMin}_max_cell">{$form.$filterMin.label}&nbsp;{$form.$filterMin.html}&nbsp;&nbsp;{$form.$filterMax.label}&nbsp;{$form.$filterMax.html}</span>
{/if}
</td>
</tr>
{/crmScope}
{literal}
<script type="text/javascript">
CRM.$(function($) {
cj("#{/literal}{$fieldOp}{literal}").change(function() {
var val = $(this).val();
if (val == 'current_user') {
cj("#{/literal}{$filterVal}{literal}").addClass('hiddenElement');
} else {
cj("#{/literal}{$filterVal}{literal}").removeClass('hiddenElement');
}
}).change();
});
</script>
{/literal}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment