/** * Gets additional fields to render in the form to add/edit a task * * @param array $taskInfo Values of the fields from the add/edit task form * @param SyncToMailChimpTask $task The task object being edited. Null when adding a task! * @param SchedulerModuleController $schedulerModule Reference to the scheduler backend module * @return array A two dimensional array, array('Identifier' => array('fieldId' => array('code' => '', 'label' => '', 'cshKey' => '', 'cshLabel' => '')) */ public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule) { $fields = array(); $listId = $task != NULL ? $task->getListId() : NULL; if (strlen($taskInfo['listId']) > 0) { $listId = $taskInfo['listId']; } $fields['listId'] = array('code' => $this->createListSelection($listId), 'label' => 'LLL:EXT:t3chimp/Resources/Private/Language/locallang_backend.xml:syncToMailChimpTask_label_listId'); if ($listId != NULL) { $code = ''; $fieldDefinitions = $this->mailChimp->getFieldsFor($listId); $existingMappings = $task != NULL ? $task->getMappings() : array(); foreach ($fieldDefinitions as $fieldDefinition) { if ($fieldDefinition['field_type'] != 'address') { $code .= $this->createSimpleField($fieldDefinition, $existingMappings[$fieldDefinition['tag']]); } else { $code .= $this->createAddressField($fieldDefinition, $existingMappings); } $code .= '<br />'; } $groupings = $this->mailChimp->getInterestGroupingsFor($listId); foreach ($groupings as $grouping) { $code .= $this->createGroupingField($grouping, $existingMappings[$grouping['name']]); $code .= '<br />'; } $fields['mappings'] = array('code' => $code, 'label' => 'LLL:EXT:t3chimp/Resources/Private/Language/locallang_backend.xml:syncToMailChimpTask_label_mappings'); } return $fields; }
/** * @param string $listId * @return array */ protected function retrieveSubscribers($listId) { $subscribers = array(); foreach ($this->mailChimp->getSubscribersFor($listId) as $subscriber) { $subscribers[$subscriber['email']] = $subscriber; } return $subscribers; }
/** * Gets additional fields to render in the form to add/edit a task * * @param array $taskInfo Values of the fields from the add/edit task form * @param SyncBackFromMailChimpTask $task The task object being eddited. Null when adding a task! * @param SchedulerModuleController $schedulerModule Reference to the scheduler backend module * @return array A two dimensional array, array('Identifier' => array('fieldId' => array('code' => '', 'label' => '', 'cshKey' => '', 'cshLabel' => '')) */ public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule) { $codeListId = '<select name="tx_scheduler[listId]">'; foreach ($this->mailChimp->getLists() as $list) { $selected = $task != NULL && $list['id'] == $task->getListId() ? ' selected="selected"' : ''; $codeListId .= '<option value="' . $list['id'] . '"' . $selected . '>' . htmlentities($list['name']) . '</option>'; } $codeListId .= '</select>'; $codeMailField = '<select name="tx_scheduler[emailField]">'; foreach ($GLOBALS['TCA']['fe_users']['columns'] as $column => $config) { $label = $GLOBALS['LANG']->sL($config['label']); if (strlen($label) == 0) { $label = $column; } else { $label = substr($label, 0, strlen($label) - 1); } $selected = $task != NULL && $column == $task->getEmailField() ? ' selected="selected"' : ''; $codeMailField .= '<option value="' . $column . '"' . $selected . '>' . $label . ' (' . $column . ')</option>'; } $codeMailField .= '</select>'; return array('listId' => array('code' => $codeListId, 'label' => 'LLL:EXT:t3chimp/Resources/Private/Language/locallang_backend.xlf:syncBackFromMailChimpTask_label_listId'), 'emailField' => array('code' => $codeMailField, 'label' => 'LLL:EXT:t3chimp/Resources/Private/Language/locallang_backend.xlf:syncBackFromMailChimpTask_label_emailField')); }
public function processAction() { $form = $this->mailChimpService->getFormFor($this->request->getArgument('list'), $this->request->hasArgument('email_type')); $form->bindRequest($this->request); $this->signalSlotDispatcher->dispatch(__CLASS__, 'onValidateForm', array($form, $this->view, $this)); $success = FALSE; $showForm = TRUE; $message = ''; if ($form->isValid()) { try { $performedAction = $this->mailChimpService->saveForm($form); if ($performedAction == MailChimp::ACTION_SUBSCRIBE) { if ($this->settings['doubleOptIn']) { $message = $this->translate('form_almostSubscribed'); } else { $message = $this->translate('form_subscribed'); } } else { if ($performedAction == MailChimp::ACTION_UPDATE) { $message = $this->translate('form_updated'); } else { $message = $this->translate('form_unsubscribed'); } } $success = TRUE; } catch (InvalidEmail $ex) { $message = $this->translate('exception_invalidEmail'); } catch (ListNotSubscribed $ex) { $message = $this->translate('exception_notSubscribed'); } catch (Error $ex) { $message = $ex->getMessage(); } $showForm = FALSE; } $this->view->assign('form', $form); $this->view->assign('message', $message); $this->view->assign('showForm', $showForm); $this->view->assign('success', $success); $this->view->assign('status', $success ? 'success' : 'error'); return json_encode(array('html' => $this->view->render(), 'success' => $success), JSON_HEX_TAG | JSON_HEX_QUOT); }