forked from mschering/groupoffice-owncloud
-
Notifications
You must be signed in to change notification settings - Fork 2
/
group_groupoffice.php
112 lines (77 loc) · 2.63 KB
/
group_groupoffice.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
namespace OCA\groupoffice;
class Group extends \OC_Group_Backend
{
public function getGroups($search = '', $limit = -1, $offset = 0)
{
$returnArray = array();
$fp = \GO_Base_Db_FindParams::newInstance()
->start($offset)
->searchQuery('%' . $search . '%');
if ($limit > 0)
$fp->limit($limit);
$stmt = \GO_Base_Model_Group::model()->find($fp);
foreach ($stmt as $group) {
$returnArray[] = $group->name;
}
return $returnArray;
}
public function getUserGroups($uid)
{
$groups = array();
$user = \GO_Base_Model_User::model()->findSingleByAttribute('username', $uid);
if ($user) {
$stmt = $user->groups();
foreach ($stmt as $group) {
$groups[] = $group->name;
}
}
return $groups;
}
public function groupExists($gid)
{
$group = \GO_Base_Model_Group::model()->findSingleByAttribute('name', $gid);
return $group != false;
}
public function inGroup($uid, $gid)
{
$user = \GO_Base_Model_User::model()->findSingleByAttribute('username', $uid);
if (!$user)
return false;
$group = \GO_Base_Model_Group::model()->findSingleByAttribute('name', $gid);
if (!$group)
return false;
$ug = \GO_Base_Model_UserGroup::model()->findByPk(array('user_id' => $user->id, 'group_id' => $group->id));
return $ug != false;
}
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0)
{
$users = array();
$group = \GO_Base_Model_Group::model()->findSingleByAttribute('name', $gid);
$findParams = \GO_Base_Db_FindParams::newInstance()
->start($offset)
->searchQuery('%' . $search . '%');
if ($limit > 0)
$findParams->limit($limit);
$stmt = $group->users($findParams);
foreach ($stmt as $user) {
$users[] = $user->username;
}
return $users;
}
public function countUsersInGroup($gid, $search = '')
{
$group = \GO_Base_Model_Group::model()->findSingleByAttribute('name', $gid);
$findParams = \GO_Base_Db_FindParams::newInstance()
->single()
->select('count(*) as total');
//if ($search != '')
// $findParams->searchQuery('%'.$search.'%');
$record = $group->users($findParams);
return $record->total;
}
public function implementsActions($actions)
{
return (bool)(OC_GROUP_BACKEND_COUNT_USERS & $actions);
}
}