PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/app/protected/core/views/PortletFrameView.php

https://bitbucket.org/andreustimm/zurmo
PHP | 153 lines | 108 code | 8 blank | 37 comment | 3 complexity | 6d5254dceb8434866a51d66f40bc83f0 MD5 | raw file
Possible License(s): 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. * The base View for a portletframe view
  38. */
  39. abstract class PortletFrameView extends MetadataView
  40. {
  41. protected $portlets;
  42. protected $uniqueLayoutId;
  43. protected $params;
  44. protected $layoutType;
  45. public function __construct($controllerId, $moduleId, $modelId, $params)
  46. {
  47. $this->controllerId = $controllerId;
  48. $this->moduleId = $moduleId;
  49. $this->modelId = $modelId;
  50. $this->uniqueLayoutId = get_class($this);
  51. $this->params = $params;
  52. }
  53. protected function renderContent()
  54. {
  55. $this->portlets = $this->getPortlets($this->uniqueLayoutId, self::getMetadata());
  56. return $this->renderPortlets($this->uniqueLayoutId);
  57. }
  58. protected function getPortlets($uniqueLayoutId, $metadata)
  59. {
  60. assert('is_string($uniqueLayoutId)');
  61. assert('is_array($metadata)');
  62. $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition($uniqueLayoutId, Yii::app()->user->userModel->id, $this->params);
  63. if (empty($portlets))
  64. {
  65. $portlets = Portlet::makePortletsUsingMetadataSortedByColumnIdAndPosition($uniqueLayoutId, $metadata, Yii::app()->user->userModel, $this->params);
  66. Portlet::savePortlets($portlets);
  67. }
  68. return $portlets;
  69. }
  70. protected function renderPortlets($uniqueLayoutId, $portletsAreCollapsible = true, $portletsAreMovable = true, $portletsAreRemovable = true)
  71. {
  72. assert('is_string($uniqueLayoutId)');
  73. assert('is_bool($portletsAreCollapsible)');
  74. assert('is_bool($portletsAreMovable)');
  75. assert('is_bool($portletsAreRemovable)');
  76. $juiPortletsWidgetItems = array();
  77. foreach ($this->portlets as $column => $columnPortlets)
  78. {
  79. foreach ($columnPortlets as $position => $portlet)
  80. {
  81. $className = get_class($portlet->getView());
  82. if (method_exists($className, 'canUserRemove'))
  83. {
  84. $removable = $className::canUserRemove();
  85. }
  86. else
  87. {
  88. $removable = $portletsAreRemovable;
  89. }
  90. $additionalOptionMenuItems = array();
  91. if (method_exists($className, 'getAdditionalOptionMenuItems'))
  92. {
  93. $additionalOptionMenuItems = $className::getAdditionalOptionMenuItems();
  94. }
  95. $juiPortletsWidgetItems[$column][$position] = array(
  96. 'id' => $portlet->id,
  97. 'uniqueId' => $portlet->getUniquePortletPageId(),
  98. 'title' => $portlet->getTitle(),
  99. 'content' => $portlet->renderContent(),
  100. 'headContent' => $portlet->renderHeadContent(),
  101. 'editable' => $portlet->isEditable(),
  102. 'collapsed' => $portlet->collapsed,
  103. 'removable' => $removable,
  104. 'uniqueClass' => $this->resolveUniqueClass($portlet),
  105. 'portletParams' => $portlet->getPortletParams(),
  106. 'additionalOptionMenuItems' => $additionalOptionMenuItems,
  107. );
  108. }
  109. }
  110. $cClipWidget = new CClipWidget();
  111. $cClipWidget->beginClip("JuiPortlets");
  112. $cClipWidget->widget('application.core.widgets.JuiPortlets', array(
  113. 'uniqueLayoutId' => $uniqueLayoutId,
  114. 'moduleId' => $this->moduleId,
  115. 'saveUrl' => Yii::app()->createUrl($this->moduleId . '/defaultPortlet/SaveLayout'),
  116. 'layoutType' => $this->getLayoutType(),
  117. 'items' => $juiPortletsWidgetItems,
  118. 'collapsible' => $portletsAreCollapsible,
  119. 'movable' => $portletsAreMovable,
  120. ));
  121. $cClipWidget->endClip();
  122. return $cClipWidget->getController()->clips['JuiPortlets'];
  123. }
  124. protected function resolveUniqueClass(Portlet $portlet)
  125. {
  126. $content = null;
  127. $content .= get_class($portlet->getView());
  128. foreach ($portlet->getCssClasses() as $cssClass)
  129. {
  130. $content .= ' ' . $cssClass;
  131. }
  132. $portletRules = PortletRulesFactory::createPortletRulesByView(get_class($portlet->getView()));
  133. $content .= ' ' . $portletRules->resolveIconTypeName();
  134. return $content;
  135. }
  136. protected function getLayoutType()
  137. {
  138. return $this->layoutType;
  139. }
  140. protected function arePortletsRemovable()
  141. {
  142. return true;
  143. }
  144. }
  145. ?>