Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 48 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| OlzAuthorBadge | |
0.00% |
0 / 48 |
|
0.00% |
0 / 1 |
182 | |
0.00% |
0 / 1 |
| getHtml | |
0.00% |
0 / 48 |
|
0.00% |
0 / 1 |
182 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\News\Components\OlzAuthorBadge; |
| 4 | |
| 5 | use Olz\Components\Common\OlzComponent; |
| 6 | use Olz\Entity\Roles\Role; |
| 7 | use Olz\Entity\Users\User; |
| 8 | |
| 9 | /** |
| 10 | * @extends OlzComponent<array{ |
| 11 | * news_id: int, |
| 12 | * user?: ?User, |
| 13 | * role?: ?Role, |
| 14 | * name?: ?string, |
| 15 | * email?: ?string, |
| 16 | * mode?: ?('full'|'badge'|'text'), |
| 17 | * }> |
| 18 | */ |
| 19 | class OlzAuthorBadge extends OlzComponent { |
| 20 | public function getHtml(mixed $args): string { |
| 21 | $news_id = $args['news_id']; |
| 22 | $user = $args['user'] ?? null; |
| 23 | $role = $args['role'] ?? null; |
| 24 | $name = $args['name'] ?? null; |
| 25 | $email = $args['email'] ?? null; |
| 26 | $mode = $args['mode'] ?? 'full'; |
| 27 | |
| 28 | $code_href = $this->envUtils()->getCodeHref(); |
| 29 | |
| 30 | $icon = null; |
| 31 | $level = null; |
| 32 | $label = '?'; |
| 33 | $has_popup = false; |
| 34 | if ($user && $role) { |
| 35 | $icon = 'author_role_20.svg'; |
| 36 | $level = 'role'; |
| 37 | $label = "{$user->getFirstName()} {$user->getLastName()}, {$role->getName()}"; |
| 38 | $has_popup = true; |
| 39 | } elseif ($role) { |
| 40 | $icon = 'author_role_20.svg'; |
| 41 | $level = 'role'; |
| 42 | $label = "{$role->getName()}"; |
| 43 | $has_popup = true; |
| 44 | } elseif ($user) { |
| 45 | $level = 'user'; |
| 46 | $label = "{$user->getFirstName()} {$user->getLastName()}"; |
| 47 | $has_popup = true; |
| 48 | } |
| 49 | if ($name) { |
| 50 | $level = 'name'; |
| 51 | $label = $name; |
| 52 | if ($email) { |
| 53 | $has_popup = true; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | if (!$level) { |
| 58 | return ""; |
| 59 | } |
| 60 | |
| 61 | if ($mode === 'text') { |
| 62 | return $label; |
| 63 | } |
| 64 | |
| 65 | $popup_class = $has_popup ? 'has-popup' : 'no-popup'; |
| 66 | |
| 67 | $icon_html = $icon ? "<img src='{$code_href}assets/icns/{$icon}' alt='' class='author-icon'>" : ''; |
| 68 | $trigger = <<<ZZZZZZZZZZ |
| 69 | <span class='olz-author-badge level-{$level} {$popup_class}'> |
| 70 | {$label}{$icon_html} |
| 71 | </span> |
| 72 | ZZZZZZZZZZ; |
| 73 | if ($mode === 'badge') { |
| 74 | return $trigger; |
| 75 | } |
| 76 | if ($has_popup) { |
| 77 | return <<<ZZZZZZZZZZ |
| 78 | <a href='#' onclick='return olz.initOlzAuthorBadge({$news_id})'> |
| 79 | {$trigger} |
| 80 | </a> |
| 81 | ZZZZZZZZZZ; |
| 82 | } |
| 83 | return $trigger; |
| 84 | } |
| 85 | } |