/** * @throws HttpException */ public function actionExport() { $this->requirePostRequest(); $this->requireAjaxRequest(); $entry = sproutEmail()->entries->getEntryById(craft()->request->getPost('entryId')); if ($entry && ($campaign = sproutEmail()->campaigns->getCampaignById($entry->campaignId))) { try { $response = sproutEmail()->mailers->exportEntry($entry, $campaign); if ($response instanceof SproutEmail_ResponseModel) { $this->returnJson($response); } $this->returnJson(SproutEmail_ResponseModel::createErrorModalResponse('sproutemail/_modals/export', array('entry' => $entry, 'campaign' => $campaign, 'message' => Craft::t('Mailer did not return a valid response model after entry export.')))); } catch (\Exception $e) { $this->returnJson(SproutEmail_ResponseModel::createErrorModalResponse('sproutemail/_modals/export', array('entry' => $entry, 'campaign' => $campaign, 'message' => Craft::t($e->getMessage())))); } } $this->returnJson(SproutEmail_ResponseModel::createErrorModalResponse('sproutemail/_modals/export', array('entry' => $entry, 'campaign' => !empty($campaign) ? $campaign : null, 'message' => Craft::t('The campaign email you are trying to send is missing.')))); }
/** * @param SproutEmail_EntryModel $entry * @param SproutEmail_CampaignModel $campaign * * @throws \Exception * * @return array */ public function exportEntry(SproutEmail_EntryModel $entry, SproutEmail_CampaignModel $campaign) { $response = new SproutEmail_ResponseModel(); try { $this->getService()->exportEntry($entry, $campaign); return SproutEmail_ResponseModel::createModalResponse('sproutemail/_modals/export', array('entry' => $entry, 'campaign' => $campaign, 'message' => $campaign->isNotification() ? Craft::t('Notification sent successfully') : Craft::t('Campaign sent successfully.'))); } catch (\Exception $e) { sproutEmail()->error($e->getMessage()); return SproutEmail_ResponseModel::createErrorModalResponse('sproutemail/_modals/export', array('entry' => $entry, 'campaign' => $campaign, 'message' => Craft::t($e->getMessage()))); } }