/admin/components/AAdminPortlet.php

https://github.com/joannalz/YiiBlocks · PHP · 130 lines · 62 code · 6 blank · 62 comment · 12 complexity · 9619cc6cc734db5ea191fab0977595a7 MD5 · raw file

  1. <?php
  2. Yii::import("zii.widgets.CPortlet");
  3. /**
  4. * A base class for admin portlets
  5. * @author Charles Pick
  6. * @package packages.admin.components
  7. */
  8. class AAdminPortlet extends CPortlet {
  9. /**
  10. * The tag name for the container
  11. * @var string
  12. */
  13. public $tagName = "article";
  14. /**
  15. * @var array the HTML attributes for the portlet container tag.
  16. */
  17. public $htmlOptions=array('class'=>'adminPortlet grid_12 alpha omega');
  18. /**
  19. * @var string the CSS class for the decoration container tag.
  20. */
  21. public $decorationCssClass='';
  22. /**
  23. * @var string the CSS class for the portlet title tag.
  24. */
  25. public $titleCssClass='';
  26. /**
  27. * @var string the CSS class for the content container tag. Defaults to 'content'.
  28. */
  29. public $contentCssClass='content';
  30. /**
  31. * An array of CMenu items to show in the header.
  32. * If this array is not set no menu will be shown
  33. * @var array
  34. */
  35. public $menuItems;
  36. /**
  37. * The configuration for the header menu, if shown
  38. * @var array
  39. */
  40. public $menuConfig = array("htmlOptions" => array("class" => "menu"));
  41. /**
  42. * An array of CMenu items to show in the sidebar.
  43. * If this array is not set no sidebar will be shown
  44. * @var array
  45. */
  46. public $sidebarMenuItems;
  47. /**
  48. * The configuration for the sidebar menu, if shown
  49. * @var array
  50. */
  51. public $sidebarMenuConfig = array("htmlOptions" => array("class" => "menu"));
  52. /**
  53. * The htmlOptions for the sidebar, if shown
  54. * @var array
  55. */
  56. public $sidebarHtmlOptions = array("class" => "sidebar");
  57. /**
  58. * Extra content to show in the sidebar, this will not be html encoded!
  59. * @var string
  60. */
  61. public $sidebarContent;
  62. private $_openTag;
  63. /**
  64. * Initializes the widget.
  65. * This renders the open tags needed by the portlet.
  66. * It also renders the decoration, if any.
  67. */
  68. public function init() {
  69. ob_start();
  70. ob_implicit_flush(false);
  71. $this->htmlOptions['id']=$this->getId();
  72. echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
  73. $this->renderDecoration();
  74. $this->renderSidebar();
  75. echo "<section class=\"{$this->contentCssClass}\">\n";
  76. $this->_openTag=ob_get_contents();
  77. ob_clean();
  78. }
  79. /**
  80. * Renders the content of the portlet.
  81. */
  82. public function run() {
  83. $this->renderContent();
  84. $content=ob_get_clean();
  85. if($this->hideOnEmpty && trim($content)==='')
  86. return;
  87. echo $this->_openTag;
  88. echo $content;
  89. echo "</section>\n";
  90. echo CHtml::closeTag($this->tagName);
  91. }
  92. /**
  93. * Shows a sidebar with menu and extra content if possible
  94. */
  95. protected function renderSidebar() {
  96. if ($this->sidebarContent == "" && (!is_array($this->sidebarMenuItems) || count($this->sidebarMenuItems) == 0)) {
  97. return;
  98. }
  99. echo CHtml::openTag("section",$this->sidebarHtmlOptions);
  100. if (is_array($this->sidebarMenuItems) && count($this->sidebarMenuItems)) {
  101. $menuConfig = $this->sidebarMenuConfig;
  102. $menuConfig['items'] = $this->sidebarMenuItems;
  103. $this->widget("zii.widgets.CMenu",$menuConfig);
  104. }
  105. echo "</section>\n";
  106. }
  107. /**
  108. * Renders the decoration for the portlet.
  109. * The default implementation will render the title if it is set.
  110. */
  111. protected function renderDecoration()
  112. {
  113. if($this->title!==null) {
  114. echo "<header class=\"{$this->decorationCssClass}\">\n";
  115. echo "<h1 class=\"{$this->titleCssClass}\">{$this->title}</h1>\n";
  116. if (is_array($this->menuItems) && count($this->menuItems)) {
  117. $menuConfig = $this->menuConfig;
  118. $menuConfig['items'] = $this->menuItems;
  119. $this->widget("zii.widgets.CMenu",$menuConfig);
  120. }
  121. echo "</header>\n";
  122. }
  123. }
  124. }