PluginProbe
User Access Manager / 2.2.2
User Access Manager v2.2.2
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
user-access-manager / src / Controller / Backend / ControllerTabNavigationTrait.php

ControllerTabNavigationTrait.php in User Access Manager 2.2.2, at src/Controller/Backend/ControllerTabNavigationTrait.php

129 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ControllerTabNavigationTrait.php
4 *
5 * The ControllerTabNavigationTrait class file.
6 *
7 * PHP versions 5
8 *
9 * @author Alexander Schneider <alexanderschneider85@gmail.com>
10 * @copyright 2008-2017 Alexander Schneider
11 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
12 * @version SVN: $id$
13 * @link http://wordpress.org/extend/plugins/user-access-manager/
14 */
15
16 declare(strict_types=1);
17
18 namespace UserAccessManager\Controller\Backend;
19
20 /**
21 * Trait ControllerTabNavigationTrait
22 *
23 * @package UserAccessManager\Controller
24 */
25 trait ControllerTabNavigationTrait
26 {
27 /**
28 * Returns the current request url.
29 * @return string
30 */
31 abstract public function getRequestUrl(): string;
32
33 /**
34 * Returns the request parameter.
35 * @param string $name
36 * @param mixed $default
37 * @return mixed
38 */
39 abstract public function getRequestParameter(string $name, $default = null);
40
41 /**
42 * Translates the given group by the group key.
43 * @param string $key
44 * @return string
45 */
46 abstract public function getGroupText(string $key): string;
47
48 /**
49 * Translates the given group section by the group key.
50 * @param string $key
51 * @return string
52 */
53 abstract public function getGroupSectionText(string $key): string;
54
55 /**
56 * Returns the tab groups.
57 * @return array
58 */
59 abstract public function getTabGroups(): array;
60
61 /**
62 * Returns the current tab group.
63 * @return string
64 */
65 public function getCurrentTabGroup(): string
66 {
67 $groups = $this->getTabGroups();
68 $keys = array_keys($groups);
69
70 return (string) $this->getRequestParameter('tab_group', reset($keys));
71 }
72
73 /**
74 * Returns the tab group sections.
75 * @return array
76 */
77 public function getSections(): array
78 {
79 $groups = $this->getTabGroups();
80 $group = $this->getCurrentTabGroup();
81
82 return isset($groups[$group]) === true ? $groups[$group] : [];
83 }
84
85 /**
86 * Returns the current tab group section.
87 * @return string
88 */
89 public function getCurrentTabGroupSection(): string
90 {
91 $groups = $this->getTabGroups();
92 $group = $this->getCurrentTabGroup();
93
94 if (isset($groups[$group]) === true) {
95 $default = reset($groups[$group]);
96 } else {
97 $firstGroup = reset($groups);
98 $default = reset($firstGroup);
99 }
100
101 return (string) $this->getRequestParameter('tab_group_section', $default);
102 }
103
104 /**
105 * Returns the settings group link by the given group key.
106 * @param string $groupKey
107 * @return string
108 */
109 public function getTabGroupLink(string $groupKey): string
110 {
111 $rawUrl = $this->getRequestUrl();
112 $url = preg_replace('/&amp;tab_group[^&]*/i', '', $rawUrl);
113 return $url . '&tab_group=' . $groupKey;
114 }
115
116 /**
117 * Returns the settings section link by the given group and section key.
118 * @param string $groupKey
119 * @param string $sectionKey
120 * @return string
121 */
122 public function getTabGroupSectionLink(string $groupKey, string $sectionKey): string
123 {
124 $rawUrl = $this->getTabGroupLink($groupKey);
125 $url = preg_replace('/&amp;tab_group_section[^&]*/i', '', $rawUrl);
126 return $url . '&tab_group_section=' . $sectionKey;
127 }
128 }
129