PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 3.0.5
Admin Columns v3.0.5
7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / Groups.php
codepress-admin-columns / classes Last commit date
Addon 8 years ago Admin 8 years ago Column 8 years ago Helper 8 years ago ListScreen 8 years ago Meta 8 years ago Notice 8 years ago Plugin 8 years ago Relation 8 years ago Settings 8 years ago ThirdParty 8 years ago API.php 8 years ago Addon.php 8 years ago Addons.php 8 years ago Admin.php 8 years ago Autoloader.php 8 years ago Collection.php 8 years ago Column.php 8 years ago Container.php 8 years ago Groups.php 8 years ago Helper.php 8 years ago ListScreen.php 8 years ago ListScreenPost.php 8 years ago Plugin.php 8 years ago PluginInformation.php 8 years ago Preferences.php 8 years ago Relation.php 8 years ago TableScreen.php 8 years ago View.php 8 years ago ViewInterface.php 8 years ago
Groups.php
155 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 /**
8 * Holds the groups to which columns can belong.
9 */
10 final class AC_Groups {
11
12 const SORT_PRIORITY = 1;
13
14 const SORT_SLUG = 2;
15
16 const SORT_LABEL = 3;
17
18 /**
19 * @var array
20 */
21 private $groups = array();
22
23 /**
24 * @return array
25 */
26 public function get_groups() {
27 return $this->groups;
28 }
29
30 /**
31 * Return the registered groups sorted by either label, slug or priority
32 *
33 * @param int $sort_by Default is self::SORT_PRIORITY
34 *
35 * @return array
36 */
37 public function get_groups_sorted( $sort_by = null ) {
38 switch ( $sort_by ) {
39 case self::SORT_LABEL :
40 $sorted = $this->sort_groups_by_string( $this->get_groups(), 'label' );
41
42 break;
43 case self::SORT_SLUG :
44 $sorted = $this->sort_groups_by_string( $this->get_groups(), 'slug' );
45
46 break;
47 default :
48 $sorted = $this->sort_groups_by_priority( $this->get_groups() );
49 }
50
51 return $sorted;
52 }
53
54 /**
55 * Sort the group by priority
56 *
57 * If there are more groups with the same priority it will those groups by label
58 *
59 * @param $groups
60 *
61 * @return array
62 */
63 private function sort_groups_by_priority( array $groups ) {
64 $aggregated = $sorted = array();
65
66 foreach ( $groups as $group ) {
67 $aggregated[ $group['priority'] ][] = $group;
68 }
69
70 ksort( $aggregated, SORT_NUMERIC );
71
72 foreach ( $aggregated as $priority => $groups ) {
73 $sorted = array_merge( $sorted, $this->sort_groups_by_string( $groups, 'label' ) );
74 }
75
76 return $sorted;
77 }
78
79 /**
80 * Sort the group by label or slug
81 *
82 * @param array $groups
83 * @param string $key
84 *
85 * @return array
86 */
87 private function sort_groups_by_string( array $groups, $key ) {
88 $sorted = array();
89
90 foreach ( $groups as $k => $group ) {
91 $sorted[ $k ] = $group[ $key ];
92 }
93
94 natcasesort( $sorted );
95
96 foreach ( array_keys( $sorted ) as $k ) {
97 $sorted[ $k ] = $groups[ $k ];
98 }
99
100 return $sorted;
101 }
102
103 /**
104 * @param string $slug
105 *
106 * @return bool|mixed
107 */
108 public function get_group( $slug ) {
109 if ( ! $this->has_group( $slug ) ) {
110 return false;
111 }
112
113 return $this->groups[ $slug ];
114 }
115
116 public function get_group_label( $slug ) {
117 $group = $this->get_group( $slug );
118
119 return $group ? $group['label'] : false;
120 }
121
122 /**
123 * @param string $slug
124 *
125 * @return bool
126 */
127 public function has_group( $slug ) {
128 return isset( $this->groups[ $slug ] );
129 }
130
131 /**
132 * Register a (column) group
133 *
134 * @param string $slug
135 * @param string $label Should be translatable
136 * @param int $priority
137 *
138 * @return bool
139 */
140 public function register_group( $slug, $label, $priority = 10 ) {
141 if ( $this->has_group( $slug ) ) {
142 return false;
143 }
144
145 $this->groups[ $slug ] = array(
146 'slug' => $slug,
147 'label' => $label,
148 'priority' => $priority,
149 );
150
151 return true;
152 }
153
154 }
155