Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 126 lines (118 sloc) 3.408 kB
44bbab5 merged zii repository into yii.
qiang.xue authored
1 <?php
2 /**
3 * CPortlet class file.
4 *
5 * @author Qiang Xue <qiang.xue@gmail.com>
6 * @link http://www.yiiframework.com/
4be0af6 changed copyright year.
qiang.xue authored
7 * @copyright Copyright &copy; 2008-2011 Yii Software LLC
44bbab5 merged zii repository into yii.
qiang.xue authored
8 * @license http://www.yiiframework.com/license/
9 */
10
11 /**
12 * CPortlet is the base class for portlet widgets.
13 *
14 * A portlet displays a fragment of content, usually in terms of a block
15 * on the side bars of a Web page.
16 *
17 * To specify the content of the portlet, override the {@link renderContent}
18 * method, or insert the content code between the {@link CController::beginWidget}
19 * and {@link CController::endWidget} calls. For example,
20 *
21 * <pre>
7e59d2c doc fix.
qiang.xue authored
22 * <?php $this->beginWidget('zii.widgets.CPortlet'); ?>
44bbab5 merged zii repository into yii.
qiang.xue authored
23 * ...insert content here...
7e59d2c doc fix.
qiang.xue authored
24 * <?php $this->endWidget(); ?>
44bbab5 merged zii repository into yii.
qiang.xue authored
25 * </pre>
26 *
27 * A portlet also has an optional {@link title}. One may also override {@link renderDecoration}
28 * to further customize the decorative display of a portlet (e.g. adding min/max buttons).
29 *
30 * @author Qiang Xue <qiang.xue@gmail.com>
31 * @version $Id$
32 * @package zii.widgets
33 * @since 1.1
34 */
35 class CPortlet extends CWidget
36 {
37 /**
38 * @var string the tag name for the portlet container tag. Defaults to 'div'.
39 */
40 public $tagName='div';
41 /**
42 * @var array the HTML attributes for the portlet container tag.
43 */
44 public $htmlOptions=array('class'=>'portlet');
45 /**
46 * @var string the title of the portlet. Defaults to null.
47 * When this is not set, Decoration will not be displayed.
48 * Note that the title will not be HTML-encoded when rendering.
49 */
50 public $title;
51 /**
52 * @var string the CSS class for the decoration container tag. Defaults to 'portlet-decoration'.
53 */
54 public $decorationCssClass='portlet-decoration';
55 /**
56 * @var string the CSS class for the portlet title tag. Defaults to 'portlet-title'.
57 */
58 public $titleCssClass='portlet-title';
59 /**
60 * @var string the CSS class for the content container tag. Defaults to 'portlet-content'.
61 */
62 public $contentCssClass='portlet-content';
63 /**
64 * @var boolean whether to hide the portlet when the body content is empty. Defaults to true.
65 * @since 1.1.4
66 */
67 public $hideOnEmpty=true;
68
69 private $_openTag;
70
71 /**
72 * Initializes the widget.
73 * This renders the open tags needed by the portlet.
74 * It also renders the decoration, if any.
75 */
76 public function init()
77 {
78 ob_start();
79 ob_implicit_flush(false);
80
81 $this->htmlOptions['id']=$this->getId();
82 echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
83 $this->renderDecoration();
84 echo "<div class=\"{$this->contentCssClass}\">\n";
85
86 $this->_openTag=ob_get_contents();
87 ob_clean();
88 }
89
90 /**
91 * Renders the content of the portlet.
92 */
93 public function run()
94 {
95 $this->renderContent();
96 $content=ob_get_clean();
97 if($this->hideOnEmpty && trim($content)==='')
98 return;
99 echo $this->_openTag;
100 echo $content;
101 echo "</div>\n";
102 echo CHtml::closeTag($this->tagName);
103 }
104
105 /**
106 * Renders the decoration for the portlet.
107 * The default implementation will render the title if it is set.
108 */
109 protected function renderDecoration()
110 {
111 if($this->title!==null)
112 {
113 echo "<div class=\"{$this->decorationCssClass}\">\n";
114 echo "<div class=\"{$this->titleCssClass}\">{$this->title}</div>\n";
115 echo "</div>\n";
116 }
117 }
118
119 /**
120 * Renders the content of the portlet.
121 * Child classes should override this method to render the actual content.
122 */
123 protected function renderContent()
124 {
125 }
126 }
Something went wrong with that request. Please try again.