| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace UserAccessManager\Controller\Backend; |
| 6 |
|
| 7 |
/** |
| 8 |
* Trait ControllerTabNavigationTrait |
| 9 |
* |
| 10 |
* @package UserAccessManager\Controller |
| 11 |
*/ |
| 12 |
trait ControllerTabNavigationTrait |
| 13 |
{ |
| 14 |
abstract public function getRequestUrl(): string; |
| 15 |
|
| 16 |
abstract public function getRequestParameter(string $name, $default = null): mixed; |
| 17 |
|
| 18 |
abstract public function getGroupText(string $key): string; |
| 19 |
|
| 20 |
abstract public function getGroupSectionText(string $key): string; |
| 21 |
|
| 22 |
abstract public function getTabGroups(): array; |
| 23 |
|
| 24 |
public function getCurrentTabGroup(): string |
| 25 |
{ |
| 26 |
$groups = $this->getTabGroups(); |
| 27 |
$keys = array_keys($groups); |
| 28 |
|
| 29 |
return (string) $this->getRequestParameter('tab_group', reset($keys)); |
| 30 |
} |
| 31 |
|
| 32 |
public function getSections(): array |
| 33 |
{ |
| 34 |
$groups = $this->getTabGroups(); |
| 35 |
$group = $this->getCurrentTabGroup(); |
| 36 |
|
| 37 |
return isset($groups[$group]) === true ? $groups[$group] : []; |
| 38 |
} |
| 39 |
|
| 40 |
public function getCurrentTabGroupSection(): string |
| 41 |
{ |
| 42 |
$groups = $this->getTabGroups(); |
| 43 |
$group = $this->getCurrentTabGroup(); |
| 44 |
|
| 45 |
if (isset($groups[$group]) === true) { |
| 46 |
$default = reset($groups[$group]); |
| 47 |
} else { |
| 48 |
$firstGroup = reset($groups); |
| 49 |
$default = reset($firstGroup); |
| 50 |
} |
| 51 |
|
| 52 |
return (string) $this->getRequestParameter('tab_group_section', $default); |
| 53 |
} |
| 54 |
|
| 55 |
public function getTabGroupLink(string $groupKey): string |
| 56 |
{ |
| 57 |
$rawUrl = $this->getRequestUrl(); |
| 58 |
$url = preg_replace('/&tab_group[^&]*/i', '', $rawUrl); |
| 59 |
return $url . '&tab_group=' . $groupKey; |
| 60 |
} |
| 61 |
|
| 62 |
public function getTabGroupSectionLink(string $groupKey, string $sectionKey): string |
| 63 |
{ |
| 64 |
$rawUrl = $this->getTabGroupLink($groupKey); |
| 65 |
$url = preg_replace('/&tab_group_section[^&]*/i', '', $rawUrl); |
| 66 |
return $url . '&tab_group_section=' . $sectionKey; |
| 67 |
} |
| 68 |
} |
| 69 |
|