| 1 |
<?php |
| 2 |
|
| 3 |
use AcyMailing\Types\OperatorInType; |
| 4 |
use AcyMailing\Types\OperatorType; |
| 5 |
|
| 6 |
trait UserAutomationFilters |
| 7 |
{ |
| 8 |
public function onAcymDeclareFilters(array &$filters): void |
| 9 |
{ |
| 10 |
$allGroups = acym_getGroups(); |
| 11 |
$groups = ['' => acym_translation('ACYM_NO_GROUP')]; |
| 12 |
foreach ($allGroups as $group) { |
| 13 |
$groups[$group->id] = $group->text; |
| 14 |
} |
| 15 |
$operatorIn = new OperatorInType(); |
| 16 |
|
| 17 |
$filters['acy_group'] = new stdClass(); |
| 18 |
$filters['acy_group']->name = acym_translation('ACYM_GROUP'); |
| 19 |
$filters['acy_group']->option = '<div class="intext_select_automation cell">'; |
| 20 |
$filters['acy_group']->option .= $operatorIn->display('acym_action[filters][__numor__][__numand__][acy_group][in]'); |
| 21 |
$filters['acy_group']->option .= '</div>'; |
| 22 |
$filters['acy_group']->option .= '<div class="intext_select_automation cell">'; |
| 23 |
$filters['acy_group']->option .= acym_select( |
| 24 |
$groups, |
| 25 |
'acym_action[filters][__numor__][__numand__][acy_group][group]', |
| 26 |
null, |
| 27 |
['class' => 'acym__select'] |
| 28 |
); |
| 29 |
$filters['acy_group']->option .= '</div>'; |
| 30 |
|
| 31 |
if (ACYM_CMS == 'joomla') { |
| 32 |
$filters['acy_group']->option .= '<div class="cell grid-x medium-3">'; |
| 33 |
ob_start(); |
| 34 |
acym_switch([ |
| 35 |
'name' => 'acym_action[filters][__numor__][__numand__][acy_group][subgroup]', |
| 36 |
'value' => 1, |
| 37 |
'label' => acym_translation('ACYM_INCLUDE_SUB_GROUPS'), |
| 38 |
]); |
| 39 |
$filters['acy_group']->option .= ob_get_clean(); |
| 40 |
$filters['acy_group']->option .= '</div>'; |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
$cmsFields = []; |
| 45 |
foreach (acym_getColumns('users', false) as $key => $column) { |
| 46 |
$cmsFields[$column] = $column; |
| 47 |
} |
| 48 |
|
| 49 |
// Handle custom fields |
| 50 |
if (ACYM_CMS == 'joomla' && ACYM_J37) { |
| 51 |
$query = 'SELECT id, title |
| 52 |
FROM #__fields |
| 53 |
WHERE context = "com_users.user" |
| 54 |
AND state = 1 |
| 55 |
AND type IN ("calendar", "checkboxes", "color", "integer", "list", "radio", "sql", "text", "url") |
| 56 |
ORDER BY title ASC'; |
| 57 |
$customFields = acym_loadObjectList($query); |
| 58 |
foreach ($customFields as $oneCF) { |
| 59 |
$cmsFields['cf_'.$oneCF->id] = $oneCF->title; |
| 60 |
} |
| 61 |
} |
| 62 |
$excluded = ['password', 'params', 'activation', 'lastResetTime', 'resetCount', 'optKey', 'otep', 'requireReset', 'user_pass', 'user_activation_key']; |
| 63 |
foreach ($excluded as $oneExcluded) { |
| 64 |
unset($cmsFields[$oneExcluded]); |
| 65 |
} |
| 66 |
|
| 67 |
$operator = new OperatorType(); |
| 68 |
|
| 69 |
$filters['acy_cmsfield'] = new stdClass(); |
| 70 |
$filters['acy_cmsfield']->name = acym_translation('ACYM_ACCOUNT_USER_FIELD'); |
| 71 |
$filters['acy_cmsfield']->option = '<div class="intext_select_automation cell">'; |
| 72 |
$filters['acy_cmsfield']->option .= acym_select( |
| 73 |
$cmsFields, |
| 74 |
'acym_action[filters][__numor__][__numand__][acy_cmsfield][field]', |
| 75 |
null, |
| 76 |
['class' => 'acym__select'] |
| 77 |
); |
| 78 |
$filters['acy_cmsfield']->option .= '</div>'; |
| 79 |
$filters['acy_cmsfield']->option .= '<div class="intext_select_automation cell">'; |
| 80 |
$filters['acy_cmsfield']->option .= $operator->display('acym_action[filters][__numor__][__numand__][acy_cmsfield][operator]'); |
| 81 |
$filters['acy_cmsfield']->option .= '</div>'; |
| 82 |
$filters['acy_cmsfield']->option .= '<input class="intext_input_automation cell" type="text" name="acym_action[filters][__numor__][__numand__][acy_cmsfield][value]">'; |
| 83 |
} |
| 84 |
|
| 85 |
public function onAcymProcessFilter_acy_group(&$query, $options, $num) |
| 86 |
{ |
| 87 |
$this->processAcyGroup($query, $options, $num); |
| 88 |
} |
| 89 |
|
| 90 |
public function onAcymProcessFilterCount_acy_group(&$query, $options, $num) |
| 91 |
{ |
| 92 |
$this->onAcymProcessFilter_acy_group($query, $options, $num); |
| 93 |
|
| 94 |
return acym_translationSprintf('ACYM_SELECTED_USERS', $query->count()); |
| 95 |
} |
| 96 |
|
| 97 |
public function onAcymProcessFilter_acy_cmsfield(&$query, $options, $num) |
| 98 |
{ |
| 99 |
$this->processAcyCMSField($query, $options, $num); |
| 100 |
} |
| 101 |
|
| 102 |
public function onAcymProcessFilterCount_acy_cmsfield(&$query, $options, $num) |
| 103 |
{ |
| 104 |
$this->onAcymProcessFilter_acy_cmsfield($query, $options, $num); |
| 105 |
|
| 106 |
return acym_translationSprintf('ACYM_SELECTED_USERS', $query->count()); |
| 107 |
} |
| 108 |
|
| 109 |
public function onAcymDeclareSummary_filters(&$automation) |
| 110 |
{ |
| 111 |
$this->summaryGroup($automation); |
| 112 |
|
| 113 |
if (!empty($automation['acy_cmsfield'])) { |
| 114 |
$automation = acym_translationSprintf( |
| 115 |
'ACYM_FILTER_ACY_CMS_FIELD_SUMMARY', |
| 116 |
$automation['acy_cmsfield']['field'], |
| 117 |
$automation['acy_cmsfield']['operator'], |
| 118 |
$automation['acy_cmsfield']['value'] |
| 119 |
); |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
public function onAcymProcessFilter_birthday(&$query, $options, $num = null) |
| 124 |
{ |
| 125 |
if ($options['plugin'] !== get_class($this) || ACYM_CMS !== 'joomla' || !ACYM_J37) return; |
| 126 |
|
| 127 |
$dateToCheck = $this->processDateToCheck($options); |
| 128 |
|
| 129 |
$query->join['j_fields'.$num] = '#__fields_values AS jf'.$num.' ON jf'.$num.'.item_id = user.cms_id AND jf'.$num.'.field_id = '.intval($options['field']); |
| 130 |
$query->where[] = 'user.cms_id != 0 '; |
| 131 |
$query->where[] = 'jf'.$num.'.value LIKE '.acym_escapeDB('%'.date_format($dateToCheck, '-m-d').'%'); |
| 132 |
} |
| 133 |
} |
| 134 |
|