← All changes
|
back/dynamics/subscriber/SubscriberAutomationConditions.php
+0
-159
11.0.2
→
11.1.1
View file →
| @@ -1,159 +1,0 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -use AcyMailing\Classes\UserClass; | |
| 4 | -use AcyMailing\Classes\FieldClass; | |
| 5 | -use AcyMailing\Helpers\AutomationHelper; | |
| 6 | -use AcyMailing\Types\OperatorType; | |
| 7 | - | |
| 8 | -trait SubscriberAutomationConditions | |
| 9 | -{ | |
| 10 | - public function onAcymDeclareConditions(array &$conditions): void | |
| 11 | - { | |
| 12 | - $userClass = new UserClass(); | |
| 13 | - $fieldClass = new FieldClass(); | |
| 14 | - $fields = $userClass->getAllColumnsUserAndCustomField(); | |
| 15 | - unset($fields['automation']); | |
| 16 | - | |
| 17 | - $customFields = $fieldClass->getAllFieldsForUser(); | |
| 18 | - $customFieldValues = []; | |
| 19 | - foreach ($customFields as $field) { | |
| 20 | - if (in_array($field->type, ['single_dropdown', 'radio', 'checkbox', 'multiple_dropdown']) && !empty($field->value)) { | |
| 21 | - $values = []; | |
| 22 | - $field->value = json_decode($field->value, true); | |
| 23 | - foreach ($field->value as $value) { | |
| 24 | - $valueTmp = new stdClass(); | |
| 25 | - $valueTmp->text = $value['title']; | |
| 26 | - $valueTmp->value = $value['value']; | |
| 27 | - if ($value['disabled'] == 'y') $valueTmp->disable = true; | |
| 28 | - $values[$value['value']] = $valueTmp; | |
| 29 | - } | |
| 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>'; | |
| 41 | - } elseif ('date' === $field->type) { | |
| 42 | - ob_start(); | |
| 43 | - acym_tooltip( | |
| 44 | - [ | |
| 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" | |
| 49 | - data-condition-field="'.intval($field->id).'">', | |
| 50 | - 'textShownInTooltip' => acym_translation('ACYM_DATE_FORMAT_FILTER'), | |
| 51 | - 'classContainer' => 'intext_select_automation cell', | |
| 52 | - ] | |
| 53 | - ); | |
| 54 | - $customFieldValues[$field->id] = ob_get_clean(); | |
| 55 | - } | |
| 56 | - } | |
| 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 | - } | |
| 89 | - | |
| 90 | - public function onAcymProcessCondition_acy_field(&$query, &$options, $num, &$conditionNotValid) | |
| 91 | - { | |
| 92 | - $affectedRows = $this->processAcyField($query, $options, $num); | |
| 93 | - if (empty($affectedRows)) $conditionNotValid++; | |
| 94 | - } | |
| 95 | - | |
| 96 | - public function onAcymDeclareSummary_conditions(&$automation) | |
| 97 | - { | |
| 98 | - $this->onAcymDeclareSummary_conditionsFilters($automation, 'ACYM_CONDITION_ACY_FIELD_SUMMARY'); | |
| 99 | - } | |
| 100 | - | |
| 101 | - private function processAcyField(&$query, &$options, $num) | |
| 102 | - { | |
| 103 | - $usersColumns = acym_getColumns('user'); | |
| 104 | - | |
| 105 | - if (!in_array($options['field'], $usersColumns)) { | |
| 106 | - $fieldClass = new FieldClass(); | |
| 107 | - $field = $fieldClass->getOneById($options['field']); | |
| 108 | - | |
| 109 | - $fieldType = empty($field->type) ? '' : $field->type; | |
| 110 | - | |
| 111 | - $query->leftjoin['userfield'.$num] = ' #__acym_user_has_field as userfield'.$num.' ON userfield'.$num.'.user_id = user.id AND userfield'.$num.'.field_id = '.intval( | |
| 112 | - $options['field'] | |
| 113 | - ); | |
| 114 | - $query->where[] = $query->convertQuery( | |
| 115 | - 'userfield'.$num, | |
| 116 | - 'value', | |
| 117 | - $options['operator'], | |
| 118 | - $options['value'], | |
| 119 | - 'phone' === $fieldType ? AutomationHelper::TYPE_PHONE : '' | |
| 120 | - ); | |
| 121 | - } else { | |
| 122 | - if (in_array($options['field'], ['creation_date', 'confirmation_date', 'last_sent_date', 'last_open_date', 'last_click_date', 'deactivation_date'])) { | |
| 123 | - $options['value'] = acym_replaceDate($options['value']); | |
| 124 | - if (!is_numeric($options['value'])) { | |
| 125 | - $options['value'] = strtotime($options['value']); | |
| 126 | - } | |
| 127 | - $options['value'] = acym_date($options['value'], 'Y-m-d H:i:s'); | |
| 128 | - } | |
| 129 | - $query->where[] = $query->convertQuery('user', $options['field'], $options['operator'], $options['value']); | |
| 130 | - } | |
| 131 | - | |
| 132 | - return $query->count(); | |
| 133 | - } | |
| 134 | - | |
| 135 | - private function onAcymDeclareSummary_conditionsFilters(&$automation, $key) | |
| 136 | - { | |
| 137 | - if (!empty($automation['acy_field'])) { | |
| 138 | - $usersColumns = acym_getColumns('user'); | |
| 139 | - | |
| 140 | - if (!in_array($automation['acy_field']['field'], $usersColumns)) { | |
| 141 | - $fieldClass = new FieldClass(); | |
| 142 | - $field = $fieldClass->getOneById($automation['acy_field']['field']); | |
| 143 | - $automation['acy_field']['field'] = $field->name; | |
| 144 | - } | |
| 145 | - | |
| 146 | - $automation = acym_translationSprintf( | |
| 147 | - $key, | |
| 148 | - $automation['acy_field']['field'], | |
| 149 | - $automation['acy_field']['operator'], | |
| 150 | - $automation['acy_field']['value'] | |
| 151 | - ); | |
| 152 | - } elseif (!empty($automation['random'])) { | |
| 153 | - $automation = acym_translationSprintf( | |
| 154 | - 'ACYM_RANDOMLY_SELECT_X_SUBSCRIBERS', | |
| 155 | - $automation['random']['number'] | |
| 156 | - ); | |
| 157 | - } | |
| 158 | - } | |
| 159 | -} | |