public function renderTranslate() { $campaign = new Campaign($this->getInt('id')); $message = $campaign->message(); $message->reload(); $subject = $this->translateString($message->subject); $plainText = $this->translateString($message->plainText); $language = $this->getStr('hl'); $htmlContent = $message->htmlContent; while ($this->translateBlock($htmlContent)) { } $message->setLanguage($language); $message->reload(); $message->subject = $subject; $message->plainText = $plainText; $message->htmlContent = $htmlContent; $message->saveChanges(); if ($campaign->availableLanguages == null) { $campaign->availableLanguages = [$language => $language]; } else { $availableLanguages = (array) $campaign->availableLanguages; $availableLanguages[$language] = $language; $campaign->availableLanguages = $availableLanguages; } $campaign->saveChanges(); return Redirect::to('/campaigns/' . $this->getStr('id') . '/message/' . $this->getStr('hl')); }
public function runBatch() { $results = []; /** * @var $message IProcessMessage */ foreach ($this->_batch as $taskId => $message) { $cid = $message->getInt('campaignId'); $started = $message->getInt('startedAt'); $lastSent = $message->getInt('lastSent', 0); $startId = $message->getInt('startId', null); $endId = $message->getInt('endId', 0); $additionalData = $message->getRaw('additionalData', null); $campaign = new Campaign($cid); $dataSource = $campaign->getDataSource(); if ($startId == null) { $startId = $dataSource->getLastId($cid, $taskId); } try { $dataSource->process($taskId, $cid, $started, $lastSent, $startId, $endId, $additionalData); $results[$taskId] = true; } catch (\Exception $e) { Log::error('Campaign ' . $cid . ': ' . $e->getMessage()); $results[$taskId] = false; } } $this->_batch = []; return $results; }
public function execute() { $startedAt = time(); $startedAt -= $startedAt % 60; $campaign = new Campaign($this->campaign); Defero::pushCampaign($campaign->id(), $startedAt, $this->startId, $this->endId); }
/** * @return int */ public function execute() { /*$campaignContact = new CampaignContact(); $campaignContact->campaignId = rand(1,9); $campaignContact->language = array_rand( ["en" => "en", "es" => "es", "de" => "de",] ); $campaignContact->contactId = rand(1,9); $campaignContact->saveChanges(); return 0;*/ $contact = new Contact(); $contact->name = "John Smith"; $contact->description = "John the test monkey"; $contact->email = "*****@*****.**"; $contact->jobTitle = "Test Monkey"; $contact->reference = "johnsmith"; $contact->signature = ' Kind Regards John Smith Test Monkey Cubex Tester 0123-456-789'; $contact->saveChanges(); $campaign = new Campaign(); $campaign->reference = "testcampaign:" . FileSystem::readRandomCharacters(3); $campaign->name = "Test Campaign"; $campaign->description = "A test created with sample data"; $campaign->active = true; $campaign->contactId = $contact->id(); $campaign->type = CampaignType::ACTION; $campaign->saveChanges(); $message = $campaign->message(); $message->setLanguage('en'); $message->subject = "This is my subject"; $message->plainText = "Hello {{name}}. how are you today?"; $message->saveAsNew(); $message->setLanguage('es'); $message->subject = "Este es mi tema"; $message->plainText = "Hola {{name}}. ¿Cómo estás hoy?"; $message->saveAsNew(); $message->setLanguage('de'); $message->subject = "Dies ist mein Thema"; $message->plainText = "Hallo {{name}}. Wie geht es Ihnen heute?"; $message->saveAsNew(); }
public static function getAll($query) { $contactSelect = self::_getDisplayResultPattern("c", "name"); $campaignsSelect = self::_getDisplayResultPattern("C", "name"); $queryData = ["SELECT * FROM (\n (SELECT {$contactSelect}, %C, 'Contact' as `type` FROM %T WHERE %C LIKE %~)\n UNION ALL\n (SELECT {$campaignsSelect}, %C, 'Campaign' as `type` FROM %T WHERE %C LIKE %~ OR %C LIKE %~)\n ) %T ORDER BY %C", "name", Contact::tableName(), "name", $query, "name", Campaign::tableName(), "name", $query, "label", $query, "temp", "name"]; $results = DB::getAccessor("defero_db")->getRows(ParseQuery::parse(DB::getAccessor("defero_db"), $queryData)); return $results; }
public function add() { $this->_throwIfNotSet("reference"); $this->_throwIfNotSet("description"); $this->_throwIfNotSet("name"); $this->_throwIfNotSet("type"); $this->_throwIfNotSet("sendType"); $type = strtoupper($this->type); $sendType = strtoupper($this->sendType); $campaign = new Campaign(); $campaign->reference = $this->reference; $campaign->description = $this->description; $campaign->name = $this->name; $campaign->type = CampaignType::$type(); $campaign->sendType = SendType::$sendType(); $campaign->contactId = $this->contactId ?: 0; $campaign->active = $this->active ?: 1; $campaign->saveChanges(); echo "Added campaign id {$campaign->id()} ({$campaign->name})"; }
private function _get30DaysStats() { $this->_stats['30d'] = new \stdClass(); $this->_stats['30d']->totalQueued = 0; $this->_stats['30d']->totalTest = 0; $this->_stats['30d']->totalSent = 0; $this->_stats['30d']->totalFailed = 0; //so counting 30 days brings us to today $time = strtotime('-29 days 00:00:00'); for ($i = 30; $i > 0; $i--) { $stats = $this->campaign->getStats((new \DateTime())->setTimestamp($time), (new \DateTime())->setTimestamp($time + 86399)); $this->_stats['30d']->queued[] = $stats->queued; $this->_stats['30d']->test[] = $stats->test; $this->_stats['30d']->sent[] = $stats->sent; $this->_stats['30d']->failed[] = $stats->failed; $this->_stats['30d']->totalQueued += $stats->queued; $this->_stats['30d']->totalTest += $stats->test; $this->_stats['30d']->totalSent += $stats->sent; $this->_stats['30d']->totalFailed += $stats->failed; $time += 86400; } }
public function renderIndex() { $campaign = new Campaign($this->getInt('id')); $dataSource = $campaign->getDataSource(); $dataSource->setExists(); $form = (new DeferoForm('source'))->bindMapper($dataSource); foreach ($dataSource->getFixedProperties() as $name => $value) { $form->get($name)->addAttribute('disabled'); } $dataSource->configureForm($form, $campaign); if ($post = $this->request()->postVariables()) { $form->hydrate($post); if ($form->isValid() && $form->csrfCheck()) { $dataSource->hydrate($form->jsonSerialize()); $campaign->dataSourceOptions = $dataSource->jsonSerialize(); $campaign->getAttribute('dataSourceOptions')->setModified(); $campaign->saveChanges(); $msg = 'Data Source Saved'; return Redirect::to('/campaigns/' . $campaign->id())->with("msg", new TransportMessage("info", $msg)); } } return new CampaignSourceView($form); }
public function ajaxReorder() { if (!$this->request()->postVariables()) { $response = ['result' => false]; $response = new Response($response); $response->addHeader('Content-Type', 'application/json'); return $response; } foreach ($this->request()->postVariables('order') as $order => $cid) { $campaign = new Campaign($cid); $campaign->sortOrder = $order; $campaign->saveChanges(); } $response = ['result' => true]; $response = new Response($response); $response->addHeader('Content-Type', 'application/json'); return $response; }
/** * @param string $baseUri * @param Request $request * * @return CampaignForm */ private function _buildCampaignForm($baseUri, Request $request) { return CampaignMapper::buildCampaignForm(sprintf("%s%s?%s", $baseUri, $this->getBaseUri(), WizardHelper::getGetRequestString($request))); }
public function renderIndex() { $campaigns = Campaign::collection()->setOrderBy('sortOrder'); return new StatsView($campaigns, $this->request()->postVariables('date')); }
/** * @param string $reference * * @return null * @throws \Exception */ public static function getCampaignIdFromReference($reference) { if (!is_numeric($reference)) { $campaign = Campaign::collection()->loadOneWhere('%C = %s', 'reference', $reference); if (!$campaign) { throw new \Exception('Reference does not match any campaigns'); } $reference = $campaign->id(); } return $reference; }