本文整理汇总了PHP中Campaign::getById方法的典型用法代码示例。如果您正苦于以下问题:PHP Campaign::getById方法的具体用法?PHP Campaign::getById怎么用?PHP Campaign::getById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Campaign
的用法示例。
在下文中一共展示了Campaign::getById方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: makeAll
public function makeAll(&$demoDataHelper)
{
assert('$demoDataHelper instanceof DemoDataHelper');
assert('$demoDataHelper->isSetRange("MarketingList")');
$campaigns = array();
for ($this->index = 0; $this->index < 10; $this->index++) {
$campaign = new Campaign();
$this->populateModel($campaign);
$campaign->marketingList = $demoDataHelper->getRandomByModelName('MarketingList');
$campaign->addPermissions(Group::getByName(Group::EVERYONE_GROUP_NAME), Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER);
$saved = $campaign->save();
if (!$saved) {
throw new FailedToSaveModelException();
}
$campaign = Campaign::getById($campaign->id);
AllPermissionsOptimizationUtil::securableItemGivenPermissionsForGroup($campaign, Group::getByName(Group::EVERYONE_GROUP_NAME));
$campaign->save();
$campaigns[] = $campaign->id;
}
$demoDataHelper->setRangeByModelName('Campaign', $campaigns[0], $campaigns[count($campaigns) - 1]);
}
示例2: testRunWithCampaignPausedAfterAllItemsGeneratedAndThenUnpaused
public function testRunWithCampaignPausedAfterAllItemsGeneratedAndThenUnpaused()
{
// Cleanup
Campaign::deleteAll();
$this->assertEquals(0, Campaign::getCount());
$this->assertEquals(0, CampaignItem::getCount());
$this->assertEquals(0, CampaignItemActivity::getCount());
MarketingList::deleteAll();
$this->assertEquals(0, MarketingList::getCount());
$this->assertEquals(0, MarketingListMember::getCount());
EmailMessage::deleteAll();
$this->assertEquals(0, EmailMessage::getCount());
$this->assertEquals(0, EmailMessageContent::getCount());
$this->assertEquals(0, EmailMessageSender::getCount());
$this->assertEquals(0, EmailMessageRecipient::getCount());
Contact::deleteAll();
$this->assertEquals(0, Contact::getCount());
// setup an email address for contacts
$email = new Email();
$email->emailAddress = 'demo@zurmo.com';
// create a marketing list with 5 members
$marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 05');
$marketingListId = $marketingList->id;
for ($i = 1; $i <= 5; $i++) {
$contact = ContactTestHelper::createContactByNameForOwner('campaignContact 0' . $i, $this->user);
$contact->primaryEmail = $email;
$this->assertTrue($contact->save());
MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
}
$marketingList->forgetAll();
// create a due campaign with that marketing list
$campaign = CampaignTestHelper::createCampaign('campaign 04', 'subject', 'text Content', 'Html Content', null, null, null, null, null, null, MarketingList::getById($marketingListId));
$campaignId = $campaign->id;
/*
* Run 1:
* CampaignGenerateDueCampaignItemsJob
* status == processing
* items generated but unprocessed
*
* CampaignQueueMessagesInOutboxJob
* status == processing
* items processed with email messages generated and queued
*
* ProcessOutboundEmailJob
* status == processing
* email items attempted to be sent
*
* Run 2:
* Pause the campaign
* items are processed and still present
*
* Unpause the campaign
* status == active
* items are processed and still present
*
* CampaignGenerateDueCampaignItemsJob
* status == processing
* ensure all items are present and processed
*
* CampaignQueueMessagesInOutboxJob
* status == processing
* ensure all items are present and processed
* ensure all email messages are present with correct folder type
*
* ProcessOutboundEmailJob
* ensure all email messages are present with correct folder type
* status == processing
*
*
* Run 3:
* Mark Campaign as Completed
* status == completed
*/
// we have to do this to ensure when we retrieve the data status is updated from db.
$campaign->forgetAll();
$this->assertEmpty(CampaignItem::getAll());
// Run 1 starts here
// Run CampaignGenerateDueCampaignItemsJob
$job = new CampaignGenerateDueCampaignItemsJob();
$this->assertTrue($job->run());
$campaign = Campaign::getById($campaignId);
// ensure status is processing
$this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
// ensure 5 campaign items have been generated
$this->assertEquals(5, CampaignItem::getCount());
// ensure all 5 campaign items are unprocessed
$campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaignId);
$this->assertNotEmpty($campaignItems);
$this->assertCount(5, $campaignItems);
// Run CampaignQueueMessagesInOutboxJob
$job = new CampaignQueueMessagesInOutboxJob();
$this->assertTrue($job->run());
// Ensure campaign status
$campaign = Campaign::getById($campaignId);
$this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
// ensure all 5 campaign items are processed
$campaignItems = CampaignItem::getByProcessedAndCampaignId(1, $campaignId);
$this->assertNotEmpty($campaignItems);
$this->assertCount(5, $campaignItems);
// Ensure 5 new email messages
//.........这里部分代码省略.........
示例3: testGenerateCampaignItemsForDueCampaignsWithCustomBatchSize
/**
* @depends testGenerateCampaignItemsForDueCampaigns
*/
public function testGenerateCampaignItemsForDueCampaignsWithCustomBatchSize()
{
$contactIds = array();
$marketingListIds = array();
$campaignIds = array();
for ($index = 6; $index < 9; $index++) {
$contact = ContactTestHelper::createContactByNameForOwner('campaignContact 0' . $index, $this->user);
$contactIds[] = $contact->id;
$contact->forgetAll();
}
for ($index = 8; $index < 12; $index++) {
$suffix = $index;
if ($index < 10) {
$suffix = "0{$suffix}";
}
$marketingList = MarketingListTestHelper::createMarketingListByName('marketingList ' . $suffix);
$marketingListId = $marketingList->id;
$marketingListIds[] = $marketingListId;
foreach ($contactIds as $contactId) {
$contact = Contact::getById($contactId);
$unsubscribed = rand(10, 20) % 2;
MarketingListMemberTestHelper::createMarketingListMember($unsubscribed, $marketingList, $contact);
}
$marketingList->forgetAll();
$marketingList = MarketingList::getById($marketingListId);
$campaignSuffix = substr($marketingList->name, -2);
$campaign = CampaignTestHelper::createCampaign('campaign ' . $campaignSuffix, 'subject ' . $campaignSuffix, 'text ' . $campaignSuffix, 'html ' . $campaignSuffix, null, null, null, null, null, null, $marketingList);
$this->assertNotNull($campaign);
$campaignIds[] = $campaign->id;
$campaign->forgetAll();
}
foreach ($campaignIds as $campaignId) {
$campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaignId);
$this->assertEmpty($campaignItems);
}
$this->assertTrue(CampaignItemsUtil::generateCampaignItemsForDueCampaigns(5));
foreach ($campaignIds as $index => $campaignId) {
$campaign = Campaign::getById($campaignId);
$campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaignId);
if ($index === 0) {
$expectedCount = AutoresponderOrCampaignBatchSizeConfigUtil::getBatchSize();
$memberCount = count($campaign->marketingList->marketingListMembers);
if ($memberCount < $expectedCount) {
$expectedCount = $memberCount;
}
$this->assertNotEmpty($campaignItems);
$this->assertCount($expectedCount, $campaignItems);
$this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
} else {
$this->assertEmpty($campaignItems);
$this->assertEquals(Campaign::STATUS_ACTIVE, $campaign->status);
}
}
$this->assertTrue(CampaignItemsUtil::generateCampaignItemsForDueCampaigns());
foreach ($campaignIds as $index => $campaignId) {
$campaign = Campaign::getById($campaignId);
$campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaignId);
if ($index < 2) {
$expectedCount = AutoresponderOrCampaignBatchSizeConfigUtil::getBatchSize();
$memberCount = count($campaign->marketingList->marketingListMembers);
if ($memberCount < $expectedCount) {
$expectedCount = $memberCount;
}
$this->assertNotEmpty($campaignItems);
$this->assertCount($expectedCount, $campaignItems);
$this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
} else {
$this->assertEmpty($campaignItems);
$this->assertEquals(Campaign::STATUS_ACTIVE, $campaign->status);
}
}
// TODO: @Shoaibi: Medium: Add tests for the other campaign type.
}
示例4: testRunWithSubscribedAndUnsubscribedMembers
/**
* @depends testRunWithMultipleRecipientsWithAttachments
*/
public function testRunWithSubscribedAndUnsubscribedMembers()
{
$campaignItemsCountBefore = CampaignItem::getCount();
$job = new CampaignQueueMessagesInOutboxJob();
$marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 10');
$marketingListId = $marketingList->id;
$contacts = array();
for ($i = 0; $i < 5; $i++) {
$email = new Email();
$email->emailAddress = "demo{$i}@zurmo.com";
$contact = ContactTestHelper::createContactByNameForOwner('contact 0' . ($i + 14), $this->user);
$contact->primaryEmail = $email;
$this->assertTrue($contact->save());
$contacts[] = $contact;
MarketingListMemberTestHelper::createMarketingListMember($i % 2, $marketingList, $contact);
}
$marketingList->forgetAll();
$marketingList = MarketingList::getById($marketingListId);
$campaign = CampaignTestHelper::createCampaign('campaign 10', 'subject 10', '[[FIRST^NAME]]', '[[LAST^NAME]]', null, null, null, Campaign::STATUS_PROCESSING, null, 0, $marketingList);
$this->assertNotNull($campaign);
$campaignId = $campaign->id;
foreach ($contacts as $contact) {
CampaignItemTestHelper::createCampaignItem(0, $campaign, $contact);
}
$this->assertTrue($job->run());
$campaign = Campaign::getById($campaignId);
$campaignItemsCountExpected = $campaignItemsCountBefore + 5;
$campaignItemsCountAfter = CampaignItem::getCount();
$this->assertEquals($campaignItemsCountExpected, $campaignItemsCountAfter);
$campaignItemsProcessed = CampaignItem::getByProcessedAndCampaignId(1, $campaign->id);
$this->assertCount(5, $campaignItemsProcessed);
$skippedCount = 0;
foreach ($campaignItemsProcessed as $campaignItem) {
$contact = $campaignItem->contact;
$member = MarketingListMember::getByMarketingListIdContactIdAndUnsubscribed($campaign->marketingList->id, $contact->id, true);
if ($member) {
$personId = $campaignItem->contact->getClassId('Person');
$type = CampaignItemActivity::TYPE_SKIP;
$activity = CampaignItemActivity::getByTypeAndModelIdAndPersonIdAndUrl($type, $campaignItem->id, $personId);
$this->assertNotNull($activity);
$this->assertNotEmpty($activity);
$this->assertCount(1, $activity);
$skippedCount++;
} else {
$this->assertNotEmpty($campaignItem->emailMessage);
$this->assertContains($contact->firstName, $campaignItem->emailMessage->content->textContent);
$this->assertContains($contact->lastName, $campaignItem->emailMessage->content->htmlContent);
}
}
$this->assertEquals(2, $skippedCount);
}
示例5: testMarkProcessedCampaignsAsCompletedWithCustomPageSize
/**
* @depends testMarkProcessedCampaignsAsCompleted
*/
public function testMarkProcessedCampaignsAsCompletedWithCustomPageSize()
{
Campaign::deleteAll();
$contact = ContactTestHelper::createContactByNameForOwner('contact 02', $this->user);
$marketingList = MarketingListTestHelper::populateMarketingListByName('marketingList 02');
$campaign01 = CampaignTestHelper::createCampaign('campaign 01', 'subject', 'text Content', 'Html Content', null, null, null, Campaign::STATUS_PROCESSING, null, null, $marketingList);
$this->assertNotNull($campaign01);
$campaign01Id = $campaign01->id;
CampaignItemTestHelper::createCampaignItem(1, $campaign01, $contact);
$campaign02 = CampaignTestHelper::createCampaign('campaign 02', 'subject', 'text Content', 'Html Content', null, null, null, Campaign::STATUS_PROCESSING, null, null, $marketingList);
$this->assertNotNull($campaign02);
$campaign02Id = $campaign02->id;
CampaignItemTestHelper::createCampaignItem(1, $campaign02, $contact);
$campaign03 = CampaignTestHelper::createCampaign('campaign 03', 'subject', 'text Content', 'Html Content', null, null, null, Campaign::STATUS_PROCESSING, null, null, $marketingList);
$this->assertNotNull($campaign03);
$campaign03Id = $campaign03->id;
$campaign01->forgetAll();
$campaign02->forgetAll();
$campaign03->forgetAll();
Yii::app()->jobQueue->deleteAll();
$jobs = Yii::app()->jobQueue->getAll();
$this->assertCount(0, $jobs);
$this->assertTrue(CampaignsUtil::markProcessedCampaignsAsCompleted(1));
$jobs = Yii::app()->jobQueue->getAll();
$this->assertCount(1, $jobs);
$this->assertEquals('CampaignMarkCompleted', $jobs[5][0]['jobType']);
$campaign01 = Campaign::getById($campaign01Id);
$this->assertNotNull($campaign01);
$this->assertEquals(Campaign::STATUS_COMPLETED, $campaign01->status);
$campaign02 = Campaign::getById($campaign02Id);
$this->assertNotNull($campaign02);
$this->assertEquals(Campaign::STATUS_PROCESSING, $campaign02->status);
$campaign03 = Campaign::getById($campaign03Id);
$this->assertNotNull($campaign03);
$this->assertEquals(Campaign::STATUS_PROCESSING, $campaign03->status);
$campaign01->forgetAll();
$campaign02->forgetAll();
$campaign03->forgetAll();
Yii::app()->jobQueue->deleteAll();
$jobs = Yii::app()->jobQueue->getAll();
$this->assertCount(0, $jobs);
$this->assertTrue(CampaignsUtil::markProcessedCampaignsAsCompleted());
$jobs = Yii::app()->jobQueue->getAll();
$this->assertCount(0, $jobs);
$campaign01 = Campaign::getById($campaign01Id);
$this->assertNotNull($campaign01);
$this->assertEquals(Campaign::STATUS_COMPLETED, $campaign01->status);
$campaign02 = Campaign::getById($campaign02Id);
$this->assertNotNull($campaign02);
$this->assertEquals(Campaign::STATUS_COMPLETED, $campaign02->status);
$campaign03 = Campaign::getById($campaign03Id);
$this->assertNotNull($campaign03);
$this->assertEquals(Campaign::STATUS_COMPLETED, $campaign03->status);
}
示例6: testHtmlContentGetsSavedCorrectly
/**
* @depends testCreateAndGetCampaignListById
*/
public function testHtmlContentGetsSavedCorrectly()
{
$randomData = ZurmoRandomDataUtil::getRandomDataByModuleAndModelClassNames('EmailTemplatesModule', 'EmailTemplate');
$htmlContent = $randomData['htmlContent'][count($randomData['htmlContent']) - 1];
$campaign = new Campaign();
$campaign->name = 'Another Test Campaign Name';
$campaign->supportsRichText = 0;
$campaign->status = Campaign::STATUS_ACTIVE;
$campaign->fromName = 'Another From Name';
$campaign->fromAddress = 'anotherfrom@zurmo.com';
$campaign->fromName = 'From Name2';
$campaign->fromAddress = 'from2@zurmo.com';
$campaign->subject = 'Another Test subject';
$campaign->textContent = 'Text Content';
$campaign->htmlContent = $htmlContent;
$campaign->marketingList = self::$marketingList;
$this->assertTrue($campaign->save());
$campaignId = $campaign->id;
$campaign->forgetAll();
$campaign = Campaign::getById($campaignId);
$this->assertEquals($htmlContent, $campaign->htmlContent);
}
示例7: actionCopy
public function actionCopy($id)
{
$copyToCampaign = new Campaign();
$postVariableName = get_class($copyToCampaign);
if (!isset($_POST[$postVariableName])) {
$campaign = Campaign::getById((int) $id);
ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($campaign);
CampaignCopyModelUtil::copy($campaign, $copyToCampaign);
}
$this->processEdit($copyToCampaign);
}
示例8: generateCampaignItemsForDueCampaigns
public function generateCampaignItemsForDueCampaigns($count)
{
$marketingList = MarketingListTestHelper::createMarketingListByName('marketingList Test', 'description goes here', 'fromName', 'from@domain.com');
$marketingListId = $marketingList->id;
$contacts = array();
$emails = array();
for ($i = 0; $i < $count; $i++) {
$emails[$i] = new Email();
$emails[$i]->emailAddress = "demo{$i}@zurmo.com";
$account = AccountTestHelper::createAccountByNameForOwner('account ' . $i, $this->user);
$contact = ContactTestHelper::createContactWithAccountByNameForOwner('contact ' . $i, $this->user, $account);
$contact->primaryEmail = $emails[$i];
$this->assertTrue($contact->save());
$contacts[$i] = $contact;
MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
}
$marketingList->forgetAll();
$marketingList = MarketingList::getById($marketingListId);
$content = <<<MTG
[[COMPANY^NAME]]
[[CREATED^DATE^TIME]]
[[DEPARTMENT]]
[[DESCRIPTION]]
[[FIRST^NAME]]
[[GOOGLE^WEB^TRACKING^ID]]
[[INDUSTRY]]
[[JOB^TITLE]]
[[LAST^NAME]]
[[LATEST^ACTIVITY^DATE^TIME]]
[[MOBILE^PHONE]]
[[MODIFIED^DATE^TIME]]
[[OFFICE^FAX]]
[[OFFICE^PHONE]]
[[TITLE]]
[[SOURCE]]
[[STATE]]
[[WEBSITE]]
[[MODEL^URL]]
[[BASE^URL]]
[[APPLICATION^NAME]]
[[CURRENT^YEAR]]
[[LAST^YEAR]]
[[OWNERS^AVATAR^SMALL]]
[[OWNERS^AVATAR^MEDIUM]]
[[OWNERS^AVATAR^LARGE]]
[[OWNERS^EMAIL^SIGNATURE]]
[[UNSUBSCRIBE^URL]]
[[MANAGE^SUBSCRIPTIONS^URL]]
[[PRIMARY^EMAIL__EMAIL^ADDRESS]]
[[PRIMARY^EMAIL__EMAIL^ADDRESS]]
[[SECONDARY^ADDRESS__CITY]]
[[SECONDARY^ADDRESS__COUNTRY]]
[[SECONDARY^ADDRESS__INVALID]]
[[SECONDARY^ADDRESS__LATITUDE]]
[[SECONDARY^ADDRESS__LONGITUDE]]
[[SECONDARY^ADDRESS__POSTAL^CODE]]
[[SECONDARY^ADDRESS__STATE]]
[[SECONDARY^ADDRESS__STREET1]]
[[SECONDARY^ADDRESS__STREET2]]
[[OWNER__DEPARTMENT]]
[[OWNER__FIRST^NAME]]
[[OWNER__IS^ACTIVE]]
[[OWNER__MOBILE^PHONE]]
[[OWNER__LAST^LOGIN^DATE^TIME]]
[[OWNER__LAST^NAME]]
[[CREATED^BY^USER__FIRST^NAME]]
[[CREATED^BY^USER__LAST^NAME]]
[[CREATED^BY^USER__MOBILE^PHONE]]
[[CREATED^BY^USER__TITLE]]
[[CREATED^BY^USER__USERNAME]]
[[ACCOUNT__ANNUAL^REVENUE]]
[[ACCOUNT__INDUSTRY]]
[[ACCOUNT__NAME]]
[[ACCOUNT__WEBSITE]]
[[ACCOUNT__BILLING^ADDRESS__COUNTRY]]
[[ACCOUNT__BILLING^ADDRESS__CITY]]
[[ACCOUNT__OWNER__FIRST^NAME]]
' " ` " '
MTG;
$sendOnDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 600);
$campaign = CampaignTestHelper::createCampaign('campaign Test', 'subject', $content, $content, null, null, null, Campaign::STATUS_ACTIVE, $sendOnDateTime, null, $marketingList, false);
$fileNames = array('testImage.png', 'testZip.zip', 'testPDF.pdf');
$files = array();
foreach ($fileNames as $index => $fileName) {
$file = ZurmoTestHelper::createFileModel($fileName);
$files[$index]['name'] = $fileName;
$files[$index]['type'] = $file->type;
$files[$index]['size'] = $file->size;
$files[$index]['contents'] = $file->fileContent->content;
$campaign->files->add($file);
}
$this->assertTrue($campaign->save(false));
$campaignId = $campaign->id;
$campaign->forgetAll();
$campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaignId);
$this->assertEmpty($campaignItems);
//Process open campaigns.
Yii::app()->jobQueue->deleteAll();
AutoresponderOrCampaignBatchSizeConfigUtil::setBatchSize($count);
Yii::app()->jobQueue->deleteAll();
//.........这里部分代码省略.........
开发者ID:RamaKavanan,项目名称:InitialVersion,代码行数:101,代码来源:CampaignGenerateDueCampaignItemsJobBenchmarkTest.php
示例9: testRunWithCustomBatchSize
/**
* @depends testRunWithCampaignWithProcessingStatusAndProcessedItems
*/
public function testRunWithCustomBatchSize()
{
$this->purgeAllCampaigns();
$contact = ContactTestHelper::createContactByNameForOwner('contact 03', $this->user);
$marketingList = MarketingListTestHelper::populateMarketingListByName('marketingList 04');
$campaign01 = CampaignTestHelper::createCampaign('campaign 01', 'subject', 'text Content', 'Html Content', null, null, null, Campaign::STATUS_PROCESSING, null, null, $marketingList);
$this->assertNotNull($campaign01);
$campaign01Id = $campaign01->id;
CampaignItemTestHelper::createCampaignItem(1, $campaign01, $contact);
$campaign02 = CampaignTestHelper::createCampaign('campaign 02', 'subject', 'text Content', 'Html Content', null, null, null, Campaign::STATUS_PROCESSING, null, null, $marketingList);
$this->assertNotNull($campaign02);
$campaign02Id = $campaign02->id;
CampaignItemTestHelper::createCampaignItem(1, $campaign02, $contact);
$campaign03 = CampaignTestHelper::createCampaign('campaign 03', 'subject', 'text Content', 'Html Content', null, null, null, Campaign::STATUS_PROCESSING, null, null, $marketingList);
$this->assertNotNull($campaign03);
$campaign03Id = $campaign03->id;
$campaign01->forgetAll();
$campaign02->forgetAll();
$campaign03->forgetAll();
$job = new CampaignMarkCompletedJob();
AutoresponderOrCampaignBatchSizeConfigUtil::setBatchSize(1);
$this->assertTrue($job->run());
$campaign01 = Campaign::getById($campaign01Id);
$this->assertNotNull($campaign01);
$this->assertEquals(Campaign::STATUS_COMPLETED, $campaign01->status);
$campaign02 = Campaign::getById($campaign02Id);
$this->assertNotNull($campaign02);
$this->assertEquals(Campaign::STATUS_PROCESSING, $campaign02->status);
$campaign03 = Campaign::getById($campaign03Id);
$this->assertNotNull($campaign03);
$this->assertEquals(Campaign::STATUS_PROCESSING, $campaign03->status);
$campaign01->forgetAll();
$campaign02->forgetAll();
$campaign03->forgetAll();
AutoresponderOrCampaignBatchSizeConfigUtil::setBatchSize(null);
$this->assertTrue($job->run());
$campaign01 = Campaign::getById($campaign01Id);
$this->assertNotNull($campaign01);
$this->assertEquals(Campaign::STATUS_COMPLETED, $campaign01->status);
$campaign02 = Campaign::getById($campaign02Id);
$this->assertNotNull($campaign02);
$this->assertEquals(Campaign::STATUS_COMPLETED, $campaign02->status);
$campaign03 = Campaign::getById($campaign03Id);
$this->assertNotNull($campaign03);
$this->assertEquals(Campaign::STATUS_COMPLETED, $campaign03->status);
}
示例10: array
<?php
$msgs = array();
if (!is_super_admin()) {
print_msgs(array('error' => Campaign::getStrings('SemPermissaoEditar')));
die;
}
if (isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) {
try {
$campaign = Campaign::getById($_REQUEST['id']);
} catch (Exception $e) {
echo $e->getMessage();
die;
}
} else {
print_msgs(array('error' => Campaign::getStrings('NaoEncontrado')));
die;
}
if (!empty($_POST)) {
$campaign->own_domain = filter_input(INPUT_POST, 'own_domain', FILTER_SANITIZE_URL);
$campaign->candidate_number = filter_input(INPUT_POST, 'candidate_number', FILTER_SANITIZE_NUMBER_INT);
$campaign->plan_id = filter_input(INPUT_POST, 'plan_id', FILTER_SANITIZE_NUMBER_INT);
$campaign->state = filter_input(INPUT_POST, 'state', FILTER_SANITIZE_NUMBER_INT);
$campaign->city = filter_input(INPUT_POST, 'city', FILTER_SANITIZE_NUMBER_INT);
$campaign->observations = filter_input(INPUT_POST, 'observations', FILTER_SANITIZE_STRING);
$campaign->status = filter_input(INPUT_POST, 'status', FILTER_SANITIZE_NUMBER_INT);
if ($campaign->validate()) {
$campaign->update();
$msgs = array('updated' => Campaign::getStrings('AtualizadoSucesso'));
} else {
$msgs = $campaign->errorHandler->errors;
示例11: testGenerateCampaignItemsForDueCampaigns
/**
* @depends testProcessDueCampaignItemWithAttachments
*/
public function testGenerateCampaignItemsForDueCampaigns()
{
$marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 07');
$marketingListId = $marketingList->id;
for ($i = 0; $i < 5; $i++) {
$contact = ContactTestHelper::createContactByNameForOwner('campaignContact ' . $i, $this->user);
MarketingListMemberTestHelper::createMarketingListMember($i % 2, $marketingList, $contact);
}
$marketingList->forgetAll();
$marketingList = MarketingList::getById($marketingListId);
$campaign = CampaignTestHelper::createCampaign('campaign 07', 'subject 07', 'text 07', 'html 07', null, null, null, null, null, null, $marketingList);
$this->assertNotNull($campaign);
$campaign->forgetAll();
$campaignId = $campaign->id;
$campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaignId);
$this->assertEmpty($campaignItems);
//Process open campaigns.
Yii::app()->jobQueue->deleteAll();
$this->assertCount(0, Yii::app()->jobQueue->getAll());
$util = new CampaignItemsUtil();
$this->assertTrue($util->generateCampaignItemsForDueCampaigns());
$jobs = Yii::app()->jobQueue->getAll();
$this->assertCount(1, $jobs);
$this->assertEquals('CampaignQueueMessagesInOutbox', $jobs[5][0]['jobType']);
$campaign = Campaign::getById($campaignId);
$this->assertNotNull($campaign);
$this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
$campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaignId);
$this->assertNotEmpty($campaignItems);
$this->assertCount(5, $campaignItems);
// TODO: @Shoaibi: Low: Add tests for the other campaign type.
}
示例12: testRunJobDoesNotRegenerateExistingItems
/**
* @depends testRunWithJustDueActiveCampaignsWithMembers
*/
public function testRunJobDoesNotRegenerateExistingItems()
{
$data = array('old' => array('subject' => 'Old Subject', 'fromName' => 'Old From Name', 'fromAddress' => 'old@zurmo.com', 'textContent' => 'Old Text Content', 'htmlContent' => 'Old Html Content'), 'new' => array('subject' => 'New Subject', 'fromName' => 'New From Name', 'fromAddress' => 'new@zurmo.com', 'textContent' => 'New Text Content', 'htmlContent' => 'New Html Content'));
$marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 06');
$marketingListId = $marketingList->id;
$processed = 0;
for ($i = 11; $i <= 15; $i++) {
$email = new Email();
$email->emailAddress = "demo{$i}@zurmo.com";
$contact = ContactTestHelper::createContactByNameForOwner('campaignContact 0' . $i, $this->user);
$contact->primaryEmail = $email;
$this->assertTrue($contact->save());
MarketingListMemberTestHelper::createMarketingListMember($processed, $marketingList, $contact);
}
$marketingList->forgetAll();
$marketingList = MarketingList::getById($marketingListId);
$nowDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
$campaign = CampaignTestHelper::createCampaign('campaign', $data['old']['subject'], $data['old']['textContent'], $data['old']['htmlContent'], $data['old']['fromName'], $data['old']['fromAddress'], null, Campaign::STATUS_ACTIVE, $nowDateTime, null, $marketingList);
$campaignId = $campaign->id;
// we have to do this to ensure when we retrieve the data status is updated from db.
$campaign->forgetAll();
$this->assertEmpty(CampaignItem::getAll());
// sleep 1 second to ensure we are giving ample time difference between creating the campaign and calling the job
sleep(1);
$campaignGenerateDueCampaignItemsJob = new CampaignGenerateDueCampaignItemsJob();
$this->assertTrue($campaignGenerateDueCampaignItemsJob->run());
$campaign = Campaign::getById($campaignId);
$this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
$allCampaignItems = CampaignItem::getAll();
$this->assertNotEmpty($allCampaignItems);
$this->assertCount(5, $allCampaignItems);
$campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaignId);
$this->assertNotEmpty($campaignItems);
$this->assertCount(5, $campaignItems);
$campaignQueueMessagesInOutboxJob = new CampaignQueueMessagesInOutboxJob();
$this->assertTrue($campaignQueueMessagesInOutboxJob->run());
$campaignItems = CampaignItem::getByProcessedAndCampaignId(1, $campaignId);
$this->assertNotEmpty($campaignItems);
$this->assertCount(5, $campaignItems);
$oldCampaignItemIds = array();
foreach ($campaignItems as $ci) {
$this->assertNotEmpty($ci->id);
$this->assertEquals(1, $ci->processed);
$this->assertNotEmpty($ci->emailMessage->id);
$this->assertNotEmpty($ci->emailMessage->sender->id);
$this->assertNotEmpty($ci->emailMessage->content->id);
$this->assertNotEmpty($ci->contact->id);
$this->assertEquals($data['old']['subject'], $ci->emailMessage->subject);
$this->assertEquals($data['old']['fromName'], $ci->emailMessage->sender->fromName);
$this->assertEquals($data['old']['fromAddress'], $ci->emailMessage->sender->fromAddress);
$this->assertContains($data['old']['textContent'], $ci->emailMessage->content->textContent);
$this->assertContains($data['old']['htmlContent'], $ci->emailMessage->content->htmlContent);
$oldCampaignItemIds[] = $ci->id;
}
$campaignItems[count($campaignItems) - 1]->delete();
array_pop($oldCampaignItemIds);
$campaign->status = Campaign::STATUS_ACTIVE;
foreach ($data['new'] as $property => $value) {
$campaign->{$property} = $value;
}
$this->assertTrue($campaign->save());
$campaign->forgetAll();
$campaignGenerateDueCampaignItemsJob = new CampaignGenerateDueCampaignItemsJob();
$this->assertTrue($campaignGenerateDueCampaignItemsJob->run());
$campaign = Campaign::getById($campaignId);
$this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
$allCampaignItems = CampaignItem::getAll();
$this->assertNotEmpty($allCampaignItems);
$this->assertCount(5, $allCampaignItems);
$campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaignId);
$this->assertNotEmpty($campaignItems);
$this->assertCount(1, $campaignItems);
$campaignQueueMessagesInOutboxJob = new CampaignQueueMessagesInOutboxJob();
$this->assertTrue($campaignQueueMessagesInOutboxJob->run());
$campaignItems = CampaignItem::getByProcessedAndCampaignId(1, $campaignId);
$this->assertNotEmpty($campaignItems);
$this->assertCount(5, $campaignItems);
$oldCounter = 0;
$newCounter = 0;
foreach ($campaignItems as $ci) {
$this->assertNotEmpty($ci->id);
$this->assertEquals(1, $ci->processed);
$this->assertNotEmpty($ci->emailMessage->id);
$this->assertNotEmpty($ci->emailMessage->sender->id);
$this->assertNotEmpty($ci->emailMessage->content->id);
$this->assertNotEmpty($ci->contact->id);
$dataIndex = in_array($ci->id, $oldCampaignItemIds) ? 'old' : 'new';
if ($dataIndex == 'old') {
$oldCounter++;
} else {
$newCounter++;
}
$this->assertEquals($data[$dataIndex]['subject'], $ci->emailMessage->subject);
$this->assertEquals($data[$dataIndex]['fromName'], $ci->emailMessage->sender->fromName);
$this->assertEquals($data[$dataIndex]['fromAddress'], $ci->emailMessage->sender->fromAddress);
$this->assertContains($data[$dataIndex]['textContent'], $ci->emailMessage->content->textContent);
$this->assertContains($data[$dataIndex]['htmlContent'], $ci->emailMessage->content->htmlContent);
//.........这里部分代码省略.........
示例13: testRequiredAttributes
/**
* @depends testCreateAndGetCampaignListById
*/
public function testRequiredAttributes()
{
$campaign = new Campaign();
$this->assertFalse($campaign->save());
$errors = $campaign->getErrors();
$this->assertNotEmpty($errors);
$this->assertCount(7, $errors);
$this->assertArrayHasKey('name', $errors);
$this->assertEquals('Name cannot be blank.', $errors['name'][0]);
$this->assertArrayHasKey('supportsRichText', $errors);
$this->assertEquals('Supports HTML cannot be blank.', $errors['supportsRichText'][0]);
$this->assertArrayHasKey('subject', $errors);
$this->assertEquals('Subject cannot be blank.', $errors['subject'][0]);
$this->assertArrayHasKey('fromName', $errors);
$this->assertEquals('From Name cannot be blank.', $errors['fromName'][0]);
$this->assertArrayHasKey('fromAddress', $errors);
$this->assertEquals('From Address cannot be blank.', $errors['fromAddress'][0]);
$this->assertArrayHasKey('textContent', $errors);
$this->assertEquals('Please provide at least one of the contents field.', $errors['textContent'][0]);
$this->assertArrayHasKey('marketingList', $errors);
$this->assertEquals('Marketing List cannot be blank.', $errors['marketingList'][0]);
$campaign->name = 'Test Campaign Name2';
$campaign->supportsRichText = 0;
$campaign->status = Campaign::STATUS_ACTIVE;
$campaign->fromName = 'From Name2';
$campaign->fromAddress = 'from2@zurmo.com';
$campaign->subject = 'Test Subject2';
$campaign->htmlContent = 'Test Html Content2';
$campaign->textContent = 'Test Text Content2';
$campaign->fromName = 'From Name2';
$campaign->fromAddress = 'from2@zurmo.com';
$campaign->marketingList = self::$marketingList;
$this->assertTrue($campaign->save());
$id = $campaign->id;
unset($campaign);
$campaign = Campaign::getById($id);
$this->assertEquals('Test Campaign Name2', $campaign->name);
$this->assertEquals(0, $campaign->supportsRichText);
$this->assertEquals(Campaign::STATUS_ACTIVE, $campaign->status);
$this->assertEquals('From Name2', $campaign->fromName);
$this->assertEquals('from2@zurmo.com', $campaign->fromAddress);
$this->assertEquals('Test Subject2', $campaign->subject);
$this->assertEquals('Test Html Content2', $campaign->htmlContent);
$this->assertEquals('Test Text Content2', $campaign->textContent);
$this->assertTrue(time() + 15 > DateTimeUtil::convertDbFormatDateTimeToTimestamp($campaign->sendOnDateTime));
}
示例14: actionEdit
public function actionEdit($id)
{
$campaign = Campaign::getById(intval($id));
ControllerSecurityUtil::resolveAccessCanCurrentUserWriteModel($campaign);
$breadcrumbLinks = static::getDetailsAndEditBreadcrumbLinks();
$breadcrumbLinks[] = StringUtil::getChoppedStringContent(strval($campaign), 25);
//todo: wizard
$editView = new CampaignEditView($this->getId(), $this->getModule()->getId(), $this->attemptToSaveModelFromPost($campaign), strval($campaign));
$view = new CampaignsPageView(MarketingDefaultViewUtil::makeViewWithBreadcrumbsForCurrentUser($this, $editView, $breadcrumbLinks, 'MarketingBreadCrumbView'));
echo $view->render();
}