← All changes
|
back/dynamics/user/UserAutomationConditions.php
+108
-63
10.10.2
→
11.1.0
View file →
| @@ -5,10 +5,26 @@ | ||
| 5 | 5 | use AcyMailing\Types\OperatorType; |
| 6 | 6 | |
| 7 | 7 | trait UserAutomationConditions |
| 8 | 8 | { |
| 9 | - public function onAcymDeclareConditions(array &$conditions): void | |
| 9 | + protected function initAutomationConditions(): void | |
| 10 | 10 | { |
| 11 | + $this->automationConditions = [ | |
| 12 | + 'user' => [ | |
| 13 | + 'acy_group' => acym_translation('ACYM_GROUP'), | |
| 14 | + 'acy_cmsfield' => acym_translation('ACYM_ACCOUNT_USER_FIELD'), | |
| 15 | + ], | |
| 16 | + 'classic' => [ | |
| 17 | + 'acy_totaluser' => acym_translation('ACYM_NUMBER_OF_SUBSCRIBERS'), | |
| 18 | + ], | |
| 19 | + 'both' => [ | |
| 20 | + 'acy_toss' => acym_translation('ACYM_TOSS'), | |
| 21 | + ], | |
| 22 | + ]; | |
| 23 | + } | |
| 24 | + | |
| 25 | + public function displayConditionOptions_acy_group(string $fieldName): void | |
| 26 | + { | |
| 11 | 27 | $allGroups = acym_getGroups(); |
| 12 | 28 | $groups = ['' => acym_translation('ACYM_NO_GROUP')]; |
| 13 | 29 | foreach ($allGroups as $group) { |
| 14 | 30 | $groups[$group->id] = $group->text; |
| @@ -13,37 +29,46 @@ | ||
| 13 | 29 | foreach ($allGroups as $group) { |
| 14 | 30 | $groups[$group->id] = $group->text; |
| 15 | 31 | } |
| 16 | 32 | $operatorIn = new OperatorInType(); |
| 33 | + ?> | |
| 34 | + <div class="intext_select_automation cell"> | |
| 35 | + <?php $operatorIn->display($fieldName.'[in]', '', 'acym__select', true); ?> | |
| 36 | + </div> | |
| 37 | + <div class="intext_select_automation cell"> | |
| 38 | + <?php acym_select( | |
| 39 | + $groups, | |
| 40 | + $fieldName.'[group]', | |
| 41 | + null, | |
| 42 | + ['class' => 'acym__select'], | |
| 43 | + 'value', | |
| 44 | + 'text', | |
| 45 | + null, | |
| 46 | + false, | |
| 47 | + true | |
| 48 | + ); ?> | |
| 49 | + </div> | |
| 50 | + <?php if (ACYM_CMS === 'joomla') { ?> | |
| 51 | + <div class="cell grid-x medium-3"> | |
| 52 | + <?php acym_switch([ | |
| 53 | + 'name' => $fieldName.'[subgroup]', | |
| 54 | + 'value' => 1, | |
| 55 | + 'label' => acym_translation('ACYM_INCLUDE_SUB_GROUPS'), | |
| 56 | + // One switch per row of the form, the JS replaces the placeholder to keep the ids unique | |
| 57 | + 'idPrefix' => '__numand__', | |
| 58 | + ]); ?> | |
| 59 | + </div> | |
| 60 | + <?php } | |
| 61 | + } | |
| 17 | 62 | |
| 18 | - $conditions['user']['acy_group'] = new stdClass(); | |
| 19 | - $conditions['user']['acy_group']->name = acym_translation('ACYM_GROUP'); | |
| 20 | - $conditions['user']['acy_group']->option = '<div class="intext_select_automation cell">'; | |
| 21 | - $conditions['user']['acy_group']->option .= $operatorIn->display('acym_condition[conditions][__numor__][__numand__][acy_group][in]'); | |
| 22 | - $conditions['user']['acy_group']->option .= '</div>'; | |
| 23 | - $conditions['user']['acy_group']->option .= '<div class="intext_select_automation cell">'; | |
| 24 | - $conditions['user']['acy_group']->option .= acym_select( | |
| 25 | - $groups, | |
| 26 | - 'acym_condition[conditions][__numor__][__numand__][acy_group][group]', | |
| 27 | - null, | |
| 28 | - ['class' => 'acym__select'] | |
| 29 | - ); | |
| 30 | - $conditions['user']['acy_group']->option .= '</div>'; | |
| 31 | - if (ACYM_CMS === 'joomla') { | |
| 32 | - $conditions['user']['acy_group']->option .= '<div class="cell grid-x medium-3">'; | |
| 33 | - $conditions['user']['acy_group']->option .= acym_switch( | |
| 34 | - 'acym_condition[conditions][__numor__][__numand__][acy_group][subgroup]', | |
| 35 | - 1, | |
| 36 | - acym_translation('ACYM_INCLUDE_SUB_GROUPS') | |
| 37 | - ); | |
| 38 | - $conditions['user']['acy_group']->option .= '</div>'; | |
| 39 | - } | |
| 40 | - | |
| 63 | + private function getCmsFieldsForConditions(): array | |
| 64 | + { | |
| 41 | 65 | $cmsFields = []; |
| 42 | 66 | foreach (acym_getColumns('users', false) as $key => $column) { |
| 43 | 67 | $cmsFields[$column] = $column; |
| 44 | 68 | } |
| 45 | 69 | |
| 70 | + // Handle custom fields | |
| 46 | 71 | if (ACYM_CMS == 'joomla' && ACYM_J37) { |
| 47 | 72 | $query = 'SELECT id, title |
| 48 | 73 | FROM #__fields |
| 49 | 74 | WHERE context = "com_users.user" |
| @@ -59,54 +84,72 @@ | ||
| 59 | 84 | foreach ($excluded as $oneExcluded) { |
| 60 | 85 | unset($cmsFields[$oneExcluded]); |
| 61 | 86 | } |
| 62 | 87 | |
| 88 | + return $cmsFields; | |
| 89 | + } | |
| 90 | + | |
| 91 | + public function displayConditionOptions_acy_cmsfield(string $fieldName): void | |
| 92 | + { | |
| 63 | 93 | $operator = new OperatorType(); |
| 94 | + ?> | |
| 95 | + <div class="intext_select_automation cell"> | |
| 96 | + <?php acym_select( | |
| 97 | + $this->getCmsFieldsForConditions(), | |
| 98 | + $fieldName.'[field]', | |
| 99 | + null, | |
| 100 | + ['class' => 'acym__select'], | |
| 101 | + 'value', | |
| 102 | + 'text', | |
| 103 | + null, | |
| 104 | + false, | |
| 105 | + true | |
| 106 | + ); ?> | |
| 107 | + </div> | |
| 108 | + <div class="intext_select_automation cell"> | |
| 109 | + <?php $operator->display($fieldName.'[operator]', '', 'acym__select', true); ?> | |
| 110 | + </div> | |
| 111 | + <input class="intext_input_automation cell" type="text" name="<?php echo esc_attr($fieldName.'[value]'); ?>"> | |
| 112 | + <?php | |
| 113 | + } | |
| 64 | 114 | |
| 65 | - $conditions['user']['acy_cmsfield'] = new stdClass(); | |
| 66 | - $conditions['user']['acy_cmsfield']->name = acym_translation('ACYM_ACCOUNT_USER_FIELD'); | |
| 67 | - $conditions['user']['acy_cmsfield']->option = '<div class="intext_select_automation cell">'; | |
| 68 | - $conditions['user']['acy_cmsfield']->option .= acym_select( | |
| 69 | - $cmsFields, | |
| 70 | - 'acym_condition[conditions][__numor__][__numand__][acy_cmsfield][field]', | |
| 71 | - null, | |
| 72 | - ['class' => 'acym__select'] | |
| 73 | - ); | |
| 74 | - $conditions['user']['acy_cmsfield']->option .= '</div>'; | |
| 75 | - $conditions['user']['acy_cmsfield']->option .= '<div class="intext_select_automation cell">'; | |
| 76 | - $conditions['user']['acy_cmsfield']->option .= $operator->display('acym_condition[conditions][__numor__][__numand__][acy_cmsfield][operator]'); | |
| 77 | - $conditions['user']['acy_cmsfield']->option .= '</div>'; | |
| 78 | - $conditions['user']['acy_cmsfield']->option .= '<input class="intext_input_automation cell" type="text" name="acym_condition[conditions][__numor__][__numand__][acy_cmsfield][value]">'; | |
| 79 | - | |
| 80 | - $conditions['classic']['acy_totaluser'] = new stdClass(); | |
| 81 | - $conditions['classic']['acy_totaluser']->name = acym_translation('ACYM_NUMBER_OF_SUBSCRIBERS'); | |
| 82 | - $conditions['classic']['acy_totaluser']->option = '<div class="cell shrink acym__automation__inner__text">'.acym_translation('ACYM_THERE_IS').'</div>'; | |
| 83 | - $conditions['classic']['acy_totaluser']->option .= '<div class="intext_select_automation cell">'; | |
| 84 | - $conditions['classic']['acy_totaluser']->option .= acym_select( | |
| 85 | - ['=' => acym_translation('ACYM_EXACTLY'), '>' => acym_translation('ACYM_MORE_THAN'), '<' => acym_translation('ACYM_LESS_THAN')], | |
| 86 | - 'acym_condition[conditions][__numor__][__numand__][acy_totaluser][operator]', | |
| 87 | - null, | |
| 88 | - ['class' => 'intext_select_automation acym__select'] | |
| 89 | - ); | |
| 90 | - $conditions['classic']['acy_totaluser']->option .= '</div>'; | |
| 91 | - $conditions['classic']['acy_totaluser']->option .= '<input type="number" min="0" class="intext_input_automation cell" name="acym_condition[conditions][__numor__][__numand__][acy_totaluser][number]">'; | |
| 92 | - $conditions['classic']['acy_totaluser']->option .= '<div class="cell shrink acym__automation__inner__text">'.acym_translation('ACYM_ACYMAILING_USERS').'</div>'; | |
| 93 | - | |
| 94 | - $conditions['both']['acy_toss'] = new stdClass(); | |
| 95 | - $conditions['both']['acy_toss']->name = acym_translation('ACYM_TOSS'); | |
| 96 | - $conditions['both']['acy_toss']->option = '<input type="hidden" name="acym_condition[conditions][__numor__][__numand__][acy_toss][toss]" value="true"><div class="acym__automation__inner__text">'.acym_translation( | |
| 97 | - 'ACYM_TOSS_DESC' | |
| 98 | - ).'</div>'; | |
| 115 | + public function displayConditionOptions_acy_totaluser(string $fieldName): void | |
| 116 | + { | |
| 117 | + ?> | |
| 118 | + <div class="cell shrink acym__automation__inner__text"><?php echo esc_html(acym_translation('ACYM_THERE_IS')); ?></div> | |
| 119 | + <div class="intext_select_automation cell"> | |
| 120 | + <?php acym_select( | |
| 121 | + [ | |
| 122 | + '=' => acym_translation('ACYM_EXACTLY'), | |
| 123 | + '>' => acym_translation('ACYM_MORE_THAN'), | |
| 124 | + '<' => acym_translation('ACYM_LESS_THAN'), | |
| 125 | + ], | |
| 126 | + $fieldName.'[operator]', | |
| 127 | + null, | |
| 128 | + ['class' => 'intext_select_automation acym__select'], | |
| 129 | + 'value', | |
| 130 | + 'text', | |
| 131 | + null, | |
| 132 | + false, | |
| 133 | + true | |
| 134 | + ); ?> | |
| 135 | + </div> | |
| 136 | + <input type="number" min="0" class="intext_input_automation cell" name="<?php echo esc_attr($fieldName.'[number]'); ?>"> | |
| 137 | + <div class="cell shrink acym__automation__inner__text"><?php echo esc_html(acym_translation('ACYM_ACYMAILING_USERS')); ?></div> | |
| 138 | + <?php | |
| 99 | 139 | } |
| 100 | 140 | |
| 101 | - public function onAcymDeclareConditionsScenario(array &$conditions): void | |
| 141 | + public function displayConditionOptions_acy_toss(string $fieldName): void | |
| 102 | 142 | { |
| 103 | - $this->onAcymDeclareConditions($conditions); | |
| 143 | + ?> | |
| 144 | + <input type="hidden" name="<?php echo esc_attr($fieldName.'[toss]'); ?>" value="true"> | |
| 145 | + <div class="acym__automation__inner__text"><?php echo esc_html(acym_translation('ACYM_TOSS_DESC')); ?></div> | |
| 146 | + <?php | |
| 104 | 147 | } |
| 105 | 148 | |
| 106 | 149 | public function onAcymProcessCondition_acy_toss(&$query, $option, $num, &$conditionNotValid) |
| 107 | 150 | { |
| 108 | - if (!mt_rand(0, 1)) $conditionNotValid++; | |
| 151 | + if (!acym_rand(0, 1)) $conditionNotValid++; | |
| 109 | 152 | } |
| 110 | 153 | |
| 111 | 154 | public function onAcymProcessCondition_acy_totaluser(&$query, $option, $num, &$conditionNotValid) |
| 112 | 155 | { |
| @@ -156,9 +199,9 @@ | ||
| 156 | 199 | $value = ' = '.intval($options['group']); |
| 157 | 200 | } else { |
| 158 | 201 | $lftrgt = acym_loadObject('SELECT lft, rgt FROM #__usergroups WHERE id = '.intval($options['group'])); |
| 159 | 202 | $allSubGroups = acym_loadResultArray('SELECT id FROM #__usergroups WHERE lft > '.intval($lftrgt->lft).' AND rgt < '.intval($lftrgt->rgt)); |
| 160 | - array_unshift($allSubGroups, $options['group']); | |
| 203 | + array_unshift($allSubGroups, intval($options['group'])); | |
| 161 | 204 | $value = ' IN ('.implode(', ', $allSubGroups).')'; |
| 162 | 205 | } |
| 163 | 206 | |
| 164 | 207 | $query->leftjoin['cmsuser'.$num] = '#__user_usergroup_map AS cmsuser'.$num.' |
| @@ -188,8 +231,9 @@ | ||
| 188 | 231 | if (empty($options['field'])) { |
| 189 | 232 | return; |
| 190 | 233 | } |
| 191 | 234 | |
| 235 | + // Handle custom fields | |
| 192 | 236 | if (strpos($options['field'], 'cf_') !== false) { |
| 193 | 237 | $cfId = substr($options['field'], 3); |
| 194 | 238 | $query->leftjoin['cmsuserfields'.$num] = '#__fields_values AS cmsuserfields'.$num.' ON cmsuserfields'.$num.'.item_id = user.cms_id AND cmsuserfields'.$num.'.field_id = '.intval( |
| 195 | 239 | $cfId |
| @@ -195,8 +239,9 @@ | ||
| 195 | 239 | $cfId |
| 196 | 240 | ); |
| 197 | 241 | $query->where[] = $query->convertQuery('cmsuserfields'.$num, 'value', $options['operator'], $options['value']); |
| 198 | 242 | } else { |
| 243 | + // Handle normal fields | |
| 199 | 244 | $type = ''; |
| 200 | 245 | $query->leftjoin['cmsuser'.$num] = '#__users AS cmsuser'.$num.' ON cmsuser'.$num.'.id = user.cms_id'; |
| 201 | 246 | |
| 202 | 247 | if (in_array($options['field'], ['registerDate', 'lastvisitDate', 'user_registered'])) { |
| @@ -206,9 +251,9 @@ | ||
| 206 | 251 | if (!is_numeric($options['value']) && strtotime($options['value']) !== false) { |
| 207 | 252 | $options['value'] = strtotime($options['value']); |
| 208 | 253 | } |
| 209 | 254 | if (is_numeric($options['value'])) { |
| 210 | - $options['value'] = date('Y-m-d H:i:s', $options['value']); | |
| 255 | + $options['value'] = gmdate('Y-m-d H:i:s', $options['value']); | |
| 211 | 256 | } |
| 212 | 257 | } |
| 213 | 258 | |
| 214 | 259 | $query->where[] = $query->convertQuery( |