/
GroupEntity.php
99 lines (86 loc) · 3.5 KB
/
GroupEntity.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
<?php
namespace Concrete\Core\Permission\Access\Entity;
use Loader;
use Concrete\Core\User\Group\Group;
use Config;
use Concrete\Core\Permission\Access\Access as PermissionAccess;
use URL;
class GroupEntity extends Entity
{
protected $group = false;
public function getGroupObject()
{
return $this->group;
}
public function getAccessEntityUsers(PermissionAccess $pa)
{
return $this->group->getGroupMembers();
}
public function getAccessEntityTypeLinkHTML()
{
$html = '<a href="' . URL::to('/ccm/system/dialogs/group/search') . '" class="dialog-launch" dialog-width="640" dialog-height="480" dialog-modal="false" dialog-title="' . t('Add Group') . '">' . tc('PermissionAccessEntityTypeName',
'Group') . '</a>';
return $html;
}
public static function configureFromImport(\SimpleXMLElement $element)
{
$g = Group::getByName((string) $element['name']);
if (!is_object($g)) {
$g = Group::add((string) $element['name'], (string) $element['description']);
}
return static::getOrCreate($g);
}
public static function getAccessEntitiesForUser($user)
{
$entities = array();
$ingids = array();
$db = Loader::db();
foreach ($user->getUserGroups() as $key => $val) {
$group = Group::getByID($key);
foreach($group->getParentGroups() as $parentGroup) {
$ingids[] = $parentGroup->getGroupID();
}
$ingids[] = $group->getGroupID();
}
$instr = implode(',', $ingids);
$peIDs = $db->GetCol('select pae.peID from PermissionAccessEntities pae inner join PermissionAccessEntityTypes paet on pae.petID = paet.petID inner join PermissionAccessEntityGroups paeg on pae.peID = paeg.peID where petHandle = \'group\' and paeg.gID in (' . $instr . ')');
if (is_array($peIDs)) {
foreach ($peIDs as $peID) {
$entity = \Concrete\Core\Permission\Access\Entity\Entity::getByID($peID);
if (is_object($entity)) {
$entities[] = $entity;
}
}
}
return $entities;
}
public static function getOrCreate(Group $g)
{
$db = Loader::db();
$petID = $db->GetOne('select petID from PermissionAccessEntityTypes where petHandle = \'group\'');
$peID = $db->GetOne('select pae.peID from PermissionAccessEntities pae inner join PermissionAccessEntityGroups paeg on pae.peID = paeg.peID where petID = ? and paeg.gID = ?',
array($petID, $g->getGroupID()));
if (!$peID) {
$db->Execute("insert into PermissionAccessEntities (petID) values(?)", array($petID));
$peID = $db->Insert_ID();
Config::save('concrete.misc.access_entity_updated', time());
$db->Execute('insert into PermissionAccessEntityGroups (peID, gID) values (?, ?)',
array($peID, $g->getGroupID()));
}
return \Concrete\Core\Permission\Access\Entity\Entity::getByID($peID);
}
public function load()
{
$db = Loader::db();
$gID = $db->GetOne('select gID from PermissionAccessEntityGroups where peID = ?', array($this->peID));
if ($gID) {
$g = Group::getByID($gID);
if (is_object($g)) {
$this->group = $g;
$this->label = $g->getGroupDisplayName();
} else {
$this->label = t('(Deleted Group)');
}
}
}
}