/
UserGroupField.php
80 lines (69 loc) · 2.48 KB
/
UserGroupField.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
namespace Concrete\Core\User\Search\Field\Field;
use Concrete\Core\File\FileList;
use Concrete\Core\File\Type\Type;
use Concrete\Core\Search\Field\AbstractField;
use Concrete\Core\Search\Field\FieldInterface;
use Concrete\Core\Search\ItemList\ItemList;
use Concrete\Core\User\Group\GroupList;
use Concrete\Core\User\UserList;
class UserGroupField extends AbstractField
{
protected $requestVariables = [
'gID', 'uGroupIn'
];
public function getKey()
{
return 'user_group';
}
public function getDisplayName()
{
return t('User Group');
}
/**
* @param UserList $list
* @param $request
*/
public function filterList(ItemList $list)
{
$filterGroups = array();
if (isset($this->data['gID']) && is_array($this->data['gID'])) {
foreach ($this->data['gID'] as $gID) {
$g = \Group::getByID($gID);
if (is_object($g)) {
$gp = new \Permissions($g);
if ($gp->canSearchUsersInGroup()) {
$filterGroups[] = $g;
}
}
}
}
$inGroup = true;
if ($this->data['uGroupIn'] == 'not') {
$inGroup = false;
}
$list->filterByInAnyGroup($filterGroups, $inGroup);
}
public function renderSearchField()
{
$gl = new GroupList();
$g1 = $gl->getResults();
$html = '<div class="form-group"><select multiple name="gID[]" class="selectize-select">';
foreach ($g1 as $g) {
$gp = new \Permissions($g);
if ($gp->canSearchUsersInGroup($g)) {
$html .= '<option value="' . $g->getGroupID() . '" ';
if (is_array($this->data['gID']) && in_array($g->getGroupID(), $this->data['gID'])) {
$html .= 'selected="selected" ';
}
$html .= '>' . $g->getGroupDisplayName() . '</option>';
}
}
$html .= '</select></div><br/>';
$html .= '<div class="form-group"><select name="uGroupIn" class="form-control">';
$html .= '<option value="in"' . ($this->data['uGroupIn'] == 'in' ? ' selected' : '') . '>' . t('Search for users in group(s)') . '</option>';
$html .= '<option value="not"' . ($this->data['uGroupIn'] == 'not' ? ' selected' : '') . '>' . t('Search for users not included in group(s)') . '</option>';
$html .= '</select></div>';
return $html;
}
}