← All changes
|
back/dynamics/subscription/SubscriptionAutomationConditions.php
+109
-37
10.2.2
→
11.1.0
View file →
| @@ -3,18 +3,21 @@ | ||
| 3 | 3 | use AcyMailing\Classes\ListClass; |
| 4 | 4 | |
| 5 | 5 | trait SubscriptionAutomationConditions |
| 6 | 6 | { |
| 7 | - public function onAcymDeclareConditions(&$conditions) | |
| 7 | + public function onAcymDeclareConditions(array &$conditions): void | |
| 8 | 8 | { |
| 9 | 9 | $listClass = new ListClass(); |
| 10 | + $allLists = $listClass->getAllForSelect(false); | |
| 11 | + $listsWithAny = ['' => acym_translation('ACYM_ANY_LIST')] + $allLists; | |
| 10 | 12 | $list = [ |
| 11 | 13 | 'type' => [ |
| 12 | 14 | 'sub' => acym_translation('ACYM_SUBSCRIBED'), |
| 13 | 15 | 'unsub' => acym_translation('ACYM_UNSUBSCRIBED'), |
| 14 | 16 | 'notsub' => acym_translation('ACYM_NO_SUBSCRIPTION_STATUS'), |
| 17 | + 'notcurrentsub' => acym_translation('ACYM_NOT_CURRENTLY_SUBSCRIBED'), | |
| 15 | 18 | ], |
| 16 | - 'lists' => $listClass->getAllForSelect(), | |
| 19 | + 'lists' => $listsWithAny, | |
| 17 | 20 | 'date' => [ |
| 18 | 21 | 'subscription_date' => acym_translation('ACYM_SUBSCRIPTION_DATE'), |
| 19 | 22 | 'unsubscribe_date' => acym_translation('ACYM_UNSUBSCRIPTION_DATE'), |
| 20 | 23 | ], |
| @@ -21,12 +24,40 @@ | ||
| 21 | 24 | ]; |
| 22 | 25 | |
| 23 | 26 | $conditions['user']['acy_list'] = new stdClass(); |
| 24 | 27 | $conditions['user']['acy_list']->name = acym_translation('ACYM_ACYMAILING_LIST'); |
| 25 | - ob_start(); | |
| 26 | - include acym_getPartial('conditions', 'acy_list'); | |
| 27 | - $conditions['user']['acy_list']->option = ob_get_clean(); | |
| 28 | 28 | |
| 29 | + $conditions['user']['acy_list']->option = '<div class="intext_select_automation cell">'; | |
| 30 | + $conditions['user']['acy_list']->option .= acym_select( | |
| 31 | + $list['type'], | |
| 32 | + 'acym_condition[conditions][__numor__][__numand__][acy_list][action]', | |
| 33 | + null, | |
| 34 | + ['class' => 'intext_select_automation acym__select'] | |
| 35 | + ); | |
| 36 | + $conditions['user']['acy_list']->option .= '</div>'; | |
| 37 | + $conditions['user']['acy_list']->option .= '<div class="intext_select_automation cell">'; | |
| 38 | + $conditions['user']['acy_list']->option .= acym_select( | |
| 39 | + $list['lists'], | |
| 40 | + 'acym_condition[conditions][__numor__][__numand__][acy_list][list]', | |
| 41 | + null, | |
| 42 | + ['class' => 'intext_select_automation acym__select'] | |
| 43 | + ); | |
| 44 | + $conditions['user']['acy_list']->option .= '</div><br>'; | |
| 45 | + $conditions['user']['acy_list']->option .= '<div class="cell grid-x grid-margin-x">'; | |
| 46 | + $conditions['user']['acy_list']->option .= acym_dateField('acym_condition[conditions][__numor__][__numand__][acy_list][date-min]'); | |
| 47 | + $conditions['user']['acy_list']->option .= '<span class="acym__title acym__title__secondary acym_vcenter margin-bottom-0 margin-left-1 margin-right-1"><</span>'; | |
| 48 | + $conditions['user']['acy_list']->option .= '<div class="intext_select_automation">'; | |
| 49 | + $conditions['user']['acy_list']->option .= acym_select( | |
| 50 | + $list['date'], | |
| 51 | + 'acym_condition[conditions][__numor__][__numand__][acy_list][date-type]', | |
| 52 | + null, | |
| 53 | + ['class' => 'intext_select_automation acym__select cell'] | |
| 54 | + ); | |
| 55 | + $conditions['user']['acy_list']->option .= '</div>'; | |
| 56 | + $conditions['user']['acy_list']->option .= '<span class="acym__title acym__title__secondary acym_vcenter margin-bottom-0 margin-left-1 margin-right-1"><</span>'; | |
| 57 | + $conditions['user']['acy_list']->option .= acym_dateField('acym_condition[conditions][__numor__][__numand__][acy_list][date-max]'); | |
| 58 | + $conditions['user']['acy_list']->option .= '</div>'; | |
| 59 | + | |
| 29 | 60 | $conditions['classic']['acy_list_all'] = new stdClass(); |
| 30 | 61 | $conditions['classic']['acy_list_all']->name = acym_translation('ACYM_NUMBER_USERS_LIST'); |
| 31 | 62 | $conditions['classic']['acy_list_all']->option = '<div class="cell shrink acym__automation__inner__text">'.acym_translation('ACYM_THERE_IS').'</div>'; |
| 32 | 63 | $conditions['classic']['acy_list_all']->option .= '<div class="intext_select_automation cell">'; |
| @@ -38,11 +69,16 @@ | ||
| 38 | 69 | ); |
| 39 | 70 | $conditions['classic']['acy_list_all']->option .= '</div>'; |
| 40 | 71 | $conditions['classic']['acy_list_all']->option .= '<input type="number" min="0" class="intext_input_automation cell" name="acym_condition[conditions][__numor__][__numand__][acy_list_all][number]">'; |
| 41 | 72 | $conditions['classic']['acy_list_all']->option .= '<div class="cell shrink acym__automation__inner__text">'.acym_translation('ACYM_ACYMAILING_USERS').'</div>'; |
| 42 | - $conditions['classic']['acy_list_all']->option .= '<div class="cell grid-x grid-margin-x margin-left-0" style="margin-bottom: 0"><div class="intext_select_automation cell">'; | |
| 73 | + $listTypeAll = [ | |
| 74 | + 'sub' => acym_translation('ACYM_SUBSCRIBED'), | |
| 75 | + 'unsub' => acym_translation('ACYM_UNSUBSCRIBED'), | |
| 76 | + 'notsub' => acym_translation('ACYM_NO_SUBSCRIPTION_STATUS'), | |
| 77 | + ]; | |
| 78 | + $conditions['classic']['acy_list_all']->option .= '<div class="cell grid-x grid-margin-x margin-left-0 margin-right-0"><div class="intext_select_automation cell">'; | |
| 43 | 79 | $conditions['classic']['acy_list_all']->option .= acym_select( |
| 44 | - $list['type'], | |
| 80 | + $listTypeAll, | |
| 45 | 81 | 'acym_condition[conditions][__numor__][__numand__][acy_list_all][action]', |
| 46 | 82 | null, |
| 47 | 83 | ['class' => 'intext_select_automation acym__select'] |
| 48 | 84 | ); |
| @@ -69,14 +105,17 @@ | ||
| 69 | 105 | $conditions['classic']['acy_list_all']->option .= '<span class="acym__title acym__title__secondary acym_vcenter margin-bottom-0 margin-left-1 margin-right-1"><</span>'; |
| 70 | 106 | $conditions['classic']['acy_list_all']->option .= acym_dateField('acym_condition[conditions][__numor__][__numand__][acy_list_all][date-max]'); |
| 71 | 107 | } |
| 72 | 108 | |
| 73 | - public function onAcymDeclareConditionsScenario(&$conditions){ | |
| 109 | + public function onAcymDeclareConditionsScenario(array &$conditions): void | |
| 110 | + { | |
| 74 | 111 | $this->onAcymDeclareConditions($conditions); |
| 75 | 112 | } |
| 76 | 113 | |
| 77 | - private function _processConditionAcyLists(&$query, &$options, $num) | |
| 114 | + private function processConditionAcyLists(&$query, &$options, $num) | |
| 78 | 115 | { |
| 116 | + $isAnyList = empty($options['list']); | |
| 117 | + | |
| 79 | 118 | $otherConditions = ''; |
| 80 | 119 | if (!empty($options['date-min'])) { |
| 81 | 120 | $options['date-min'] = acym_replaceDate($options['date-min']); |
| 82 | 121 | if (!is_numeric($options['date-min'])) { |
| @@ -95,16 +134,35 @@ | ||
| 95 | 134 | $otherConditions .= ' AND userlist'.$num.'.'.acym_secureDBColumn($options['date-type']).' < '.acym_escapeDB(acym_date($options['date-max'], 'Y-m-d H:i:s', false)); |
| 96 | 135 | } |
| 97 | 136 | } |
| 98 | 137 | |
| 99 | - $query->leftjoin['list'.$num] = '#__acym_user_has_list as userlist'.$num.' ON user.id = userlist'.$num.'.user_id AND userlist'.$num.'.list_id = '.intval( | |
| 100 | - $options['list'] | |
| 101 | - ).$otherConditions; | |
| 102 | - if ($options['action'] == 'notsub') { | |
| 103 | - $query->where[] = 'userlist'.$num.'.user_id IS NULL'; | |
| 138 | + if ($isAnyList) { | |
| 139 | + $standardListType = acym_escapeDB(ListClass::LIST_TYPE_STANDARD); | |
| 140 | + | |
| 141 | + if (in_array($options['action'], ['notsub', 'notcurrentsub'])) { | |
| 142 | + $statusCondition = $options['action'] == 'notcurrentsub' ? 'userlist.status = 1 AND ' : ''; | |
| 143 | + $subquery = 'SELECT userlist.user_id FROM #__acym_user_has_list AS userlist | |
| 144 | + INNER JOIN #__acym_list AS list ON userlist.list_id = list.id | |
| 145 | + WHERE '.$statusCondition.'list.type = '.$standardListType; | |
| 146 | + $query->where[] = 'user.id NOT IN ('.$subquery.')'; | |
| 147 | + } else { | |
| 148 | + $status = $options['action'] === 'sub' ? '1' : '0'; | |
| 149 | + $query->join['list'.$num] = '#__acym_user_has_list AS userlist'.$num.' ON user.id = userlist'.$num.'.user_id AND userlist'.$num.'.status = '.$status.$otherConditions; | |
| 150 | + $query->join['listtype'.$num] = '#__acym_list AS list'.$num.' ON userlist'.$num.'.list_id = list'.$num.'.id AND list'.$num.'.type = '.$standardListType; | |
| 151 | + } | |
| 104 | 152 | } else { |
| 105 | - $status = $options['action'] == 'sub' ? '1' : '0'; | |
| 106 | - $query->where[] = 'userlist'.$num.'.status = '.intval($status); | |
| 153 | + // specific list | |
| 154 | + $query->leftjoin['list'.$num] = '#__acym_user_has_list AS userlist'.$num.' ON user.id = userlist'.$num.'.user_id AND userlist'.$num.'.list_id = '.intval( | |
| 155 | + $options['list'] | |
| 156 | + ).$otherConditions; | |
| 157 | + if ($options['action'] == 'notsub') { | |
| 158 | + $query->where[] = 'userlist'.$num.'.user_id IS NULL'; | |
| 159 | + } elseif ($options['action'] === 'notcurrentsub') { | |
| 160 | + $query->where[] = '(userlist'.$num.'.user_id IS NULL OR userlist'.$num.'.status = 0)'; | |
| 161 | + } else { | |
| 162 | + $status = $options['action'] == 'sub' ? '1' : '0'; | |
| 163 | + $query->where[] = 'userlist'.$num.'.status = '.intval($status); | |
| 164 | + } | |
| 107 | 165 | } |
| 108 | 166 | |
| 109 | 167 | return $query->count(); |
| 110 | 168 | } |
| @@ -110,25 +168,25 @@ | ||
| 110 | 168 | } |
| 111 | 169 | |
| 112 | 170 | public function onAcymProcessCondition_acy_list(&$query, &$options, $num, &$conditionNotValid) |
| 113 | 171 | { |
| 114 | - $affectedRows = $this->_processConditionAcyLists($query, $options, $num); | |
| 172 | + $affectedRows = $this->processConditionAcyLists($query, $options, $num); | |
| 115 | 173 | if (empty($affectedRows)) $conditionNotValid++; |
| 116 | 174 | } |
| 117 | 175 | |
| 118 | 176 | public function onAcymProcessCondition_acy_list_all(&$query, &$options, $num, &$conditionNotValid) |
| 119 | 177 | { |
| 120 | - $affectedRows = $this->_processConditionAcyLists($query, $options, $num); | |
| 178 | + $affectedRows = $this->processConditionAcyLists($query, $options, $num); | |
| 121 | 179 | |
| 122 | 180 | $res = false; |
| 123 | 181 | switch ($options['operator']) { |
| 124 | - case '=' : | |
| 182 | + case '=': | |
| 125 | 183 | $res = $affectedRows == $options['number']; |
| 126 | 184 | break; |
| 127 | - case '>' : | |
| 185 | + case '>': | |
| 128 | 186 | $res = $affectedRows > $options['number']; |
| 129 | 187 | break; |
| 130 | - case '<' : | |
| 188 | + case '<': | |
| 131 | 189 | $res = $affectedRows < $options['number']; |
| 132 | 190 | break; |
| 133 | 191 | } |
| 134 | 192 | |
| @@ -144,9 +202,9 @@ | ||
| 144 | 202 | $finalText = acym_translation('ACYM_THERE_IS').' '.acym_strtolower( |
| 145 | 203 | $operators[$automation['acy_list_all']['operator']] |
| 146 | 204 | ).' '.$automation['acy_list_all']['number'].' '.acym_translation('ACYM_ACYMAILING_USERS').' '; |
| 147 | 205 | $listClass = new ListClass(); |
| 148 | - $automation['acy_list_all']['list'] = $listClass->getOneById($automation['acy_list_all']['list']); | |
| 206 | + $automation['acy_list_all']['list'] = $listClass->getOneById($automation['acy_list_all']['list'] ? : 0); | |
| 149 | 207 | if (empty($automation['acy_list_all']['list'])) { |
| 150 | 208 | $automation = '<span class="acym__color__red">'.acym_translation('ACYM_SELECT_A_LIST').'</span>'; |
| 151 | 209 | |
| 152 | 210 | return; |
| @@ -159,35 +217,49 @@ | ||
| 159 | 217 | acym_translation($automation['acy_list_all']['action']), |
| 160 | 218 | $automation['acy_list_all']['list']->name |
| 161 | 219 | ).' '; |
| 162 | 220 | |
| 163 | - $automation = $this->_summaryDate($automation['acy_list_all'], $finalText); | |
| 221 | + $automation = $this->summaryDate($automation['acy_list_all'], $finalText); | |
| 164 | 222 | } |
| 165 | 223 | |
| 166 | - $this->onAcymDeclareSummary_conditionsFilters($automation, 'ACYM_CONDITION_ACY_LIST_SUMMARY', 'ACYM_IS_SUBSCRIBED', 'ACYM_IS_UNSUBSCRIBED', 'ACYM_IS_NOT_SUBSCRIBED'); | |
| 224 | + $this->onAcymDeclareSummary_conditionsFilters( | |
| 225 | + $automation, | |
| 226 | + 'ACYM_CONDITION_ACY_LIST_SUMMARY', | |
| 227 | + 'ACYM_IS_SUBSCRIBED', | |
| 228 | + 'ACYM_IS_UNSUBSCRIBED', | |
| 229 | + 'ACYM_IS_NOT_SUBSCRIBED', | |
| 230 | + 'ACYM_IS_NOT_CURRENTLY_SUBSCRIBED' | |
| 231 | + ); | |
| 167 | 232 | } |
| 168 | 233 | |
| 169 | - private function onAcymDeclareSummary_conditionsFilters(&$automation, $key, $keySub, $keyUnsub, $keyNotSub) | |
| 170 | - { | |
| 234 | + private function onAcymDeclareSummary_conditionsFilters( | |
| 235 | + &$automation, | |
| 236 | + string $key, | |
| 237 | + string $keySub, | |
| 238 | + string $keyUnsub, | |
| 239 | + string $keyNotSub, | |
| 240 | + string $keyNotCurrentSub | |
| 241 | + ): void { | |
| 171 | 242 | if (!empty($automation['acy_list'])) { |
| 172 | 243 | $finalText = ''; |
| 173 | 244 | $listClass = new ListClass(); |
| 174 | - $automation['acy_list']['list'] = $listClass->getOneById($automation['acy_list']['list']); | |
| 175 | - if (empty($automation['acy_list']['list'])) { | |
| 176 | - $automation = '<span class="acym__color__red">'.acym_translation('ACYM_SELECT_A_LIST').'</span>'; | |
| 245 | + $automation['acy_list']['list'] = $listClass->getOneById($automation['acy_list']['list'] ? : 0); | |
| 177 | 246 | |
| 178 | - return; | |
| 179 | - } | |
| 180 | - if ($automation['acy_list']['action'] == 'sub') $automation['acy_list']['action'] = $keySub; | |
| 181 | - if ($automation['acy_list']['action'] == 'unsub') $automation['acy_list']['action'] = $keyUnsub; | |
| 182 | - if ($automation['acy_list']['action'] == 'notsub') $automation['acy_list']['action'] = $keyNotSub; | |
| 247 | + $listName = empty($automation['acy_list']['list']) | |
| 248 | + ? acym_translation('ACYM_ANY_LIST') | |
| 249 | + : $automation['acy_list']['list']->name; | |
| 250 | + | |
| 251 | + if ($automation['acy_list']['action'] === 'sub') $automation['acy_list']['action'] = $keySub; | |
| 252 | + if ($automation['acy_list']['action'] === 'unsub') $automation['acy_list']['action'] = $keyUnsub; | |
| 253 | + if ($automation['acy_list']['action'] === 'notsub') $automation['acy_list']['action'] = $keyNotSub; | |
| 254 | + if ($automation['acy_list']['action'] === 'notcurrentsub') $automation['acy_list']['action'] = $keyNotCurrentSub; | |
| 183 | 255 | $finalText .= acym_translationSprintf( |
| 184 | 256 | $key, |
| 185 | 257 | acym_translation($automation['acy_list']['action']), |
| 186 | - $automation['acy_list']['list']->name | |
| 258 | + $listName | |
| 187 | 259 | ).' '; |
| 188 | 260 | |
| 189 | - $automation = $this->_summaryDate($automation['acy_list'], $finalText); | |
| 261 | + $automation = $this->summaryDate($automation['acy_list'], $finalText); | |
| 190 | 262 | } |
| 191 | 263 | |
| 192 | 264 | if (!empty($automation['unconfirmed'])) { |
| 193 | 265 | $automation = acym_translation('ACYM_ACTION_UNCONFIRM'); |
| @@ -193,9 +265,9 @@ | ||
| 193 | 265 | $automation = acym_translation('ACYM_ACTION_UNCONFIRM'); |
| 194 | 266 | } |
| 195 | 267 | } |
| 196 | 268 | |
| 197 | - private function _summaryDate($automation, $finalText) | |
| 269 | + private function summaryDate($automation, $finalText) | |
| 198 | 270 | { |
| 199 | 271 | if (!empty($automation['date-min']) || !empty($automation['date-max'])) { |
| 200 | 272 | $finalText .= acym_translationSprintf('ACYM_WHERE_DATE_ACY_LIST_SUMMARY', acym_strtolower(acym_translation('ACYM_'.strtoupper($automation['date-type'])))); |
| 201 | 273 | |