PluginProbe
User Access Manager / 2.1.3
User Access Manager v2.1.3
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.1.3, at src/Controller/Backend/ControllerTabNavigationTrait.php

141 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 namespace UserAccessManager\Controller\Backend;
16
17 /**
18 * Trait ControllerTabNavigationTrait
19 *
20 * @package UserAccessManager\Controller
21 */
22 trait ControllerTabNavigationTrait
23 {
24 /**
25 * Returns the current request url.
26 *
27 * @return string
28 */
29 abstract public function getRequestUrl();
30
31 /**
32 * Returns the request parameter.
33 *
34 * @param string $name
35 * @param mixed $default
36 *
37 * @return mixed
38 */
39 abstract public function getRequestParameter($name, $default = null);
40
41 /**
42 * Translates the given group by the group key.
43 *
44 * @param string $key
45 *
46 * @return string
47 */
48 abstract public function getGroupText($key);
49
50 /**
51 * Translates the given group section by the group key.
52 *
53 * @param string $key
54 *
55 * @return string
56 */
57 abstract public function getGroupSectionText($key);
58
59 /**
60 * Returns the tab groups.
61 *
62 * @return array
63 */
64 abstract public function getTabGroups();
65
66 /**
67 * Returns the current tab group.
68 *
69 * @return string
70 */
71 public function getCurrentTabGroup()
72 {
73 $groups = $this->getTabGroups();
74 $keys = array_keys($groups);
75
76 return (string)$this->getRequestParameter('tab_group', reset($keys));
77 }
78
79 /**
80 * Returns the tab group sections.
81 *
82 * @return array
83 */
84 public function getSections()
85 {
86 $groups = $this->getTabGroups();
87 $group = $this->getCurrentTabGroup();
88
89 return isset($groups[$group]) === true ? $groups[$group] : [];
90 }
91
92 /**
93 * Returns the current tab group section.
94 *
95 * @return string
96 */
97 public function getCurrentTabGroupSection()
98 {
99 $groups = $this->getTabGroups();
100 $group = $this->getCurrentTabGroup();
101
102 if (isset($groups[$group]) === true) {
103 $default = reset($groups[$group]);
104 } else {
105 $firstGroup = reset($groups);
106 $default = reset($firstGroup);
107 }
108
109 return (string)$this->getRequestParameter('tab_group_section', $default);
110 }
111
112 /**
113 * Returns the settings group link by the given group key.
114 *
115 * @param string $groupKey
116 *
117 * @return string
118 */
119 public function getTabGroupLink($groupKey)
120 {
121 $rawUrl = $this->getRequestUrl();
122 $url = preg_replace('/&amp;tab_group[^&]*/i', '', $rawUrl);
123 return $url.'&tab_group='.$groupKey;
124 }
125
126 /**
127 * Returns the settings section link by the given group and section key.
128 *
129 * @param string $groupKey
130 * @param string $sectionKey
131 *
132 * @return string
133 */
134 public function getTabGroupSectionLink($groupKey, $sectionKey)
135 {
136 $rawUrl = $this->getTabGroupLink($groupKey);
137 $url = preg_replace('/&amp;tab_group_section[^&]*/i', '', $rawUrl);
138 return $url.'&tab_group_section='.$sectionKey;
139 }
140 }
141