1 | <?php |
||||||
2 | /** |
||||||
3 | * Elgg Groups. |
||||||
4 | * Groups contain other entities, or rather act as a placeholder for other entities to |
||||||
5 | * mark any given container as their container. |
||||||
6 | * |
||||||
7 | * @package Elgg.Core |
||||||
8 | * @subpackage DataModel.Group |
||||||
9 | */ |
||||||
10 | |||||||
11 | /** |
||||||
12 | * Adds a group tool option |
||||||
13 | * |
||||||
14 | * @see remove_group_tool_option(). |
||||||
15 | * |
||||||
16 | * @param string $name Name of the group tool option |
||||||
17 | * @param string $label Used for the group edit form |
||||||
18 | * @param bool $default_on True if this option should be active by default |
||||||
19 | * |
||||||
20 | * @return void |
||||||
21 | * @since 1.5.0 |
||||||
22 | */ |
||||||
23 | function add_group_tool_option($name, $label, $default_on = true) { |
||||||
24 | 34 | $options = _elgg_config()->group_tool_options; |
|||||
25 | 34 | if (!$options) { |
|||||
26 | 18 | $options = []; |
|||||
27 | } |
||||||
28 | |||||||
29 | 34 | $options[$name] = (object) [ |
|||||
30 | 34 | 'name' => $name, |
|||||
31 | 34 | 'label' => $label, |
|||||
32 | 34 | 'default_on' => $default_on, |
|||||
33 | ]; |
||||||
34 | 34 | _elgg_config()->group_tool_options = $options; |
|||||
35 | 34 | } |
|||||
36 | |||||||
37 | /** |
||||||
38 | * Removes a group tool option based on name |
||||||
39 | * |
||||||
40 | * @see add_group_tool_option() |
||||||
41 | * |
||||||
42 | * @param string $name Name of the group tool option |
||||||
43 | * |
||||||
44 | * @return void |
||||||
45 | * @since 1.7.5 |
||||||
46 | */ |
||||||
47 | function remove_group_tool_option($name) { |
||||||
48 | 1 | $options = _elgg_config()->group_tool_options; |
|||||
49 | 1 | if (!is_array($options)) { |
|||||
50 | return; |
||||||
51 | } |
||||||
52 | |||||||
53 | 1 | if (!isset($options[$name])) { |
|||||
54 | return; |
||||||
55 | } |
||||||
56 | |||||||
57 | 1 | unset($options[$name]); |
|||||
58 | |||||||
59 | 1 | _elgg_config()->group_tool_options = $options; |
|||||
60 | 1 | } |
|||||
61 | |||||||
62 | /** |
||||||
63 | * Checks if a group has a specific tool enabled. |
||||||
64 | * Forward to the group if the tool is disabled. |
||||||
65 | * |
||||||
66 | * @param string $option The group tool option to check |
||||||
67 | * @param int $group_guid The group that owns the page. If not set, this |
||||||
68 | * will be pulled from elgg_get_page_owner_guid(). |
||||||
69 | * |
||||||
70 | * @return void |
||||||
71 | * @since 3.0.0 |
||||||
72 | */ |
||||||
73 | function elgg_group_tool_gatekeeper($option, $group_guid = null) { |
||||||
74 | $group_guid = $group_guid ?: elgg_get_page_owner_guid(); |
||||||
75 | |||||||
76 | $group = get_entity($group_guid); |
||||||
77 | if (!$group instanceof \ElggGroup) { |
||||||
78 | return; |
||||||
79 | } |
||||||
80 | |||||||
81 | if ($group->isToolEnabled($option)) { |
||||||
82 | return; |
||||||
83 | } |
||||||
84 | |||||||
85 | register_error(elgg_echo('groups:tool_gatekeeper')); |
||||||
86 | forward($group->getURL(), 'group_tool'); |
||||||
87 | } |
||||||
88 | |||||||
89 | /** |
||||||
90 | * Function to return available group tool options |
||||||
91 | * |
||||||
92 | * @param \ElggGroup $group optional group |
||||||
93 | * |
||||||
94 | * @return array |
||||||
95 | * @since 3.0.0 |
||||||
96 | */ |
||||||
97 | function elgg_get_group_tool_options(\ElggGroup $group = null) { |
||||||
98 | |||||||
99 | 3 | $tool_options = elgg_get_config('group_tool_options'); |
|||||
100 | |||||||
101 | $hook_params = [ |
||||||
102 | 3 | 'group_tool_options' => $tool_options, |
|||||
103 | 3 | 'entity' => $group, |
|||||
104 | ]; |
||||||
105 | |||||||
106 | 3 | return (array) elgg_trigger_plugin_hook('tool_options', 'group', $hook_params, $tool_options); |
|||||
107 | } |
||||||
108 | |||||||
109 | /** |
||||||
110 | * Allow group members to write to the group container |
||||||
111 | * |
||||||
112 | * @param string $hook Hook name |
||||||
113 | * @param string $type Hook type |
||||||
114 | * @param bool $result The value of the hook |
||||||
115 | * @param array $params Parameters related to the hook |
||||||
116 | * @return bool |
||||||
117 | * @access private |
||||||
118 | */ |
||||||
119 | function _elgg_groups_container_override($hook, $type, $result, $params) { |
||||||
2 ignored issues
–
show
The parameter
$type is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
Loading history...
|
|||||||
120 | 10 | $container = $params['container']; |
|||||
121 | 10 | $user = $params['user']; |
|||||
122 | |||||||
123 | 10 | if ($container instanceof ElggGroup && $user) { |
|||||
124 | /* @var \ElggGroup $container */ |
||||||
125 | 2 | if ($container->isMember($user)) { |
|||||
126 | 2 | return true; |
|||||
127 | } |
||||||
128 | } |
||||||
129 | |||||||
130 | 10 | return $result; |
|||||
131 | } |
||||||
132 | |||||||
133 | /** |
||||||
134 | * Runs unit tests for the group entities. |
||||||
135 | * |
||||||
136 | * @param string $hook Hook name |
||||||
137 | * @param string $type Hook type |
||||||
138 | * @param array $value Array of unit test locations |
||||||
139 | * |
||||||
140 | * @return array |
||||||
141 | * @access private |
||||||
142 | * @codeCoverageIgnore |
||||||
143 | */ |
||||||
144 | function _elgg_groups_test($hook, $type, $value) { |
||||||
2 ignored issues
–
show
The parameter
$hook is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
Loading history...
The parameter
$type is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
Loading history...
|
|||||||
145 | $value[] = ElggCoreGroupTest::class; |
||||||
146 | return $value; |
||||||
147 | } |
||||||
148 | |||||||
149 | /** |
||||||
150 | * init the groups library |
||||||
151 | * |
||||||
152 | * @return void |
||||||
153 | * |
||||||
154 | * @access private |
||||||
155 | */ |
||||||
156 | function _elgg_groups_init() { |
||||||
157 | 31 | elgg_register_plugin_hook_handler('container_permissions_check', 'all', '_elgg_groups_container_override'); |
|||||
158 | 31 | elgg_register_plugin_hook_handler('unit_test', 'system', '_elgg_groups_test'); |
|||||
159 | 31 | } |
|||||
160 | |||||||
161 | /** |
||||||
162 | * @see \Elgg\Application::loadCore Do not do work here. Just register for events. |
||||||
163 | */ |
||||||
164 | return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
||||||
1 ignored issue
–
show
The parameter
$hooks is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
Loading history...
|
|||||||
165 | 18 | $events->registerHandler('init', 'system', '_elgg_groups_init'); |
|||||
166 | }; |
||||||
167 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.