/**
  * Method for testing creating a simple notification for the current user.
  */
 public function actionGenerateManageSubscriptionHash()
 {
     if (Yii::app()->user->userModel->username != 'super') {
         throw new NotSupportedException();
     }
     $contact = RandomDataUtil::getRandomValueFromArray(Contact::getAll());
     $personId = $contact->getClassId('Person');
     $marketingList = RandomDataUtil::getRandomValueFromArray(MarketingList::getAll());
     $marketingListId = $marketingList->id;
     $model = RandomDataUtil::getRandomValueFromArray(CampaignItem::getAll());
     $modelId = $model->id;
     $modelType = get_class($model);
     $hash = EmailMessageActivityUtil::resolveHashForUnsubscribeAndManageSubscriptionsUrls($personId, $marketingListId, $modelId, $modelType, false);
     echo 'index.php/marketingLists/external/manageSubscriptions?hash=' . $hash;
 }
 protected function renderToggleSubscriptionSwitch($marketingListId, $subscribed)
 {
     $template = ZurmoHtml::tag('div', array('class' => 'switch-state clearfix'), '{input}{label}');
     $createNewActivity = false;
     if ($marketingListId == $this->sourceMarketingListId) {
         $createNewActivity = true;
     }
     $hash = EmailMessageActivityUtil::resolveHashForUnsubscribeAndManageSubscriptionsUrls($this->personId, $marketingListId, $this->modelId, $this->modelType, $createNewActivity);
     $subscribeUrl = $this->getSubscribeUrlByHash($hash);
     $unsubscribeUrl = $this->getUnsubscribeUrlByHash($hash);
     $checkedValue = $subscribeUrl;
     if (!$subscribed) {
         $checkedValue = $unsubscribeUrl;
     }
     $baseId = static::TOGGLE_UNSUBSCRIPTION_LINK_CLASS . '_' . $marketingListId;
     $content = ZurmoHTML::radioButtonList($baseId, $checkedValue, self::getDropDownArray($subscribeUrl, $unsubscribeUrl), array('separator' => '', 'template' => $template));
     return ZurmoHtml::tag('div', array('class' => 'switch'), $content);
 }
 /**
  * @depends testOptOutAction
  */
 public function testSubscribeActionAfterOptOutActionDisableOptOut()
 {
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $marketingList = MarketingList::getByName('marketingList 04');
     $this->assertNotEmpty($marketingList);
     $marketingList = $marketingList[0];
     $marketingListId = $marketingList->id;
     $contact = Contact::getByName('contact 05 contact 05son');
     $this->assertNotEmpty($contact);
     $contact = $contact[0];
     $this->assertEquals(1, $contact->primaryEmail->optOut);
     $personId = $contact->getClassId('Person');
     $member = MarketingListMember::getByMarketingListIdContactIdAndSubscribed($marketingList->id, $contact->id, 1);
     $this->assertNotEmpty($member);
     Yii::app()->user->userModel = null;
     $hash = EmailMessageActivityUtil::resolveHashForUnsubscribeAndManageSubscriptionsUrls($personId, $marketingListId, 1, 'AutoresponderItem', false);
     $this->setGetArray(array('hash' => $hash));
     @$this->runControllerWithRedirectExceptionAndGetUrl($this->subscribeUrl);
     $content = $this->runControllerWithNoExceptionsAndGetContent($this->manageSubscriptionsUrl);
     $this->assertTrue(strpos($content, '<td>marketingList 01</td>') !== false);
     $this->assertTrue(strpos($content, '<td>marketingList 03</td>') !== false);
     $this->assertTrue(strpos($content, 'marketingLists/external/subscribe?hash=') !== false);
     $this->assertTrue(strpos($content, 'id="marketingListsManage' . 'SubscriptionListView-toggleUnsubscribed_') !== false);
     $this->assertTrue(strpos($content, 'id="marketingListsManage' . 'SubscriptionListView-toggleUnsubscribed_') !== false);
     $this->assertTrue(strpos($content, 'type="radio" name="marketingListsManage' . 'SubscriptionListView-toggleUnsubscribed_') !== false);
     $this->assertTrue(strpos($content, 'id="marketingListsManageSubscriptionListView-toggleUnsubscribed_' . $marketingListId . '_0" checked="checked" type="radio" name="marketingListsManage' . 'SubscriptionListView-toggleUnsubscribed_' . $marketingListId) !== false);
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $contact = Contact::getByName('contact 05 contact 05son');
     $this->assertNotEmpty($contact);
     $contact = $contact[0];
     $this->assertEquals(0, $contact->primaryEmail->optOut);
 }