← All changes
|
back/dynamics/subscriber/SubscriberAutomationConditions.php
+0
-137
10.2.2
→
11.1.1
View file →
| @@ -1,137 +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 | - private function onAcymDeclareSummary_conditionsFilters(&$automation, $key) | |
| 11 | - { | |
| 12 | - if (!empty($automation['acy_field'])) { | |
| 13 | - $usersColumns = acym_getColumns('user'); | |
| 14 | - | |
| 15 | - if (!in_array($automation['acy_field']['field'], $usersColumns)) { | |
| 16 | - $fieldClass = new FieldClass(); | |
| 17 | - $field = $fieldClass->getOneById($automation['acy_field']['field']); | |
| 18 | - $automation['acy_field']['field'] = $field->name; | |
| 19 | - } | |
| 20 | - | |
| 21 | - $automation = acym_translationSprintf( | |
| 22 | - $key, | |
| 23 | - $automation['acy_field']['field'], | |
| 24 | - $automation['acy_field']['operator'], | |
| 25 | - $automation['acy_field']['value'] | |
| 26 | - ); | |
| 27 | - } elseif (!empty($automation['random'])) { | |
| 28 | - $automation = acym_translationSprintf( | |
| 29 | - 'ACYM_RANDOMLY_SELECT_X_SUBSCRIBERS', | |
| 30 | - $automation['random']['number'] | |
| 31 | - ); | |
| 32 | - } | |
| 33 | - } | |
| 34 | - | |
| 35 | - public function onAcymDeclareConditions(&$conditions) | |
| 36 | - { | |
| 37 | - $userClass = new UserClass(); | |
| 38 | - $fieldClass = new FieldClass(); | |
| 39 | - $fields = $userClass->getAllColumnsUserAndCustomField(); | |
| 40 | - unset($fields['automation']); | |
| 41 | - | |
| 42 | - $customFields = $fieldClass->getAllFieldsForUser(); | |
| 43 | - $customFieldValues = []; | |
| 44 | - foreach ($customFields as $field) { | |
| 45 | - if (in_array($field->type, ['single_dropdown', 'radio', 'checkbox', 'multiple_dropdown']) && !empty($field->value)) { | |
| 46 | - $values = []; | |
| 47 | - $field->value = json_decode($field->value, true); | |
| 48 | - foreach ($field->value as $value) { | |
| 49 | - $valueTmp = new stdClass(); | |
| 50 | - $valueTmp->text = $value['title']; | |
| 51 | - $valueTmp->value = $value['value']; | |
| 52 | - if ($value['disabled'] == 'y') $valueTmp->disable = true; | |
| 53 | - $values[$value['value']] = $valueTmp; | |
| 54 | - } | |
| 55 | - $customFieldValues[$field->id] = '<div class="acym__automation__one-field intext_select_automation cell" style="display: none">'; | |
| 56 | - $customFieldValues[$field->id] .= acym_select( | |
| 57 | - $values, | |
| 58 | - '[conditions][__numor__][__numand__][acy_field][value]', | |
| 59 | - null, | |
| 60 | - [ | |
| 61 | - 'class' => 'acym__select acym__automation__conditions__fields__select', | |
| 62 | - 'data-condition-field' => intval($field->id), | |
| 63 | - ] | |
| 64 | - ); | |
| 65 | - $customFieldValues[$field->id] .= '</div>'; | |
| 66 | - } elseif ('date' == $field->type) { | |
| 67 | - $field->option = json_decode($field->option, true); | |
| 68 | - $customFieldValues[$field->id] = acym_tooltip( | |
| 69 | - [ | |
| 70 | - 'hoveredText' => '<input class="acym__automation__one-field acym__automation__conditions__fields__select intext_input_automation cell" type="text" name="[conditions][__numor__][__numand__][acy_field][value]" style="display: none" data-condition-field="'.intval( | |
| 71 | - $field->id | |
| 72 | - ).'">', | |
| 73 | - 'textShownInTooltip' => acym_translationSprintf('ACYM_DATE_AUTOMATION_INPUT', $field->option['format']), | |
| 74 | - 'classContainer' => 'intext_select_automation cell', | |
| 75 | - ] | |
| 76 | - ); | |
| 77 | - } | |
| 78 | - } | |
| 79 | - $operator = new OperatorType(); | |
| 80 | - | |
| 81 | - $conditions['user']['acy_field'] = new stdClass(); | |
| 82 | - $conditions['user']['acy_field']->name = acym_translation('ACYM_ACYMAILING_FIELD'); | |
| 83 | - ob_start(); | |
| 84 | - include acym_getPartial('conditions', 'acy_field'); | |
| 85 | - $conditions['user']['acy_field']->option = ob_get_clean(); | |
| 86 | - } | |
| 87 | - | |
| 88 | - public function onAcymDeclareConditionsScenario(&$conditions) | |
| 89 | - { | |
| 90 | - $this->onAcymDeclareConditions($conditions); | |
| 91 | - } | |
| 92 | - | |
| 93 | - public function onAcymProcessCondition_acy_field(&$query, &$options, $num, &$conditionNotValid) | |
| 94 | - { | |
| 95 | - $affectedRows = $this->_processAcyField($query, $options, $num); | |
| 96 | - if (empty($affectedRows)) $conditionNotValid++; | |
| 97 | - } | |
| 98 | - | |
| 99 | - public function onAcymDeclareSummary_conditions(&$automation) | |
| 100 | - { | |
| 101 | - $this->onAcymDeclareSummary_conditionsFilters($automation, 'ACYM_CONDITION_ACY_FIELD_SUMMARY'); | |
| 102 | - } | |
| 103 | - | |
| 104 | - private function _processAcyField(&$query, &$options, $num) | |
| 105 | - { | |
| 106 | - $usersColumns = acym_getColumns('user'); | |
| 107 | - | |
| 108 | - if (!in_array($options['field'], $usersColumns)) { | |
| 109 | - $fieldClass = new FieldClass(); | |
| 110 | - $field = $fieldClass->getOneById($options['field']); | |
| 111 | - | |
| 112 | - $fieldType = empty($field->type) ? '' : $field->type; | |
| 113 | - | |
| 114 | - $query->leftjoin['userfield'.$num] = ' #__acym_user_has_field as userfield'.$num.' ON userfield'.$num.'.user_id = user.id AND userfield'.$num.'.field_id = '.intval( | |
| 115 | - $options['field'] | |
| 116 | - ); | |
| 117 | - $query->where[] = $query->convertQuery( | |
| 118 | - 'userfield'.$num, | |
| 119 | - 'value', | |
| 120 | - $options['operator'], | |
| 121 | - $options['value'], | |
| 122 | - 'phone' === $fieldType ? AutomationHelper::TYPE_PHONE : '' | |
| 123 | - ); | |
| 124 | - } else { | |
| 125 | - if (in_array($options['field'], ['creation_date', 'confirmation_date', 'last_sent_date', 'last_open_date', 'last_click_date'])) { | |
| 126 | - $options['value'] = acym_replaceDate($options['value']); | |
| 127 | - if (!is_numeric($options['value'])) { | |
| 128 | - $options['value'] = strtotime($options['value']); | |
| 129 | - } | |
| 130 | - $options['value'] = acym_date($options['value'], 'Y-m-d H:i:s'); | |
| 131 | - } | |
| 132 | - $query->where[] = $query->convertQuery('user', $options['field'], $options['operator'], $options['value']); | |
| 133 | - } | |
| 134 | - | |
| 135 | - return $query->count(); | |
| 136 | - } | |
| 137 | -} | |