/
Service.php
70 lines (57 loc) · 1.91 KB
/
Service.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
<?php
namespace Concrete\Core\Site\User\Group;
use Concrete\Core\Entity\Site\Site;
use Concrete\Core\Entity\Site\Type;
use Concrete\Core\User\Group\Group;
use Doctrine\ORM\EntityManagerInterface;
use Concrete\Core\Entity\Site\Group\Relation;
use Concrete\Core\Entity\Site\Group\Group as SiteGroupEntity;
class Service
{
const PARENT_GROUP_PATH = '/Sites';
const PARENT_GROUP_NAME = 'Sites';
protected $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
public function getSiteParentGroup()
{
return Group::getByPath(static::PARENT_GROUP_PATH);
}
public function getSiteTypeGroups(Type $type)
{
return $this->entityManager->getRepository(SiteGroupEntity::class)
->findByType($type);
}
public function getInstanceGroupsBySite(Site $site)
{
$relations = $this->entityManager->getRepository(Relation::class)
->findBySite($site);
$groups = array();
foreach($relations as $relation) {
$groups[] = Group::getByID($relation->getInstanceGroupID());
}
return $groups;
}
/**
* Creates the concrete5 user group that will hold instance groups for this site.
*/
public function createSiteGroup(Site $site)
{
$name = $site->getSiteName();
return Group::add($site->getSiteName(), '', $this->getSiteParentGroup());
}
public function createInstanceGroup(\Concrete\Core\Entity\Site\Group\Group $siteGroup, Group $parent)
{
return Group::add($siteGroup->getSiteGroupName(), '', $parent);
}
public function addGroup(Type $type, $groupName)
{
$group = new SiteGroupEntity();
$group->setSiteGroupName($groupName);
$group->setSiteType($type);
$this->entityManager->persist($group);
$this->entityManager->flush();
}
}