Skip to content

Commit 48adeb0

Browse files
committed
some refactoring
1 parent f0fa5b2 commit 48adeb0

File tree

4 files changed

+60
-52
lines changed

4 files changed

+60
-52
lines changed

src/CardWidget.php

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ class CardWidget extends \yii\base\Widget
6666
*/
6767
public string $shadow = '';
6868

69+
/**
70+
* @var string
71+
*/
72+
protected string $content = '';
73+
6974
use CardToolsSupportTrait;
7075

7176
/**
@@ -85,12 +90,12 @@ public function init()
8590
*/
8691
public function run(): string
8792
{
93+
$this->content = ob_get_clean();
8894
$this->registerJs();
89-
$content = ob_get_clean();
90-
$html = Html::beginTag('div', ['class' => $this->getCardClass(), 'data-widget' => 'card-widget']);
95+
$html = Html::beginTag('div', ['class' => $this->getCardClass()]);
9196

9297
$html .= $this->getCardHeader();
93-
$html .= $this->getCardBody($content);
98+
$html .= $this->getCardBody();
9499
$html .= $this->getCardFooter();
95100

96101
if ($this->ajaxLoad) {
@@ -106,7 +111,7 @@ public function run(): string
106111
/**
107112
* @return string
108113
*/
109-
private function getCardHeader(): string
114+
protected function getCardHeader(): string
110115
{
111116
$html = Html::beginTag('div', ['class' => $this->getCardHeaderClass()]);
112117
$html .= $this->getCardTitle();
@@ -119,32 +124,31 @@ private function getCardHeader(): string
119124
/**
120125
* @return string
121126
*/
122-
private function getCardTitle(): string
127+
protected function getCardTitle(): string
123128
{
124129
return (!empty($this->title)) ? Html::tag('h3', Html::encode($this->title), ['class' => 'card-title']) : '';
125130
}
126131

127132
/**
128-
* @param string $content
129133
* @return string
130134
*/
131-
private function getCardBody(string $content = ''): string
135+
protected function getCardBody(): string
132136
{
133-
return (!empty($content)) ? Html::tag('div', $content, ['class' => $this->getCardBodyClass()]) : '';
137+
return (!empty($this->content)) ? Html::tag('div', $this->content, ['class' => $this->getCardBodyClass()]) : '';
134138
}
135139

136140
/**
137141
* @return string
138142
*/
139-
private function getCardFooter(): string
143+
protected function getCardFooter(): string
140144
{
141145
return (!empty($this->footer)) ? Html::tag('div', $this->footer, ['class' => $this->getCardFooterClass()]) : '';
142146
}
143147

144148
/**
145149
* @return string
146150
*/
147-
private function getCardClass(): string
151+
protected function getCardClass(): string
148152
{
149153
$class = "card";
150154

@@ -161,41 +165,41 @@ private function getCardClass(): string
161165
/**
162166
* @return string
163167
*/
164-
private function getCardHeaderClass(): string
168+
protected function getCardHeaderClass(): string
165169
{
166170
return 'card-header';
167171
}
168172

169173
/**
170174
* @return string
171175
*/
172-
private function getCardBodyClass(): string
176+
protected function getCardBodyClass(): string
173177
{
174178
return 'card-body';
175179
}
176180

177181
/**
178182
* @return string
179183
*/
180-
private function getCardFooterClass(): string
184+
protected function getCardFooterClass(): string
181185
{
182186
return 'card-footer';
183187
}
184188

185189
/**
186190
* @return void
187191
*/
188-
private function registerJs(): void
192+
protected function registerJs(): void
189193
{
190194
if ($this->ajaxLoad) {
191195
$this->view->registerJs("
192-
$.each($('[data-ajax-load-url]'), function(i, el) {
193-
let url = $(el).attr('data-ajax-load-url');
194-
$(el).siblings('.card-body').load(url, function() {
195-
$(el).remove();
196-
});
197-
});
198-
", View::POS_READY, 'ajaxLoad');
196+
$.each($('[data-ajax-load-url]'), function(i, el) {
197+
let url = $(el).attr('data-ajax-load-url');
198+
$(el).siblings('.card-body').load(url, function() {
199+
$(el).remove();
200+
});
201+
});
202+
", View::POS_READY, 'ajaxLoad');
199203
}
200204
}
201205
}

src/ContactCardWidget.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function run(): string
110110
/**
111111
* @return string
112112
*/
113-
private function getCardHeader(): string
113+
protected function getCardHeader(): string
114114
{
115115
$html = Html::beginTag('div', ['class' => $this->getCardHeaderClass()]);
116116
$html .= $this->getCardTitle();
@@ -123,7 +123,7 @@ private function getCardHeader(): string
123123
/**
124124
* @return string
125125
*/
126-
private function getCardTitle(): string
126+
protected function getCardTitle(): string
127127
{
128128
return (!empty($this->position)) ? Html::encode($this->position) : '';
129129
}
@@ -132,7 +132,7 @@ private function getCardTitle(): string
132132
* @param string $content
133133
* @return string
134134
*/
135-
private function getCardBody(string $content = ''): string
135+
protected function getCardBody(string $content = ''): string
136136
{
137137
$inner = Html::tag('b', Html::encode($this->name));
138138
$html = (!empty($this->name)) ? Html::tag('h2', $inner, ['class' => 'lead']) : '';
@@ -150,7 +150,7 @@ private function getCardBody(string $content = ''): string
150150
/**
151151
* @return string
152152
*/
153-
private function getCardFooter(): string
153+
protected function getCardFooter(): string
154154
{
155155
if (empty($this->footer)) return '';
156156

@@ -170,7 +170,7 @@ private function getCardFooter(): string
170170
/**
171171
* @return string
172172
*/
173-
private function getUserImage(): string
173+
protected function getUserImage(): string
174174
{
175175
if (empty($this->image)) return '';
176176

@@ -182,7 +182,7 @@ private function getUserImage(): string
182182
/**
183183
* @return string
184184
*/
185-
private function getUserAbout(): string
185+
protected function getUserAbout(): string
186186
{
187187
if (empty($this->about)) return '';
188188

@@ -200,7 +200,7 @@ private function getUserAbout(): string
200200
/**
201201
* @return string
202202
*/
203-
private function getUserInfo(): string
203+
protected function getUserInfo(): string
204204
{
205205
$html = '';
206206

@@ -222,7 +222,7 @@ private function getUserInfo(): string
222222
/**
223223
* @return string
224224
*/
225-
private function getCardClass(): string
225+
protected function getCardClass(): string
226226
{
227227
$class = 'card d-flex flex-fill';
228228

@@ -237,23 +237,23 @@ private function getCardClass(): string
237237
/**
238238
* @return string
239239
*/
240-
private function getCardHeaderClass(): string
240+
protected function getCardHeaderClass(): string
241241
{
242242
return 'card-header text-muted border-bottom-0';
243243
}
244244

245245
/**
246246
* @return string
247247
*/
248-
private function getCardBodyClass(): string
248+
protected function getCardBodyClass(): string
249249
{
250250
return 'card-body pt-0';
251251
}
252252

253253
/**
254254
* @return string
255255
*/
256-
private function getCardFooterClass(): string
256+
protected function getCardFooterClass(): string
257257
{
258258
return 'card-footer';
259259
}

src/ProfileCardWidget.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ class ProfileCardWidget extends \yii\base\Widget
6363
*/
6464
public array $rows = [];
6565

66+
/**
67+
* @var string
68+
*/
69+
protected string $content = '';
70+
6671
/**
6772
* @return void
6873
*/
@@ -78,10 +83,10 @@ public function init()
7883
*/
7984
public function run(): string
8085
{
81-
$content = ob_get_clean();
86+
$this->content = ob_get_clean();
8287
$html = Html::beginTag('div', ['class' => $this->getCardClass()]);
8388

84-
$html .= $this->getCardBody($content);
89+
$html .= $this->getCardBody();
8590
$html .= $this->getCardFooter();
8691

8792
$html .= Html::endTag('div'); // the end of a card
@@ -90,33 +95,32 @@ public function run(): string
9095
}
9196

9297
/**
93-
* @param string $content
9498
* @return string
9599
*/
96-
private function getCardBody(string $content = ''): string
100+
protected function getCardBody(): string
97101
{
98102
$html = $this->getUserImage();
99103
$html .= (!empty($this->name)) ? Html::tag('h3', Html::encode($this->name), ['class' => 'profile-username text-center']) : '';
100104
$html .= (!empty($this->position)) ? Html::tag('p', Html::encode($this->position), ['class' => 'text-muted text-center']) : '';
101105
$html .= (!empty($this->rows)) ? $this->getCardRows() : '';
102106

103-
$html .= $content;
107+
$html .= $this->content;
104108

105109
return Html::tag('div', $html, ['class' => $this->getCardBodyClass()]);
106110
}
107111

108112
/**
109113
* @return string
110114
*/
111-
private function getCardFooter(): string
115+
protected function getCardFooter(): string
112116
{
113117
return (!empty($this->footer)) ? Html::tag('div', $this->footer, ['class' => $this->getCardFooterClass()]) : '';
114118
}
115119

116120
/**
117121
* @return string
118122
*/
119-
private function getUserImage(): string
123+
protected function getUserImage(): string
120124
{
121125
if (empty($this->image)) return '';
122126

@@ -128,7 +132,7 @@ private function getUserImage(): string
128132
/**
129133
* @return string
130134
*/
131-
private function getCardRows(): string
135+
protected function getCardRows(): string
132136
{
133137
$html = '';
134138

@@ -144,7 +148,7 @@ private function getCardRows(): string
144148
/**
145149
* @return string
146150
*/
147-
private function getCardClass(): string
151+
protected function getCardClass(): string
148152
{
149153
$class = "card";
150154

@@ -157,15 +161,15 @@ private function getCardClass(): string
157161
/**
158162
* @return string
159163
*/
160-
private function getCardBodyClass(): string
164+
protected function getCardBodyClass(): string
161165
{
162166
return 'card-body box-profile';
163167
}
164168

165169
/**
166170
* @return string
167171
*/
168-
private function getCardFooterClass(): string
172+
protected function getCardFooterClass(): string
169173
{
170174
return 'card-footer';
171175
}

0 commit comments

Comments
 (0)