| 1 |
<?php |
| 2 |
|
| 3 |
use AcyMailing\Classes\ListClass; |
| 4 |
|
| 5 |
trait SubscriptionAutomationConditions |
| 6 |
{ |
| 7 |
public function onAcymDeclareConditions(&$conditions) |
| 8 |
{ |
| 9 |
$listClass = new ListClass(); |
| 10 |
$list = [ |
| 11 |
'type' => [ |
| 12 |
'sub' => acym_translation('ACYM_SUBSCRIBED'), |
| 13 |
'unsub' => acym_translation('ACYM_UNSUBSCRIBED'), |
| 14 |
'notsub' => acym_translation('ACYM_NO_SUBSCRIPTION_STATUS'), |
| 15 |
], |
| 16 |
'lists' => $listClass->getAllForSelect(), |
| 17 |
'date' => [ |
| 18 |
'subscription_date' => acym_translation('ACYM_SUBSCRIPTION_DATE'), |
| 19 |
'unsubscribe_date' => acym_translation('ACYM_UNSUBSCRIPTION_DATE'), |
| 20 |
], |
| 21 |
]; |
| 22 |
|
| 23 |
$conditions['user']['acy_list'] = new stdClass(); |
| 24 |
$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 |
|
| 29 |
$conditions['classic']['acy_list_all'] = new stdClass(); |
| 30 |
$conditions['classic']['acy_list_all']->name = acym_translation('ACYM_NUMBER_USERS_LIST'); |
| 31 |
$conditions['classic']['acy_list_all']->option = '<div class="cell shrink acym__automation__inner__text">'.acym_translation('ACYM_THERE_IS').'</div>'; |
| 32 |
$conditions['classic']['acy_list_all']->option .= '<div class="intext_select_automation cell">'; |
| 33 |
$conditions['classic']['acy_list_all']->option .= acym_select( |
| 34 |
['>' => acym_translation('ACYM_MORE_THAN'), '<' => acym_translation('ACYM_LESS_THAN'), '=' => acym_translation('ACYM_EXACTLY')], |
| 35 |
'acym_condition[conditions][__numor__][__numand__][acy_list_all][operator]', |
| 36 |
null, |
| 37 |
['class' => 'intext_select_automation acym__select'] |
| 38 |
); |
| 39 |
$conditions['classic']['acy_list_all']->option .= '</div>'; |
| 40 |
$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 |
$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">'; |
| 43 |
$conditions['classic']['acy_list_all']->option .= acym_select( |
| 44 |
$list['type'], |
| 45 |
'acym_condition[conditions][__numor__][__numand__][acy_list_all][action]', |
| 46 |
null, |
| 47 |
['class' => 'intext_select_automation acym__select'] |
| 48 |
); |
| 49 |
$conditions['classic']['acy_list_all']->option .= '</div>'; |
| 50 |
$conditions['classic']['acy_list_all']->option .= '<div class="intext_select_automation cell">'; |
| 51 |
$conditions['classic']['acy_list_all']->option .= acym_select( |
| 52 |
$list['lists'], |
| 53 |
'acym_condition[conditions][__numor__][__numand__][acy_list_all][list]', |
| 54 |
null, |
| 55 |
['class' => 'intext_select_automation acym__select'] |
| 56 |
); |
| 57 |
$conditions['classic']['acy_list_all']->option .= '</div></div>'; |
| 58 |
$conditions['classic']['acy_list_all']->option .= '<br><div class="cell grid-x grid-margin-x">'; |
| 59 |
$conditions['classic']['acy_list_all']->option .= acym_dateField('acym_condition[conditions][__numor__][__numand__][acy_list_all][date-min]'); |
| 60 |
$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>'; |
| 61 |
$conditions['classic']['acy_list_all']->option .= '<div class="intext_select_automation">'; |
| 62 |
$conditions['classic']['acy_list_all']->option .= acym_select( |
| 63 |
$list['date'], |
| 64 |
'acym_condition[conditions][__numor__][__numand__][acy_list_all][date-type]', |
| 65 |
null, |
| 66 |
['class' => 'intext_select_automation acym__select cell'] |
| 67 |
); |
| 68 |
$conditions['classic']['acy_list_all']->option .= '</div>'; |
| 69 |
$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 |
$conditions['classic']['acy_list_all']->option .= acym_dateField('acym_condition[conditions][__numor__][__numand__][acy_list_all][date-max]'); |
| 71 |
} |
| 72 |
|
| 73 |
public function onAcymDeclareConditionsScenario(&$conditions){ |
| 74 |
$this->onAcymDeclareConditions($conditions); |
| 75 |
} |
| 76 |
|
| 77 |
private function _processConditionAcyLists(&$query, &$options, $num) |
| 78 |
{ |
| 79 |
$otherConditions = ''; |
| 80 |
if (!empty($options['date-min'])) { |
| 81 |
$options['date-min'] = acym_replaceDate($options['date-min']); |
| 82 |
if (!is_numeric($options['date-min'])) { |
| 83 |
$options['date-min'] = strtotime($options['date-min']); |
| 84 |
} |
| 85 |
if (!empty($options['date-min'])) { |
| 86 |
$otherConditions .= ' AND userlist'.$num.'.'.acym_secureDBColumn($options['date-type']).' > '.acym_escapeDB(acym_date($options['date-min'], 'Y-m-d H:i:s', false)); |
| 87 |
} |
| 88 |
} |
| 89 |
if (!empty($options['date-max'])) { |
| 90 |
$options['date-max'] = acym_replaceDate($options['date-max']); |
| 91 |
if (!is_numeric($options['date-max'])) { |
| 92 |
$options['date-max'] = strtotime($options['date-max']); |
| 93 |
} |
| 94 |
if (!empty($options['date-max'])) { |
| 95 |
$otherConditions .= ' AND userlist'.$num.'.'.acym_secureDBColumn($options['date-type']).' < '.acym_escapeDB(acym_date($options['date-max'], 'Y-m-d H:i:s', false)); |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 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'; |
| 104 |
} else { |
| 105 |
$status = $options['action'] == 'sub' ? '1' : '0'; |
| 106 |
$query->where[] = 'userlist'.$num.'.status = '.intval($status); |
| 107 |
} |
| 108 |
|
| 109 |
return $query->count(); |
| 110 |
} |
| 111 |
|
| 112 |
public function onAcymProcessCondition_acy_list(&$query, &$options, $num, &$conditionNotValid) |
| 113 |
{ |
| 114 |
$affectedRows = $this->_processConditionAcyLists($query, $options, $num); |
| 115 |
if (empty($affectedRows)) $conditionNotValid++; |
| 116 |
} |
| 117 |
|
| 118 |
public function onAcymProcessCondition_acy_list_all(&$query, &$options, $num, &$conditionNotValid) |
| 119 |
{ |
| 120 |
$affectedRows = $this->_processConditionAcyLists($query, $options, $num); |
| 121 |
|
| 122 |
$res = false; |
| 123 |
switch ($options['operator']) { |
| 124 |
case '=' : |
| 125 |
$res = $affectedRows == $options['number']; |
| 126 |
break; |
| 127 |
case '>' : |
| 128 |
$res = $affectedRows > $options['number']; |
| 129 |
break; |
| 130 |
case '<' : |
| 131 |
$res = $affectedRows < $options['number']; |
| 132 |
break; |
| 133 |
} |
| 134 |
|
| 135 |
if (!$res) { |
| 136 |
$conditionNotValid++; |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
public function onAcymDeclareSummary_conditions(&$automation) |
| 141 |
{ |
| 142 |
if (!empty($automation['acy_list_all'])) { |
| 143 |
$operators = ['=' => acym_translation('ACYM_EXACTLY'), '>' => acym_translation('ACYM_MORE_THAN'), '<' => acym_translation('ACYM_LESS_THAN')]; |
| 144 |
$finalText = acym_translation('ACYM_THERE_IS').' '.acym_strtolower( |
| 145 |
$operators[$automation['acy_list_all']['operator']] |
| 146 |
).' '.$automation['acy_list_all']['number'].' '.acym_translation('ACYM_ACYMAILING_USERS').' '; |
| 147 |
$listClass = new ListClass(); |
| 148 |
$automation['acy_list_all']['list'] = $listClass->getOneById($automation['acy_list_all']['list']); |
| 149 |
if (empty($automation['acy_list_all']['list'])) { |
| 150 |
$automation = '<span class="acym__color__red">'.acym_translation('ACYM_SELECT_A_LIST').'</span>'; |
| 151 |
|
| 152 |
return; |
| 153 |
} |
| 154 |
if ($automation['acy_list_all']['action'] == 'sub') $automation['acy_list_all']['action'] = 'ACYM_SUBSCRIBED'; |
| 155 |
if ($automation['acy_list_all']['action'] == 'unsub') $automation['acy_list_all']['action'] = 'ACYM_UNSUBSCRIBED'; |
| 156 |
if ($automation['acy_list_all']['action'] == 'notsub') $automation['acy_list_all']['action'] = 'ACYM__NOT_SUBSCRIBED'; |
| 157 |
$finalText .= acym_translationSprintf( |
| 158 |
'ACYM_CONDITION_ACY_LIST_SUMMARY', |
| 159 |
acym_translation($automation['acy_list_all']['action']), |
| 160 |
$automation['acy_list_all']['list']->name |
| 161 |
).' '; |
| 162 |
|
| 163 |
$automation = $this->_summaryDate($automation['acy_list_all'], $finalText); |
| 164 |
} |
| 165 |
|
| 166 |
$this->onAcymDeclareSummary_conditionsFilters($automation, 'ACYM_CONDITION_ACY_LIST_SUMMARY', 'ACYM_IS_SUBSCRIBED', 'ACYM_IS_UNSUBSCRIBED', 'ACYM_IS_NOT_SUBSCRIBED'); |
| 167 |
} |
| 168 |
|
| 169 |
private function onAcymDeclareSummary_conditionsFilters(&$automation, $key, $keySub, $keyUnsub, $keyNotSub) |
| 170 |
{ |
| 171 |
if (!empty($automation['acy_list'])) { |
| 172 |
$finalText = ''; |
| 173 |
$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>'; |
| 177 |
|
| 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; |
| 183 |
$finalText .= acym_translationSprintf( |
| 184 |
$key, |
| 185 |
acym_translation($automation['acy_list']['action']), |
| 186 |
$automation['acy_list']['list']->name |
| 187 |
).' '; |
| 188 |
|
| 189 |
$automation = $this->_summaryDate($automation['acy_list'], $finalText); |
| 190 |
} |
| 191 |
|
| 192 |
if (!empty($automation['unconfirmed'])) { |
| 193 |
$automation = acym_translation('ACYM_ACTION_UNCONFIRM'); |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
private function _summaryDate($automation, $finalText) |
| 198 |
{ |
| 199 |
if (!empty($automation['date-min']) || !empty($automation['date-max'])) { |
| 200 |
$finalText .= acym_translationSprintf('ACYM_WHERE_DATE_ACY_LIST_SUMMARY', acym_strtolower(acym_translation('ACYM_'.strtoupper($automation['date-type'])))); |
| 201 |
|
| 202 |
$dates = []; |
| 203 |
if (!empty($automation['date-min'])) { |
| 204 |
$automation['date-min'] = acym_replaceDate($automation['date-min']); |
| 205 |
$dates[] = acym_translationSprintf('ACYM_WHERE_DATE_MIN_ACY_LIST_SUMMARY', acym_date($automation['date-min'], 'd M Y H:i')); |
| 206 |
} |
| 207 |
if (!empty($automation['date-max'])) { |
| 208 |
$automation['date-max'] = acym_replaceDate($automation['date-max']); |
| 209 |
$dates[] = acym_translationSprintf('ACYM_WHERE_DATE_MAX_ACY_LIST_SUMMARY', acym_date($automation['date-max'], 'd M Y H:i')); |
| 210 |
} |
| 211 |
|
| 212 |
$finalText .= ' '.implode(' '.acym_strtolower(acym_translation('ACYM_AND')).' ', $dates); |
| 213 |
} |
| 214 |
|
| 215 |
return $finalText; |
| 216 |
} |
| 217 |
} |
| 218 |
|