mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,74 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a suite of a modules, Chill is a software for social workers
|
||||
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Chill\MainBundle\Entity\RoleScope;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="permission_groups")
|
||||
* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="acl_cache_region")
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class PermissionsGroup
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @ORM\Id
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(type="string", length=255)
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*
|
||||
* @ORM\Column(type="json")
|
||||
*/
|
||||
private $flags = [];
|
||||
|
||||
/**
|
||||
* @var Collection
|
||||
*
|
||||
* @ORM\ManyToMany(
|
||||
* targetEntity="Chill\MainBundle\Entity\RoleScope",
|
||||
* inversedBy="permissionsGroups",
|
||||
* cascade={ "persist" })
|
||||
* @ORM\Cache(usage="NONSTRICT_READ_WRITE")
|
||||
*/
|
||||
private $roleScopes;
|
||||
|
||||
|
||||
/**
|
||||
* @var Collection
|
||||
*
|
||||
@@ -78,8 +38,34 @@ class PermissionsGroup
|
||||
* )
|
||||
*/
|
||||
private $groupCenters;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*
|
||||
* @ORM\Id
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @ORM\Column(type="string", length=255)
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var Collection
|
||||
*
|
||||
* @ORM\ManyToMany(
|
||||
* targetEntity="Chill\MainBundle\Entity\RoleScope",
|
||||
* inversedBy="permissionsGroups",
|
||||
* cascade={ "persist" })
|
||||
* @ORM\Cache(usage="NONSTRICT_READ_WRITE")
|
||||
*/
|
||||
private $roleScopes;
|
||||
|
||||
/**
|
||||
* PermissionsGroup constructor.
|
||||
*/
|
||||
@@ -88,7 +74,20 @@ class PermissionsGroup
|
||||
$this->roleScopes = new \Doctrine\Common\Collections\ArrayCollection();
|
||||
$this->groupCenters = new \Doctrine\Common\Collections\ArrayCollection();
|
||||
}
|
||||
|
||||
|
||||
public function addRoleScope(RoleScope $roleScope)
|
||||
{
|
||||
$this->roleScopes->add($roleScope);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getFlags()
|
||||
{
|
||||
return $this->flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
@@ -104,7 +103,7 @@ class PermissionsGroup
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return ArrayCollection|Collection
|
||||
*/
|
||||
@@ -112,78 +111,62 @@ class PermissionsGroup
|
||||
{
|
||||
return $this->roleScopes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @return $this
|
||||
* Test that a role scope is associated only once
|
||||
* with the permission group.
|
||||
*/
|
||||
public function setName($name)
|
||||
public function isRoleScopePresentOnce(ExecutionContextInterface $context)
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
$roleScopesId = array_map(
|
||||
function (RoleScope $roleScope) {
|
||||
return $roleScope->getId();
|
||||
},
|
||||
$this->getRoleScopes()->toArray()
|
||||
);
|
||||
$countedIds = array_count_values($roleScopesId);
|
||||
|
||||
foreach ($countedIds as $id => $nb) {
|
||||
if (1 < $nb) {
|
||||
$context->buildViolation('A permission is already present '
|
||||
. 'for the same role and scope')
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RoleScope $roleScope
|
||||
*/
|
||||
public function addRoleScope(RoleScope $roleScope)
|
||||
{
|
||||
$this->roleScopes->add($roleScope);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RoleScope $roleScope
|
||||
* @throws \RuntimeException if the roleScope could not be removed.
|
||||
* @throws RuntimeException if the roleScope could not be removed.
|
||||
*/
|
||||
public function removeRoleScope(RoleScope $roleScope)
|
||||
{
|
||||
$result = $this->roleScopes->removeElement($roleScope);
|
||||
if ($result === FALSE) {
|
||||
throw new \RuntimeException(sprintf("The roleScope '%s' could not be removed, "
|
||||
. "aborting.", spl_object_hash($roleScope)));
|
||||
|
||||
if (false === $result) {
|
||||
throw new RuntimeException(sprintf("The roleScope '%s' could not be removed, "
|
||||
. 'aborting.', spl_object_hash($roleScope)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getFlags()
|
||||
{
|
||||
return $this->flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $flags
|
||||
* @return $this
|
||||
*/
|
||||
public function setFlags(array $flags)
|
||||
{
|
||||
$this->flags = $flags;
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a role scope is associated only once
|
||||
* with the permission group
|
||||
*
|
||||
* @param ExecutionContextInterface $context
|
||||
*/
|
||||
public function isRoleScopePresentOnce(ExecutionContextInterface $context)
|
||||
{
|
||||
$roleScopesId = array_map(function(RoleScope $roleScope) {
|
||||
return $roleScope->getId();
|
||||
},
|
||||
$this->getRoleScopes()->toArray());
|
||||
$countedIds = array_count_values($roleScopesId);
|
||||
|
||||
foreach ($countedIds as $id => $nb) {
|
||||
if ($nb > 1) {
|
||||
$context->buildViolation("A permission is already present "
|
||||
. "for the same role and scope")
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user