← All changes
|
back/dynamics/subscriber/SubscriberAutomationConditions.php
+63
-53
11.0.2
→
11.1.0
View file →
| @@ -6,18 +6,54 @@ | ||
| 6 | 6 | use AcyMailing\Types\OperatorType; |
| 7 | 7 | |
| 8 | 8 | trait SubscriberAutomationConditions |
| 9 | 9 | { |
| 10 | - public function onAcymDeclareConditions(array &$conditions): void | |
| 10 | + protected function initAutomationConditions(): void | |
| 11 | 11 | { |
| 12 | + $this->automationConditions['user']['acy_field'] = acym_translation('ACYM_ACYMAILING_FIELD'); | |
| 13 | + } | |
| 14 | + | |
| 15 | + public function displayConditionOptions_acy_field(string $fieldName): void | |
| 16 | + { | |
| 12 | 17 | $userClass = new UserClass(); |
| 13 | - $fieldClass = new FieldClass(); | |
| 14 | 18 | $fields = $userClass->getAllColumnsUserAndCustomField(); |
| 15 | 19 | unset($fields['automation']); |
| 16 | 20 | |
| 17 | - $customFields = $fieldClass->getAllFieldsForUser(); | |
| 18 | - $customFieldValues = []; | |
| 19 | - foreach ($customFields as $field) { | |
| 21 | + $operator = new OperatorType(); | |
| 22 | + ?> | |
| 23 | + <div class="intext_select_automation cell"> | |
| 24 | + <?php acym_select( | |
| 25 | + $fields, | |
| 26 | + $fieldName.'[field]', | |
| 27 | + null, | |
| 28 | + ['class' => 'acym__select acym__automation__conditions__fields__dropdown'], | |
| 29 | + 'value', | |
| 30 | + 'text', | |
| 31 | + null, | |
| 32 | + false, | |
| 33 | + true | |
| 34 | + ); ?> | |
| 35 | + </div> | |
| 36 | + <div class="intext_select_automation cell"> | |
| 37 | + <?php $operator->display($fieldName.'[operator]', '', 'acym__automation__conditions__operator__dropdown', true); ?> | |
| 38 | + </div> | |
| 39 | + <input class="acym__automation__one-field intext_input_automation cell acym__automation__condition__regular-field" | |
| 40 | + type="text" | |
| 41 | + name="<?php echo esc_attr($fieldName.'[value]'); ?>"> | |
| 42 | + <?php | |
| 43 | + $this->displayCustomFieldValues($fieldName); | |
| 44 | + } | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * One hidden value field per custom field, shown by the JS when that field is selected | |
| 48 | + */ | |
| 49 | + private function displayCustomFieldValues(string $fieldName): void | |
| 50 | + { | |
| 51 | + // Declared without the prefix so they are not posted, the JS adds it back on the shown one | |
| 52 | + $valueFieldName = $this->getFieldNameWithoutPrefix($fieldName).'[value]'; | |
| 53 | + | |
| 54 | + $fieldClass = new FieldClass(); | |
| 55 | + foreach ($fieldClass->getAllFieldsForUser() as $field) { | |
| 20 | 56 | if (in_array($field->type, ['single_dropdown', 'radio', 'checkbox', 'multiple_dropdown']) && !empty($field->value)) { |
| 21 | 57 | $values = []; |
| 22 | 58 | $field->value = json_decode($field->value, true); |
| 23 | 59 | foreach ($field->value as $value) { |
| @@ -26,66 +62,40 @@ | ||
| 26 | 62 | $valueTmp->value = $value['value']; |
| 27 | 63 | if ($value['disabled'] == 'y') $valueTmp->disable = true; |
| 28 | 64 | $values[$value['value']] = $valueTmp; |
| 29 | 65 | } |
| 30 | - $customFieldValues[$field->id] = '<div class="acym__automation__one-field intext_select_automation cell" style="display: none">'; | |
| 31 | - $customFieldValues[$field->id] .= acym_select( | |
| 32 | - $values, | |
| 33 | - '[conditions][__numor__][__numand__][acy_field][value]', | |
| 34 | - null, | |
| 35 | - [ | |
| 36 | - 'class' => 'acym__select acym__automation__conditions__fields__select', | |
| 37 | - 'data-condition-field' => intval($field->id), | |
| 38 | - ] | |
| 39 | - ); | |
| 40 | - $customFieldValues[$field->id] .= '</div>'; | |
| 66 | + ?> | |
| 67 | + <div class="acym__automation__one-field intext_select_automation cell" style="display: none"> | |
| 68 | + <?php acym_select( | |
| 69 | + $values, | |
| 70 | + $valueFieldName, | |
| 71 | + null, | |
| 72 | + [ | |
| 73 | + 'class' => 'acym__select acym__automation__conditions__fields__select', | |
| 74 | + 'data-condition-field' => intval($field->id), | |
| 75 | + ], | |
| 76 | + 'value', | |
| 77 | + 'text', | |
| 78 | + null, | |
| 79 | + false, | |
| 80 | + true | |
| 81 | + ); ?> | |
| 82 | + </div> | |
| 83 | + <?php | |
| 41 | 84 | } elseif ('date' === $field->type) { |
| 42 | - ob_start(); | |
| 43 | 85 | acym_tooltip( |
| 44 | 86 | [ |
| 45 | - 'hoveredText' => '<input class="acym__automation__one-field acym__automation__conditions__fields__select intext_input_automation cell" | |
| 46 | - type="text" | |
| 47 | - name="[conditions][__numor__][__numand__][acy_field][value]" | |
| 48 | - style="display: none" | |
| 87 | + 'hoveredText' => '<input class="acym__automation__one-field acym__automation__conditions__fields__select intext_input_automation cell" | |
| 88 | + type="text" | |
| 89 | + name="'.esc_attr($valueFieldName).'" | |
| 90 | + style="display: none" | |
| 49 | 91 | data-condition-field="'.intval($field->id).'">', |
| 50 | 92 | 'textShownInTooltip' => acym_translation('ACYM_DATE_FORMAT_FILTER'), |
| 51 | 93 | 'classContainer' => 'intext_select_automation cell', |
| 52 | 94 | ] |
| 53 | 95 | ); |
| 54 | - $customFieldValues[$field->id] = ob_get_clean(); | |
| 55 | 96 | } |
| 56 | 97 | } |
| 57 | - | |
| 58 | - $conditions['user']['acy_field'] = new stdClass(); | |
| 59 | - $conditions['user']['acy_field']->name = acym_translation('ACYM_ACYMAILING_FIELD'); | |
| 60 | - | |
| 61 | - $conditions['user']['acy_field']->option = '<div class="intext_select_automation cell">'; | |
| 62 | - $conditions['user']['acy_field']->option .= acym_select( | |
| 63 | - $fields, | |
| 64 | - 'acym_condition[conditions][__numor__][__numand__][acy_field][field]', | |
| 65 | - null, | |
| 66 | - ['class' => 'acym__select acym__automation__conditions__fields__dropdown'] | |
| 67 | - ); | |
| 68 | - $conditions['user']['acy_field']->option .= '</div>'; | |
| 69 | - | |
| 70 | - $conditions['user']['acy_field']->option .= '<div class="intext_select_automation cell">'; | |
| 71 | - $operator = new OperatorType(); | |
| 72 | - $conditions['user']['acy_field']->option .= $operator->display( | |
| 73 | - 'acym_condition[conditions][__numor__][__numand__][acy_field][operator]', | |
| 74 | - '', | |
| 75 | - 'acym__automation__conditions__operator__dropdown' | |
| 76 | - ); | |
| 77 | - $conditions['user']['acy_field']->option .= '</div>'; | |
| 78 | - | |
| 79 | - $conditions['user']['acy_field']->option .= '<input class="acym__automation__one-field intext_input_automation cell acym__automation__condition__regular-field" | |
| 80 | - type="text" | |
| 81 | - name="acym_condition[conditions][__numor__][__numand__][acy_field][value]">'; | |
| 82 | - $conditions['user']['acy_field']->option .= implode(' ', $customFieldValues); | |
| 83 | - } | |
| 84 | - | |
| 85 | - public function onAcymDeclareConditionsScenario(array &$conditions): void | |
| 86 | - { | |
| 87 | - $this->onAcymDeclareConditions($conditions); | |
| 88 | 98 | } |
| 89 | 99 | |
| 90 | 100 | public function onAcymProcessCondition_acy_field(&$query, &$options, $num, &$conditionNotValid) |
| 91 | 101 | { |