PageRenderTime 51ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins_repo/openXMarket/www/admin/plugins/oxMarket/library/OX/oxMarket/UI/EntityScreenManager.php

https://bitbucket.org/valmy/openx
PHP | 252 lines | 163 code | 47 blank | 42 comment | 14 complexity | ace82e641ba5928e9f500b69bd021dfd MD5 | raw file
  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v2.8 |
  5. | ========== |
  6. | |
  7. | Copyright (c) 2003-2009 OpenX Limited |
  8. | For contact details, see: http://www.openx.org/ |
  9. | |
  10. | This program is free software; you can redistribute it and/or modify |
  11. | it under the terms of the GNU General Public License as published by |
  12. | the Free Software Foundation; either version 2 of the License, or |
  13. | (at your option) any later version. |
  14. | |
  15. | This program is distributed in the hope that it will be useful, |
  16. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  17. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  18. | GNU General Public License for more details. |
  19. | |
  20. | You should have received a copy of the GNU General Public License |
  21. | along with this program; if not, write to the Free Software |
  22. | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
  23. +---------------------------------------------------------------------------+
  24. $Id:$
  25. */
  26. require_once OX_MARKET_LIB_PATH . '/OX/oxMarket/Dal/Advertiser.php';
  27. /**
  28. * A listener of UI events. eg. renders additional content before campaign list.
  29. */
  30. class OX_oxMarket_UI_EntityScreenManager
  31. {
  32. /**
  33. * Bacl reference market component
  34. *
  35. * @var Plugins_admin_oxMarket_oxMarket
  36. */
  37. private $oMarketComponent;
  38. public function __construct(Plugins_admin_oxMarket_oxMarket $oMarketComponent)
  39. {
  40. $this->oMarketComponent = $oMarketComponent;
  41. }
  42. public function beforePageHeader(OX_Admin_UI_Event_EventContext $oEventContext)
  43. {
  44. $pageId = $oEventContext->data['pageId'];
  45. $pageData = $oEventContext->data['pageData'];
  46. $oHeaderModel = $oEventContext->data['headerModel'];
  47. $oEntityHelper = $this->oMarketComponent->getEntityHelper();
  48. $oUI = OA_Admin_UI::getInstance();
  49. switch($pageId) {
  50. case 'advertiser-index': {
  51. $oUI->registerStylesheetFile(MAX::constructURL(MAX_URL_ADMIN,
  52. 'plugins/oxMarket/css/ox.market.css.php?v=' . htmlspecialchars($this->oMarketComponent->getPluginVersion()) . '&b=' . $this->oMarketComponent->aBranding['key']));
  53. break;
  54. }
  55. case 'advertiser-campaigns': {
  56. $oUI->registerStylesheetFile(MAX::constructURL(MAX_URL_ADMIN,
  57. 'plugins/oxMarket/css/ox.market.css.php?v=' . htmlspecialchars($this->oMarketComponent->getPluginVersion()) . '&b=' . $this->oMarketComponent->aBranding['key']));
  58. if (isset($oHeaderModel) && $oEntityHelper->isMarketAdvertiser($pageData['clientid'])) {
  59. $oHeaderModel->setIconClass('iconCampaignsSystemLarge');
  60. }
  61. break;
  62. }
  63. case 'market-campaign-edit_new': {
  64. if (isset($oHeaderModel)) {
  65. $oHeaderModel->setIconClass('iconCampaignSystemAddLarge');
  66. }
  67. break;
  68. }
  69. case 'market-campaign-edit':
  70. case 'market-campaign-acl': {
  71. if (isset($oHeaderModel)) {
  72. $oHeaderModel->setIconClass('iconCampaignSystemLarge');
  73. }
  74. break;
  75. }
  76. case 'campaign-zone': {
  77. if (isset($oHeaderModel) && $oEntityHelper->isMarketAdvertiser($pageData['clientid'])) {
  78. $oHeaderModel->setIconClass('iconCampaignSystemLarge');
  79. }
  80. break;
  81. }
  82. case 'campaign-edit' :
  83. case 'campaign-edit_new': {
  84. $hasMarket = $oEntityHelper->isMarketAdvertiser($pageData['clientid']);
  85. if (!($hasMarket)) { //only redirect to proper screens if it is market
  86. break;
  87. }
  88. OX_Admin_Redirect::redirect('plugins/' . $this->oMarketComponent->group
  89. . '/market-campaign-edit.php?clientid='.$pageData['clientid']
  90. .'&campaignid='.$pageData['campaignid']);
  91. break;
  92. }
  93. }
  94. }
  95. public function beforeContent(OX_Admin_UI_Event_EventContext $oEventContext)
  96. {
  97. $pageId = $oEventContext->data['pageId'];
  98. $pageData = $oEventContext->data['pageData'];
  99. $smarty = $oEventContext->data['oTpl'];
  100. $result = '';
  101. switch($pageId) {
  102. case 'advertiser-campaigns': {
  103. $result = $this->advertiserCampaignsBeforeContent($pageData, $smarty);
  104. break;
  105. }
  106. }
  107. return $result;
  108. }
  109. public function afterContent(OX_Admin_UI_Event_EventContext $oEventContext)
  110. {
  111. $pageId = $oEventContext->data['pageId'];
  112. $pageData = $oEventContext->data['pageData'];
  113. $smarty = $oEventContext->data['oTpl'];
  114. $result = '';
  115. switch($pageId) {
  116. case 'campaign-zone' : {
  117. if ($this->oMarketComponent->getEntityHelper()->isMarketCampaign($pageData['campaignId'])) {
  118. $result = $this->campaignZoneAfterContent($pageData, $smarty);
  119. }
  120. break;
  121. }
  122. case 'advertiser-index' : {
  123. $result = $this->advertiserIndexAfterContent($pageData, $smarty);
  124. break;
  125. }
  126. case 'advertiser-campaigns': {
  127. $result = $this->advertiserCampaignsAfterContent($pageData, $smarty);
  128. break;
  129. }
  130. }
  131. return $result;
  132. }
  133. protected function campaignZoneAfterContent($pageData, $smarty)
  134. {
  135. $oTpl = new OA_Plugin_Template('fragment-campaign-zone.html','oxMarket');
  136. $oTpl->assign('after', true);
  137. $oTpl->assign('aBranding', $this->oMarketComponent->aBranding);
  138. return $oTpl->toString();
  139. }
  140. protected function advertiserIndexAfterContent($pageData, $smarty)
  141. {
  142. $oTpl = new OA_Plugin_Template('fragment-advertiser-index.html','oxMarket');
  143. //retrieve alternative content if any
  144. $aContentKeys = $this->oMarketComponent->retrieveCustomContent('market-advertiser-index');
  145. if (!$aContentKeys) {
  146. $aContentKeys = array();
  147. }
  148. $content = $aContentKeys['content-bottom'];
  149. $oPreferenceDal = $this->oMarketComponent->getPreferenceManager();
  150. $infoShown = $oPreferenceDal->getMarketUserVariable('advertiser_index_market_info_shown_to_user');
  151. $showInfo = !isset($infoShown) || !$infoShown;
  152. if ($showInfo) {
  153. $oPreferenceDal->setMarketUserVariable('advertiser_index_market_info_shown_to_user', '1');
  154. }
  155. $dalAdvertiser = new OX_oxMarket_Dal_Advertiser();
  156. $agency_id = OA_Permission::getEntityId();
  157. $oAdvertiser = $dalAdvertiser->getMarketAdvertiser($agency_id);
  158. $marketClientId = $oAdvertiser->clientid;
  159. $oTpl->assign('marketClientId', $marketClientId);
  160. $oTpl->assign('content', $content);
  161. $oTpl->assign('showMarketInfo', $showInfo);
  162. $oTpl->assign('aBranding', $this->oMarketComponent->aBranding);
  163. return $oTpl->toString();
  164. }
  165. /*
  166. * A view listener function that inserts some market content on campaigns
  167. * screen only if current advertiser is OpenX Market.
  168. */
  169. protected function advertiserCampaignsBeforeContent($pageData, $smarty)
  170. {
  171. $oEntityHelper = $this->oMarketComponent->getEntityHelper();
  172. $hasMarket = $oEntityHelper->isMarketAdvertiser($pageData['advertiserId']);
  173. if (!($hasMarket)) { //only default system campaign screen will be modified
  174. return null;
  175. }
  176. //retrieve alternative content if any
  177. $aContentKeys = $this->oMarketComponent->retrieveCustomContent('market-advertiser-campaigns');
  178. if (!$aContentKeys) {
  179. $aContentKeys = array();
  180. }
  181. $content = $aContentKeys['content-top'];
  182. $oTpl = new OA_Plugin_Template('fragment-advertiser-campaigns.html','oxMarket');
  183. $oTpl->assign('content', $content);
  184. $oTpl->assign('before', true);
  185. $oTpl->assign('aBranding', $this->oMarketComponent->aBranding);
  186. return $oTpl->toString();
  187. }
  188. /*
  189. * A view listener function that inserts some market content on campaigns
  190. * screen only if current advertiser is OpenX Market.
  191. */
  192. protected function advertiserCampaignsAfterContent($pageData, $smarty)
  193. {
  194. $oEntityHelper = $this->oMarketComponent->getEntityHelper();
  195. $hasMarket = $oEntityHelper->isMarketAdvertiser($pageData['advertiserId']);
  196. if (!($hasMarket)) { //only default system campaign screen will be modified
  197. return null;
  198. }
  199. $oTpl = new OA_Plugin_Template('fragment-advertiser-campaigns.html','oxMarket');
  200. $oTpl->assign('content', $content);
  201. $oTpl->assign('after', true);
  202. $oTpl->assign('aBranding', $this->oMarketComponent->aBranding);
  203. return $oTpl->toString();
  204. }
  205. }