protected static function generateCampaignItems($campaign, $pageSize) { if ($pageSize == null) { $pageSize = self::DEFAULT_CAMPAIGNITEMS_TO_CREATE_PAGE_SIZE; } $contacts = array(); $quote = DatabaseCompatibilityUtil::getQuote(); $sql = "select {$quote}marketinglistmember{$quote}.{$quote}contact_id{$quote} from {$quote}marketinglistmember{$quote}\n left join {$quote}campaignitem{$quote} on {$quote}campaignitem{$quote}.{$quote}contact_id{$quote} " . "= {$quote}marketinglistmember{$quote}.{$quote}contact_id{$quote} " . "AND {$quote}campaignitem{$quote}.{$quote}campaign_id{$quote} = " . $campaign->id . " where {$quote}marketinglistmember{$quote}.{$quote}marketinglist_id{$quote} = " . $campaign->marketingList->id . " and {$quote}campaignitem{$quote}.{$quote}id{$quote} IS NULL limit " . $pageSize; $ids = R::getCol($sql); foreach ($ids as $contactId) { $contacts[] = Contact::getById((int) $contactId); } if (!empty($contacts)) { //todo: if the return value is false, then we might need to catch that since it didn't go well. CampaignItem::registerCampaignItemsByCampaign($campaign, $contacts); if (count($ids) < $pageSize) { return true; } } else { return true; } }
protected static function generateCampaignItems($campaign, $pageSize) { if ($pageSize == null) { $pageSize = self::DEFAULT_CAMPAIGNITEMS_TO_CREATE_PAGE_SIZE; } $contacts = array(); $quote = DatabaseCompatibilityUtil::getQuote(); $marketingListMemberTableName = RedBeanModel::getTableName('MarketingListMember'); $campaignItemTableName = RedBeanModel::getTableName('CampaignItem'); $sql = "select {$quote}{$marketingListMemberTableName}{$quote}.{$quote}contact_id{$quote} from {$quote}{$marketingListMemberTableName}{$quote}"; // Not Coding Standard $sql .= "left join {$quote}{$campaignItemTableName}{$quote} on "; $sql .= "{$quote}{$campaignItemTableName}{$quote}.{$quote}contact_id{$quote} "; $sql .= "= {$quote}{$marketingListMemberTableName}{$quote}.{$quote}contact_id{$quote}"; $sql .= "AND {$quote}{$campaignItemTableName}{$quote}.{$quote}campaign_id{$quote} = " . $campaign->id . " "; $sql .= "where {$quote}{$marketingListMemberTableName}{$quote}.{$quote}marketinglist_id{$quote} = " . $campaign->marketingList->id; $sql .= " and {$quote}{$campaignItemTableName}{$quote}.{$quote}id{$quote} is null limit " . $pageSize; $ids = R::getCol($sql); foreach ($ids as $contactId) { $contacts[] = Contact::getById((int) $contactId); } if (!empty($contacts)) { //todo: if the return value is false, then we might need to catch that since it didn't go well. CampaignItem::registerCampaignItemsByCampaign($campaign, $contacts); if (count($ids) < $pageSize) { return true; } } else { return true; } return false; }
/** * @depends testAddNewItem */ public function testRegisterCampaignItemsByCampaign() { $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 05'); $campaign = CampaignTestHelper::createCampaign('campaign 04', 'subject 04', 'text 04', 'html 04', null, null, null, null, null, null, $marketingList); $this->assertNotNull($campaign); $contacts = array(); $contacts[] = ContactTestHelper::createContactByNameForOwner('campaignContact 01', Yii::app()->user->userModel); $contacts[] = ContactTestHelper::createContactByNameForOwner('campaignContact 02', Yii::app()->user->userModel); $contacts[] = ContactTestHelper::createContactByNameForOwner('campaignContact 03', Yii::app()->user->userModel); $contacts[] = ContactTestHelper::createContactByNameForOwner('campaignContact 04', Yii::app()->user->userModel); $contacts[] = ContactTestHelper::createContactByNameForOwner('campaignContact 05', Yii::app()->user->userModel); CampaignItem::registerCampaignItemsByCampaign($campaign, $contacts); $campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaign->id); $this->assertNotEmpty($campaignItems); $this->assertCount(5, $campaignItems); }