Issues (1797)

public/main/group/settings.php (1 issue)

Labels
Severity
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
use Chamilo\CoreBundle\Framework\Container;
6
use Chamilo\CourseBundle\Entity\CGroup;
7
use Chamilo\CoreBundle\Component\Utils\ToolIcon;
8
9
/**
10
 * This script displays an area where teachers can edit the group properties and member list.
11
 *
12
 * @author various contributors
13
 * @author Roan Embrechts (VUB), partial code cleanup, initial virtual course support
14
 *
15
 * @todo course admin functionality to create groups based on who is in which course (or class).
16
 */
17
require_once __DIR__.'/../inc/global.inc.php';
18
$this_section = SECTION_COURSES;
19
$current_course_tool = TOOL_GROUP;
20
21
api_protect_course_script(true);
22
23
$group_id = api_get_group_id();
24
$current_group = GroupManager::get_group_properties($group_id);
25
$groupRepo = Container::getGroupRepository();
26
/** @var CGroup $groupEntity */
27
$groupEntity = $groupRepo->find($group_id);
28
29
if (null === $groupEntity) {
30
    api_not_allowed(true);
31
}
32
33
$nameTools = get_lang('Edit this group');
34
$interbreadcrumb[] = ['url' => 'group.php?'.api_get_cidreq(), 'name' => get_lang('Groups')];
35
$interbreadcrumb[] = ['url' => 'group_space.php?'.api_get_cidreq(), 'name' => $groupEntity->getTitle()];
36
$groupMember = GroupManager::isTutorOfGroup(api_get_user_id(), $groupEntity);
37
38
if (!$groupMember && !api_is_allowed_to_edit(false, true)) {
39
    api_not_allowed(true);
40
}
41
42
// Build form
43
$form = new FormValidator('group_edit', 'post', api_get_self().'?'.api_get_cidreq());
44
$form->addElement('hidden', 'action');
45
46
$form->addHtml('<div class="row">');
47
$form->addElement('html', '<div class="col-md-12">');
48
$form->addElement('header', $nameTools);
49
$form->addHtml('</div>');
50
$form->addHtml('</div>');
51
52
$form->addHtml('<div class="row">');
53
$form->addElement('html', '<div class="col-md-6">');
54
55
// Group name
56
$form->addElement('text', 'name', get_lang('Group name'));
57
58
if ('true' === api_get_setting('allow_group_categories')) {
59
    $groupCategories = GroupManager::get_categories();
60
    $categoryList = [];
61
    foreach ($groupCategories as $category) {
62
        $categoryList[$category['iid']] = $category['title'];
63
    }
64
    $form->addSelect('category_id', get_lang('Category'), $categoryList);
65
} else {
66
    $form->addHidden('category_id', 0);
67
}
68
$form->addElement('html', '</div>');
69
70
$form->addElement('html', '<div class="col-md-6">');
71
$form->addElement('textarea', 'description', get_lang('Description'));
72
$form->addHtml('</div>');
73
$form->addHtml('</div>');
74
75
$form->addHtml('<div class="row">');
76
$form->addElement('html', '<div class="col-md-6">');
77
78
// Members per group
79
$group = [
80
    $form->createElement(
81
        'radio',
82
        'max_member_no_limit',
83
        get_lang('Limit'),
84
        get_lang('No limitation'),
85
        GroupManager::MEMBER_PER_GROUP_NO_LIMIT
86
    ),
87
    $form->createElement(
88
        'radio',
89
        'max_member_no_limit',
90
        null,
91
        get_lang('Maximum number of members'),
92
        1,
93
        ['id' => 'max_member_selected']
94
    ),
95
    $form->createElement('text', 'max_member', null, ['class' => 'span1', 'id' => 'max_member']),
96
    $form->createElement('static', null, null, ' '.get_lang('seats (optional)')),
97
];
98
$form->addGroup($group, 'max_member_group', get_lang('Limit'), null, false);
99
$form->addRule(
100
    'max_member_group',
101
    get_lang('Please enter a valid number for the maximum number of members.'),
102
    'callback',
103
    'check_max_number_of_members'
104
);
105
$form->addElement('html', '</div>');
106
107
$form->addElement('html', '<div class="col-md-6">');
108
109
// Self registration
110
$group = [
111
    $form->createElement(
112
        'checkbox',
113
        'self_registration_allowed',
114
        get_lang('Registration'),
115
        get_lang('Learners are allowed to self-register in groups')
116
    ),
117
    $form->createElement(
118
        'checkbox',
119
        'self_unregistration_allowed',
120
        null,
121
        get_lang('Learners are allowed to unregister themselves from groups'),
122
    ),
123
];
124
$form->addGroup(
125
    $group,
126
    '',
127
    Display::getMdiIcon(ToolIcon::MEMBER, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Registration')).
128
    '<span>'.get_lang('Registration').'</span>',
129
    null,
130
    false
131
);
132
133
$form->addElement('html', '</div>');
134
$form->addHtml('</div>');
135
136
$form->addElement('html', '<div class="col-md-12">');
137
$form->addElement('header', get_lang('Default settings for new groups'));
138
$form->addElement('html', '</div>');
139
140
$form->addElement('html', '<div class="col-md-6">');
141
// Documents settings
142
$group = [
143
    $form->createElement('radio', 'doc_state', get_lang('Documents'), get_lang('Not available'), GroupManager::TOOL_NOT_AVAILABLE),
144
    $form->createElement('radio', 'doc_state', null, get_lang('Public access (access authorized to any member of the course)'), GroupManager::TOOL_PUBLIC),
145
    $form->createElement('radio', 'doc_state', null, get_lang('Private access (access authorized to group members only)'), GroupManager::TOOL_PRIVATE),
146
];
147
$form->addGroup(
148
    $group,
149
    '',
150
    Display::getMdiIcon(ToolIcon::DOCUMENT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Documents')).'<span>'.get_lang('Documents').'</span>',
151
    null,
152
    false
153
);
154
155
$allowDocumentGroupAccess = ('true' === api_get_setting('document.group_document_access'));
156
if ($allowDocumentGroupAccess) {
157
    $form->addElement('html', '</div>');
158
    $form->addElement('html', '<div class="col-md-6">');
159
    $group = [
160
        $form->createElement(
161
            'radio',
162
            'document_access',
163
            null,
164
            get_lang('Share mode'),
165
            GroupManager::DOCUMENT_MODE_SHARE
166
        ),
167
        $form->createElement(
168
            'radio',
169
            'document_access',
170
            get_lang('Documents'),
171
            get_lang('Collaboration mode'),
172
            GroupManager::DOCUMENT_MODE_COLLABORATION
173
        ),
174
        $form->createElement(
175
            'radio',
176
            'document_access',
177
            null,
178
            get_lang('Read only mode'),
179
            GroupManager::DOCUMENT_MODE_READ_ONLY
180
        ),
181
    ];
182
    $form->addGroup(
183
        $group,
184
        '',
185
        Display::getMdiIcon(ToolIcon::DOCUMENT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('DocumentsAccess')
186
        ).'<span>'.get_lang('DocumentsAccess').'</span>',
187
        null,
188
        false
189
    );
190
    $form->addElement('html', '</div>');
191
192
    $form->addElement('html', '<div class="col-md-12">');
193
    $form->addElement('header', '');
194
    $form->addElement('html', '</div>');
195
196
    $form->addElement('html', '<div class="col-md-6">');
197
}
198
199
// Work settings
200
$group = [
201
    $form->createElement(
202
        'radio',
203
        'work_state',
204
        get_lang('Assignments'),
205
        get_lang('Not available'),
206
        GroupManager::TOOL_NOT_AVAILABLE
207
    ),
208
    $form->createElement('radio', 'work_state', null, get_lang('Public access (access authorized to any member of the course)'), GroupManager::TOOL_PUBLIC),
209
    $form->createElement('radio', 'work_state', null, get_lang('Private access (access authorized to group members only)'), GroupManager::TOOL_PRIVATE),
210
];
211
$form->addElement('html', '</div>');
212
213
$form->addElement('html', '<div class="col-md-12">');
214
$form->addElement('html', '</div>');
215
216
$form->addElement('html', '<div class="col-md-6">');
217
218
$form->addGroup(
219
    $group,
220
    '',
221
    Display::getMdiIcon(ToolIcon::ASSIGNMENT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Assignments')).'<span>'.get_lang('Assignments').'</span>',
222
    null,
223
    false
224
);
225
226
// Calendar settings
227
$group = [
228
    $form->createElement('radio', 'calendar_state', get_lang('Agenda'), get_lang('Not available'), GroupManager::TOOL_NOT_AVAILABLE),
229
    $form->createElement('radio', 'calendar_state', null, get_lang('Public access (access authorized to any member of the course)'), GroupManager::TOOL_PUBLIC),
230
    $form->createElement('radio', 'calendar_state', null, get_lang('Private access (access authorized to group members only)'), GroupManager::TOOL_PRIVATE),
231
];
232
233
$form->addElement('html', '</div>');
234
235
$form->addElement('html', '<div class="col-md-6">');
236
$form->addGroup(
237
    $group,
238
    '',
239
    Display::getMdiIcon(ToolIcon::AGENDA, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Agenda')).'<span>'.get_lang('Agenda').'</span>',
240
    null,
241
    false
242
);
243
244
$form->addElement('html', '</div>');
245
246
$form->addElement('html', '<div class="col-md-12">');
247
$form->addElement('header', '');
248
$form->addElement('html', '</div>');
249
250
$form->addElement('html', '<div class="col-md-6">');
251
252
// Announcements settings
253
$group = [
254
    $form->createElement('radio', 'announcements_state', get_lang('Announcements'), get_lang('Not available'), GroupManager::TOOL_NOT_AVAILABLE),
255
    $form->createElement('radio', 'announcements_state', null, get_lang('Public access (access authorized to any member of the course)'), GroupManager::TOOL_PUBLIC),
256
    $form->createElement('radio', 'announcements_state', null, get_lang('Private access (access authorized to group members only)'), GroupManager::TOOL_PRIVATE),
257
    $form->createElement('radio', 'announcements_state', null, get_lang('Private between users'), GroupManager::TOOL_PRIVATE_BETWEEN_USERS),
258
];
259
260
$form->addGroup(
261
    $group,
262
    '',
263
    Display::getMdiIcon(ToolIcon::ANNOUNCEMENT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Announcements')).'<span>'.get_lang('Announcements').'</span>',
264
    null,
265
    false
266
);
267
268
$form->addElement('html', '</div>');
269
270
$form->addElement('html', '<div class="col-md-6">');
271
272
// Forum settings
273
$group = [
274
    $form->createElement('radio', 'forum_state', get_lang('Group Forum'), get_lang('Not available'), GroupManager::TOOL_NOT_AVAILABLE),
275
    $form->createElement('radio', 'forum_state', null, get_lang('Public access (access authorized to any member of the course)'), GroupManager::TOOL_PUBLIC),
276
    $form->createElement('radio', 'forum_state', null, get_lang('Private access (access authorized to group members only)'), GroupManager::TOOL_PRIVATE),
277
];
278
$form->addGroup(
279
    $group,
280
    '',
281
    Display::getMdiIcon(ToolIcon::FORUM, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Group Forum')).'<span>'.get_lang('Group Forum').'</span>',
282
    null,
283
    false
284
);
285
286
$form->addElement('html', '</div>');
287
288
$form->addElement('html', '<div class="col-md-12">');
289
$form->addElement('header', '');
290
$form->addElement('html', '</div>');
291
292
$form->addElement('html', '<div class="col-md-6">');
293
294
// Wiki settings
295
$group = [
296
    $form->createElement('radio', 'wiki_state', get_lang('Wiki'), get_lang('Not available'), GroupManager::TOOL_NOT_AVAILABLE),
297
    $form->createElement('radio', 'wiki_state', null, get_lang('Public access (access authorized to any member of the course)'), GroupManager::TOOL_PUBLIC),
298
    $form->createElement('radio', 'wiki_state', null, get_lang('Private access (access authorized to group members only)'), GroupManager::TOOL_PRIVATE),
299
];
300
$form->addGroup(
301
    $group,
302
    '',
303
    Display::getMdiIcon(ToolIcon::WIKI, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Wiki')).'<span>'.get_lang('Wiki').'</span>',
304
    '',
305
    false
306
);
307
308
$form->addElement('html', '</div>');
309
$form->addElement('html', '<div class="col-md-6">');
310
311
// Chat settings
312
$group = [
313
    $form->createElement('radio', 'chat_state', get_lang('Chat'), get_lang('Not available'), GroupManager::TOOL_NOT_AVAILABLE),
314
    $form->createElement('radio', 'chat_state', null, get_lang('Public access (access authorized to any member of the course)'), GroupManager::TOOL_PUBLIC),
315
    $form->createElement('radio', 'chat_state', null, get_lang('Private access (access authorized to group members only)'), GroupManager::TOOL_PRIVATE),
316
];
317
$form->addGroup(
318
    $group,
319
    '',
320
    Display::getMdiIcon(ToolIcon::CHAT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Chat')).'<span>'.get_lang('Chat').'</span>',
321
    null,
322
    false
323
);
324
325
$form->addElement('html', '</div>');
326
$form->addElement('html', '<div class="col-md-12">');
327
// Submit button
328
$form->addButtonSave(get_lang('Save settings'));
329
$form->addElement('html', '</div>');
330
331
if ($form->validate()) {
332
    $values = $form->exportValues();
333
    $max_member = $values['max_member'];
334
    if (GroupManager::MEMBER_PER_GROUP_NO_LIMIT == $values['max_member_no_limit']) {
335
        $max_member = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
336
    }
337
    $self_registration_allowed = isset($values['self_registration_allowed']) ? 1 : 0;
338
    $self_unregistration_allowed = isset($values['self_unregistration_allowed']) ? 1 : 0;
339
    $categoryId = $values['category_id'] ?? null;
340
341
    GroupManager::set_group_properties(
342
        $group_id,
343
        $values['name'],
344
        $values['description'],
345
        $max_member,
346
        $values['doc_state'],
347
        $values['work_state'],
348
        $values['calendar_state'],
349
        $values['announcements_state'],
350
        $values['forum_state'],
351
        $values['wiki_state'],
352
        $values['chat_state'],
353
        $self_registration_allowed,
354
        $self_unregistration_allowed,
355
        $categoryId,
356
        $values['document_access'] ?? 0
357
    );
358
    if (isset($_POST['group_members']) &&
359
        count($_POST['group_members']) > $max_member &&
360
        GroupManager::MEMBER_PER_GROUP_NO_LIMIT != $max_member
361
    ) {
362
        Display::addFlash(
363
            Display::return_message(
364
                get_lang(
365
                    'Number proposed exceeds max. that you allowed (you can modify in the group settings). Group composition has not been modified'
366
                ),
367
                'warning'
368
            )
369
        );
370
        header('Location: group.php?'.api_get_cidreq(true, false).'&category='.$categoryId);
371
    } else {
372
        Display::addFlash(Display::return_message(get_lang('Group settings modified'), 'success'));
373
        header('Location: group.php?'.api_get_cidreq(true, false).'&category='.$categoryId);
374
    }
375
    exit;
376
}
377
378
$defaults = $current_group;
379
$category = GroupManager::get_category_from_group($current_group['iid']);
380
if (!empty($category)) {
381
    $defaults['category_id'] = $category['iid'];
382
}
383
384
$action = isset($_GET['action']) ? $_GET['action'] : '';
385
$defaults['action'] = $action;
386
if (GroupManager::MEMBER_PER_GROUP_NO_LIMIT == $defaults['maximum_number_of_students']) {
387
    $defaults['max_member_no_limit'] = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
388
} else {
389
    $defaults['max_member_no_limit'] = 1;
390
    $defaults['max_member'] = $defaults['maximum_number_of_students'];
391
}
392
393
if (!empty($_GET['keyword']) && !empty($_GET['submit'])) {
394
    $keyword_name = Security::remove_XSS($_GET['keyword']);
395
    echo '<br/>'.get_lang('Search results for:').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
396
}
397
398
Display::display_header($nameTools, 'Group');
399
400
$form->setDefaults($defaults);
401
echo GroupManager::getSettingBar('settings');
0 ignored issues
show
Are you sure the usage of GroupManager::getSettingBar('settings') targeting GroupManager::getSettingBar() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
402
$form->display();
403
404
Display :: display_footer();
405