public function actionSubscribeContacts($marketingListId, $id, $type, $page = 1, $subscribedCount = 0, $skippedCount = 0)
 {
     assert('$type === "contact" || $type === "report"');
     if (!in_array($type, array('contact', 'report'))) {
         throw new NotSupportedException();
     }
     $contactIds = array((int) $id);
     if ($type === 'report') {
         $attributeName = null;
         $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType('reportResultsListPageSize', get_class($this->getModule()));
         $reportDataProvider = MarketingListMembersUtil::makeReportDataProviderAndResolveAttributeName($id, $pageSize, $attributeName);
         $contactIds = MarketingListMembersUtil::getContactIdsByReportDataProviderAndAttributeName($reportDataProvider, $attributeName);
         $pageCount = $reportDataProvider->getPagination()->getPageCount();
         $subscriberInformation = $this->addNewSubscribers($marketingListId, $contactIds);
         if ($pageCount == $page || $pageCount == 0) {
             $subscriberInformation = array('subscribedCount' => $subscribedCount + $subscriberInformation['subscribedCount'], 'skippedCount' => $skippedCount + $subscriberInformation['skippedCount']);
             $message = $this->renderCompleteMessageBySubscriberInformation($subscriberInformation);
             echo CJSON::encode(array('message' => $message, 'type' => 'message'));
         } else {
             $percentageComplete = round($page / $pageCount, 2) * 100 . ' %';
             $message = Zurmo::t('MarketingListsModule', 'Processing: {percentageComplete} complete', array('{percentageComplete}' => $percentageComplete));
             echo CJSON::encode(array('message' => $message, 'type' => 'message', 'nextPage' => $page + 1, 'subscribedCount' => $subscribedCount + $subscriberInformation['subscribedCount'], 'skippedCount' => $skippedCount + $subscriberInformation['skippedCount']));
         }
     } else {
         $subscriberInformation = $this->addNewSubscribers($marketingListId, $contactIds, MarketingListMember::SCENARIO_MANUAL_CHANGE);
         $message = $this->renderCompleteMessageBySubscriberInformation($subscriberInformation);
         echo CJSON::encode(array('message' => $message, 'type' => 'message'));
     }
 }
 /**
  * @depends testMakeReportDataProviderAndResolveAttributeName
  */
 public function testGetContactIdsByReportDataProviderAndAttributeName()
 {
     $contactReports = SavedReport::getAll();
     $contactReport = $contactReports[0];
     $contacts = Contact::getAll();
     $attributeName = null;
     $reportDataProvider = MarketingListMembersUtil::makeReportDataProviderAndResolveAttributeName($contactReport->id, 1, $attributeName);
     $contactIds = MarketingListMembersUtil::getContactIdsByReportDataProviderAndAttributeName($reportDataProvider, $attributeName);
     $this->assertCount(1, $contactIds);
     $attributeName = null;
     $reportDataProvider = MarketingListMembersUtil::makeReportDataProviderAndResolveAttributeName($contactReport->id, 2, $attributeName);
     $contactIds = MarketingListMembersUtil::getContactIdsByReportDataProviderAndAttributeName($reportDataProvider, $attributeName);
     $this->assertCount(2, $contactIds);
     $this->assertContains($contacts[0]->id, $contactIds);
     $this->assertContains($contacts[1]->id, $contactIds);
 }