pluginDescription->name = 'Export in automations';
$this->pluginDescription->category = 'User management';
$this->pluginDescription->features = '["automation"]';
$this->pluginDescription->description = '- Export the filtered users in the automations';
}
public function onAcymDeclareActions(&$actions)
{
$actions['export'] = new stdClass();
$actions['export']->name = acym_translation('ACYM_EXPORT_SUBSCRIBERS');
$actions['export']->option = '
';
$fields = acym_getColumns('user');
$fieldClass = new FieldClass();
$customFields = $fieldClass->getAll();
$fields = array_merge($fields, $customFields);
$defaultFields = explode(',', $this->config->get('export_fields', 'name,email'));
foreach ($fields as $field) {
if (is_object($field)) {
$type = 'custom';
$fieldName = $field->name;
$fieldValue = $field->id;
if ($field->type == 'file' || in_array($field->id, [1, 2])) continue;
} else {
$type = 'core';
$fieldName = $field;
$fieldValue = $fieldName;
if (in_array($fieldName, ['id', 'automation'])) continue;
}
$checked = in_array($fieldValue, $defaultFields) ? 'checked="checked"' : '';
$actions['export']->option .= '
';
$actions['export']->option .= '';
$actions['export']->option .= '';
$actions['export']->option .= '
';
}
$actions['export']->option .= '
';
$actions['export']->option .= '';
$actions['export']->option .= '
'.acym_translation('ACYM_SEPARATOR').'
';
$actions['export']->option .= '
'.acym_select(
[
'semicol' => acym_translation('ACYM_SEMICOLON'),
'comma' => acym_translation('ACYM_COMMA'),
],
'acym_action[actions][__and__][export][separator]',
$this->config->get('export_separator', 'comma'),
'class="acym__select"'
).'
';
$actions['export']->option .= '
';
$actions['export']->option .= '';
$actions['export']->option .= '
'.acym_translation('ACYM_ENCODING').'
';
$encodingHelper = new EncodingHelper();
$actions['export']->option .= '
'.$encodingHelper->charsetField(
'acym_action[actions][__and__][export][charset]',
$this->config->get('export_charset', 'UTF-8'),
'class="acym__select"'
).'
';
$actions['export']->option .= '
';
$actions['export']->option .= '';
$actions['export']->option .= '';
$actions['export']->option .= '';
$actions['export']->option .= '
';
}
public function onAcymProcessAction_export(&$cquery, $action)
{
// Get the file name
$pathtolog = ACYM_ROOT.ACYM_LOGS_FOLDER.'export_'.date('Y-m-d').'.csv';
if (!empty($action['path']) && false === strpos($action['path'], '..')) {
$pathtolog = ACYM_ROOT.strftime($action['path']);
}
if (empty($action['core']) && empty($action['custom'])) return '['.acym_translation('ACYM_EXPORT_SUBSCRIBERS').'] '.acym_translation('ACYM_EXPORT_SELECT_FIELD');
if (empty($action['core'])) $action['core'] = [];
if (empty($action['custom'])) $action['custom'] = [];
acym_increasePerf();
$select = ['user.`id`'];
foreach ($action['core'] as $oneField) {
$select[] = 'user.`'.acym_secureDBColumn($oneField).'`';
}
$query = $cquery->getQuery($select);
$exportHelper = new ExportHelper();
$realSeparators = ['comma' => ',', 'semicol' => ';'];
$error = $exportHelper->exportCSV($query, $action['core'], $action['custom'], $realSeparators[$action['separator']], $action['charset'], $pathtolog);
if (empty($error)) {
return acym_translationSprintf('ACYM_USERS_EXPORTED', $pathtolog);
} else {
return '['.acym_translation('ACYM_EXPORT_SUBSCRIBERS').'] '.$error;
}
}
public function onAcymDeclareSummary_actions(&$automation)
{
if (!empty($automation['export'])) {
$automation = acym_translation('ACYM_ALL_SUBSCRIBER_WILL_BE_EXPORTED');
}
}
}