Skip to content

Commit 454dada

Browse files
committed
refactor userstats
1 parent 8d4ba45 commit 454dada

File tree

1 file changed

+17
-38
lines changed

1 file changed

+17
-38
lines changed

classes/tables/userstats_table.php

+17-38
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,7 @@ public function col_username($row) {
331331
* @return string
332332
*/
333333
public function col_receivedupvotes($row) {
334-
if ($row->receivedupvotes > 0) {
335-
return \html_writer::tag('h5', \html_writer::start_span('badge badge-success') .
336-
$row->receivedupvotes . \html_writer::end_span());
337-
} else {
338-
return \html_writer::tag('h5', \html_writer::start_span('badge badge-warning') .
339-
$row->receivedupvotes . \html_writer::end_span());
340-
}
334+
return $this->badge_render($row->receivedupvotes);
341335
}
342336

343337
/**
@@ -346,13 +340,7 @@ public function col_receivedupvotes($row) {
346340
* @return string
347341
*/
348342
public function col_receiveddownvotes($row) {
349-
if ($row->receiveddownvotes > 0) {
350-
return \html_writer::tag('h5', \html_writer::start_span('badge badge-success') .
351-
$row->receiveddownvotes . \html_writer::end_span());
352-
} else {
353-
return \html_writer::tag('h5', \html_writer::start_span('badge badge-warning') .
354-
$row->receiveddownvotes . \html_writer::end_span());
355-
}
343+
return $this->badge_render($row->receiveddownvotes);
356344
}
357345

358346
/**
@@ -361,13 +349,7 @@ public function col_receiveddownvotes($row) {
361349
* @return string
362350
*/
363351
public function col_forumactivity($row) {
364-
if ($row->forumactivity > 0) {
365-
return \html_writer::tag('h5', \html_writer::start_span('badge badge-success') .
366-
$row->forumactivity . \html_writer::end_span());
367-
} else {
368-
return \html_writer::tag('h5', \html_writer::start_span('badge badge-warning') .
369-
$row->forumactivity . \html_writer::end_span());
370-
}
352+
return $this->badge_render($row->forumactivity);
371353
}
372354

373355
/**
@@ -376,13 +358,7 @@ public function col_forumactivity($row) {
376358
* @return string
377359
*/
378360
public function col_forumreputation($row) {
379-
if ($row->forumreputation > 0) {
380-
return \html_writer::tag('h5', \html_writer::start_span('badge badge-success') .
381-
$row->forumreputation . \html_writer::end_span());
382-
} else {
383-
return \html_writer::tag('h5', \html_writer::start_span('badge badge-warning') .
384-
$row->forumreputation . \html_writer::end_span());
385-
}
361+
return $this->badge_render($row->forumreputation);
386362
}
387363

388364
/**
@@ -391,13 +367,7 @@ public function col_forumreputation($row) {
391367
* @return string
392368
*/
393369
public function col_courseactivity($row) {
394-
if ($row->courseactivity > 0) {
395-
return \html_writer::tag('h5', \html_writer::start_span('badge badge-success') .
396-
$row->courseactivity . \html_writer::end_span());
397-
} else {
398-
return \html_writer::tag('h5', \html_writer::start_span('badge badge-warning') .
399-
$row->courseactivity . \html_writer::end_span());
400-
}
370+
return $this->badge_render($row->courseactivity);
401371
}
402372

403373
/**
@@ -406,12 +376,21 @@ public function col_courseactivity($row) {
406376
* @return string
407377
*/
408378
public function col_coursereputation($row) {
409-
if ($row->coursereputation > 0) {
379+
return $this->badge_render($row->coursereputation);
380+
}
381+
382+
/**
383+
* Dependeng on the value display success or warning badge.
384+
* @param int $number
385+
* @return string
386+
*/
387+
private function badge_render($number) {
388+
if ($number > 0) {
410389
return \html_writer::tag('h5', \html_writer::start_span('badge badge-success') .
411-
$row->coursereputation . \html_writer::end_span());
390+
$number . \html_writer::end_span());
412391
} else {
413392
return \html_writer::tag('h5', \html_writer::start_span('badge badge-warning') .
414-
$row->coursereputation . \html_writer::end_span());
393+
$number . \html_writer::end_span());
415394
}
416395
}
417396
/**

0 commit comments

Comments
 (0)