-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCard.php
166 lines (155 loc) · 3.78 KB
/
Card.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
/**
* Created by PhpStorm.
* User: p0larbeer
* Date: 10.07.15
* Time: 12:37
*/
namespace webmaxx\materialize;
use yii\helpers\Html;
/**
* Button renders a materialize button.
*
* For example,
*
* ```php
* echo Card::widget([
* 'title' => 'Title',
* 'content' => 'Content',
* ]);
* ```
* @see http://materializecss.com/cards.html
* @author p0larbeer
* @since 2.0
*/
class Card extends Widget
{
/**
* @var string src for render image block
*/
public $image;
/**
* @var string the title of card
*/
public $title;
/**
* @var boolean whether to show title section. *
*/
public $renderTitle = true;
/**
* @var string html code to render on content block of card
*/
public $content;
/**
* @var string html code to render on action block of card;
*/
public $action;
/**
* @var boolean whether the content should be HTML-encoded.
*/
public $encodeContent = true;
/**
* @var boolean whether the action should be HTML-encoded.
*/
public $encodeAction = true;
/**
* @var boolean whether the title should be HTML-encoded.
*/
public $encodeTitle = true;
/**
* @var string default css class for card
*/
public $defaultClass = 'card';
/**
* Initializes the widget.
* If you override this method, make sure you call the parent implementation first.
*/
public function init()
{
parent::init();
$this->clientOptions = false;
if ($this->defaultClass)
Html::addCssClass($this->options, $this->defaultClass);
}
/**
* Renders the widget.
*/
public function run()
{
//return Html::tag($this->tagName, $this->encodeLabel ? Html::encode($this->label) : $this->label, $this->options);
$html = '';
if ($this->image !== null) {
$html .= $this->renderImage();
}
if ($this->content !== null) {
$html .= $this->renderContent();
}
if ($this->action !== null) {
$html .= $this->renderAction();
}
if ($this->defaultClass) {
Html::addCssClass($this->options, $this->defaultClass);
}
return Html::tag('div', $html, $this->options);
}
/**
* Renders the title.
* @return string the rendering result.
*/
public function renderTitle()
{
return Html::tag(
'span',
$this->encodeTitle ? Html::encode($this->title) : $this->title,
['class' => 'card-title']
);
}
/**
* Renders the action.
* @return string the rendering result.
*/
public function renderAction()
{
return Html::tag(
'div',
$this->encodeAction ? Html::encode($this->action) : $this->action,
['class' => 'card-action']
);
}
/**
* Renders the image.
* @return string the rendering result.
*/
public function renderImage()
{
$html = Html::img($this->image);
if ($this->renderTitle) {
$html .= $this->renderTitle();
}
return Html::tag(
'div',
$html,
['class' => 'card-image']
);
}
/**
* Renders the content.
* @return string the rendering result.
*/
public function renderContent()
{
if ($this->renderTitle) {
$this->encodeContent = false;
}
if ($this->image === null) {
$title = $this->renderTitle();
} else {
$title = '';
}
return Html::tag(
'div',
$this->encodeContent ? Html::encode($title . $this->content) : $title . $this->content,
['class' => 'card-content']
);
}
}