PageRenderTime 25ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/app/protected/modules/marketingLists/views/MarketingListsManageSubscriptionsListView.php

https://bitbucket.org/zurmo/zurmo/
PHP | 213 lines | 154 code | 21 blank | 38 comment | 7 complexity | 35d5d90ab9effd204da626564f79b255 MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, GPL-2.0, LGPL-3.0, LGPL-2.1, BSD-2-Clause
  1. <?php
  2. /*********************************************************************************
  3. * Zurmo is a customer relationship management program developed by
  4. * Zurmo, Inc. Copyright (C) 2015 Zurmo Inc.
  5. *
  6. * Zurmo is free software; you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License version 3 as published by the
  8. * Free Software Foundation with the addition of the following permission added
  9. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  10. * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
  11. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  12. *
  13. * Zurmo is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License along with
  19. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  20. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  21. * 02110-1301 USA.
  22. *
  23. * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
  24. * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
  25. *
  26. * The interactive user interfaces in original and modified versions
  27. * of this program must display Appropriate Legal Notices, as required under
  28. * Section 5 of the GNU Affero General Public License version 3.
  29. *
  30. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  31. * these Appropriate Legal Notices must retain the display of the Zurmo
  32. * logo and Zurmo copyright notice. If the display of the logo is not reasonably
  33. * feasible for technical reasons, the Appropriate Legal Notices must display the words
  34. * "Copyright Zurmo Inc. 2015. All rights reserved".
  35. ********************************************************************************/
  36. /**
  37. * A view that displays a list of currency models in the application.
  38. *
  39. */
  40. class MarketingListsManageSubscriptionsListView extends MetadataView
  41. {
  42. protected $controllerId;
  43. protected $moduleId;
  44. protected $marketingLists;
  45. protected $personId;
  46. protected $sourceMarketingListId;
  47. protected $modelId;
  48. protected $modelType;
  49. const TOGGLE_UNSUBSCRIPTION_LINK_CLASS = 'marketingListsManageSubscriptionListView-toggleUnsubscribed';
  50. public function __construct($controllerId, $moduleId, $marketingLists, $personId,
  51. $sourceMarketingListId, $modelId, $modelType)
  52. {
  53. assert('is_string($controllerId)');
  54. assert('is_string($moduleId)');
  55. assert('is_array($marketingLists)');
  56. $this->controllerId = $controllerId;
  57. $this->moduleId = $moduleId;
  58. $this->marketingLists = $marketingLists;
  59. $this->personId = $personId;
  60. $this->sourceMarketingListId = $sourceMarketingListId;
  61. $this->modelId = $modelId;
  62. $this->modelType = $modelType;
  63. }
  64. public function isUniqueToAPage()
  65. {
  66. return true;
  67. }
  68. public function getTitle()
  69. {
  70. $applicationName = ZurmoConfigurationUtil::getByModuleName('ZurmoModule', 'applicationName');
  71. if ($applicationName != null)
  72. {
  73. $applicationName = ' - ' . $applicationName;
  74. }
  75. return Zurmo::t('MarketingListsModule', 'My Subscriptions') . $applicationName;
  76. }
  77. protected function renderContent()
  78. {
  79. $this->renderScripts();
  80. $titleContent = $this->renderTitleContent();
  81. $bodyContent = $this->renderMarketingListsList();
  82. $content = $titleContent . ZurmoHtml::tag('div', array('class' => 'wide',
  83. 'id' => 'marketingLists-manageSubscriptionsList'),
  84. $bodyContent);
  85. $content = ZurmoHtml::tag('div', array('class' => 'left-column full-width'), $content);
  86. $content = ZurmoHtml::tag('div', array('class' => 'wrapper'), $content);
  87. return $content;
  88. }
  89. protected function renderMarketingListsList()
  90. {
  91. $colGroupContent = ZurmoHtml::openTag('colgroup');
  92. $colGroupContent .= ZurmoHtml::tag('col', array('style' => 'width:20%'));
  93. $colGroupContent .= ZurmoHtml::tag('col', array('style' => 'width:80%'));
  94. $colGroupContent .= ZurmoHtml::closeTag('colgroup');
  95. $rowsContentArray = array();
  96. foreach ($this->marketingLists as $marketingList)
  97. {
  98. $marketingListModel = $marketingList['model'];
  99. $subscribed = $marketingList['subscribed'];
  100. $columnsContent = ZurmoHtml::tag('td', array(), $this->renderToggleSubscriptionSwitch(
  101. $marketingListModel->id,
  102. $subscribed));
  103. $columnsContent .= ZurmoHtml::tag('td', array(), strval($marketingListModel));
  104. $rowsContentArray[] = ZurmoHtml::tag('tr', array(), $columnsContent);
  105. }
  106. $linkColumnsContent = ZurmoHtml::tag('td', array(), $this->renderUnsubscribeAllLink());
  107. $linkColumnsContent .= ZurmoHtml::tag('td');
  108. $rowsContentArray[] = ZurmoHtml::tag('tr', array(), $linkColumnsContent);
  109. $rowsContent = implode("\n", $rowsContentArray);
  110. $content = $colGroupContent . $rowsContent;
  111. $tableContent = ZurmoHtml::tag('table', array(), $content);
  112. return $tableContent;
  113. }
  114. protected function renderUnsubscribeAllLink()
  115. {
  116. $title = Zurmo::t('MarketingListsModule', 'Unsubscribe All/OptOut');
  117. $hash = Yii::app()->request->getQuery('hash');
  118. $url = Yii::app()->createUrl('/marketingLists/external/optOut', array('hash' => $hash));
  119. $options = array('class' => 'simple-link ' . static::TOGGLE_UNSUBSCRIPTION_LINK_CLASS);
  120. $link = ZurmoHtml::link($title, $url, $options);
  121. return $link;
  122. }
  123. protected function renderToggleSubscriptionSwitch($marketingListId, $subscribed)
  124. {
  125. $template = ZurmoHtml::tag('div', array('class' => 'switch-state clearfix'), '{input}{label}');
  126. $createNewActivity = false;
  127. if ($marketingListId == $this->sourceMarketingListId)
  128. {
  129. $createNewActivity = true;
  130. }
  131. $hash = GlobalMarketingFooterUtil::resolveHash($this->personId, $marketingListId,
  132. $this->modelId, $this->modelType, $createNewActivity);
  133. $subscribeUrl = $this->getSubscribeUrlByHash($hash);
  134. $unsubscribeUrl = $this->getUnsubscribeUrlByHash($hash);
  135. $checkedValue = $subscribeUrl;
  136. if (!$subscribed)
  137. {
  138. $checkedValue = $unsubscribeUrl;
  139. }
  140. $baseId = static::TOGGLE_UNSUBSCRIPTION_LINK_CLASS . '_' . $marketingListId;
  141. $content = ZurmoHTML::radioButtonList(
  142. $baseId,
  143. $checkedValue,
  144. self::getDropDownArray($subscribeUrl, $unsubscribeUrl),
  145. array('separator' => '', 'template' => $template));
  146. return ZurmoHtml::tag('div', array('class' => 'switch'), $content);
  147. }
  148. protected function getSubscribeUrlByHash($hash)
  149. {
  150. return $this->getSubscribeOrUnsubscribeUrlByHash($hash, 1);
  151. }
  152. protected function getUnsubscribeUrlByHash($hash)
  153. {
  154. return $this->getSubscribeOrUnsubscribeUrlByHash($hash, 0);
  155. }
  156. protected function getSubscribeOrUnsubscribeUrlByHash($hash, $subscribe = true)
  157. {
  158. $action = 'subscribe';
  159. if (!$subscribe)
  160. {
  161. $action = 'un' . $action;
  162. }
  163. return Yii::app()->createUrl('/marketingLists/external/' . $action, array('hash' => $hash));
  164. }
  165. public static function getDropDownArray($subscribeUrl, $unsubscribeUrl)
  166. {
  167. return array($subscribeUrl => Zurmo::t('Core', 'Subscribe'),
  168. $unsubscribeUrl => Zurmo::t('Core', 'Unsubcribe'));
  169. }
  170. protected function renderScripts()
  171. {
  172. $this->renderToggleUnsubscribeScript();
  173. }
  174. protected function renderToggleUnsubscribeScript()
  175. {
  176. $scriptName = static::TOGGLE_UNSUBSCRIPTION_LINK_CLASS;
  177. if (Yii::app()->clientScript->isScriptRegistered($scriptName))
  178. {
  179. return;
  180. }
  181. else
  182. {
  183. Yii::app()->clientScript->registerScript($scriptName, '
  184. $("input:radio").unbind("change.toggleUnsubscribe")
  185. .bind("change.toggleUnsubscribe", function (event)
  186. {
  187. window.location.href = ($(this)).val();
  188. });');
  189. }
  190. }
  191. }
  192. ?>