mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-03 21:34:59 +00:00
sf4, repair errors and make basic and admin chill pages works
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Chill\MainBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\Security\RoleProvider;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
@@ -9,9 +11,10 @@ use Chill\MainBundle\Entity\RoleScope;
|
||||
use Chill\MainBundle\Entity\PermissionsGroup;
|
||||
use Chill\MainBundle\Form\PermissionsGroupType;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Symfony\Component\Security\Core\Role\RoleInterface;
|
||||
use Symfony\Component\Security\Core\Role\RoleHierarchy;
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\MainBundle\Form\Type\ComposedRoleScopeType;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
* PermissionsGroup controller.
|
||||
@@ -19,7 +22,47 @@ use Chill\MainBundle\Form\Type\ComposedRoleScopeType;
|
||||
*/
|
||||
class PermissionsGroupController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
private $translatableStringHelper;
|
||||
|
||||
/**
|
||||
* @var RoleProvider $roleProvider
|
||||
*/
|
||||
private $roleProvider;
|
||||
|
||||
/**
|
||||
* @var RoleHierarchy $roleHierarchy
|
||||
*/
|
||||
private $roleHierarchy;
|
||||
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
/**
|
||||
* PermissionsGroupController constructor.
|
||||
*
|
||||
* @param TranslatableStringHelper $translatableStringHelper
|
||||
* @param RoleProvider $roleProvider
|
||||
* @param RoleHierarchy $roleHierarchy
|
||||
* @param TranslatorInterface $translator
|
||||
*/
|
||||
public function __construct(
|
||||
TranslatableStringHelper $translatableStringHelper,
|
||||
RoleProvider $roleProvider,
|
||||
RoleHierarchy $roleHierarchy,
|
||||
TranslatorInterface $translator
|
||||
)
|
||||
{
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
$this->roleProvider = $roleProvider;
|
||||
$this->roleHierarchy = $roleHierarchy;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all PermissionsGroup entities.
|
||||
*
|
||||
@@ -30,7 +73,7 @@ class PermissionsGroupController extends Controller
|
||||
|
||||
$entities = $em->getRepository('ChillMainBundle:PermissionsGroup')->findAll();
|
||||
|
||||
return $this->render('ChillMainBundle:PermissionsGroup:index.html.twig', array(
|
||||
return $this->render('@ChillMain/PermissionsGroup/index.html.twig', array(
|
||||
'entities' => $entities,
|
||||
));
|
||||
}
|
||||
@@ -54,7 +97,7 @@ class PermissionsGroupController extends Controller
|
||||
array('id' => $permissionsGroup->getId())));
|
||||
}
|
||||
|
||||
return $this->render('ChillMainBundle:PermissionsGroup:new.html.twig', array(
|
||||
return $this->render('@ChillMain/PermissionsGroup/new.html.twig', array(
|
||||
'entity' => $permissionsGroup,
|
||||
'form' => $form->createView(),
|
||||
));
|
||||
@@ -88,7 +131,7 @@ class PermissionsGroupController extends Controller
|
||||
$permissionsGroup = new PermissionsGroup();
|
||||
$form = $this->createCreateForm($permissionsGroup);
|
||||
|
||||
return $this->render('ChillMainBundle:PermissionsGroup:new.html.twig', array(
|
||||
return $this->render('@ChillMain/PermissionsGroup/new.html.twig', array(
|
||||
'entity' => $permissionsGroup,
|
||||
'form' => $form->createView(),
|
||||
));
|
||||
@@ -108,7 +151,7 @@ class PermissionsGroupController extends Controller
|
||||
throw $this->createNotFoundException('Unable to find PermissionsGroup entity.');
|
||||
}
|
||||
|
||||
$translatableStringHelper = $this->get('chill.main.helper.translatable_string');
|
||||
$translatableStringHelper = $this->translatableStringHelper;
|
||||
$roleScopes = $permissionsGroup->getRoleScopes()->toArray();
|
||||
|
||||
// sort $roleScopes by name
|
||||
@@ -128,8 +171,7 @@ class PermissionsGroupController extends Controller
|
||||
});
|
||||
|
||||
// sort role scope by title
|
||||
/* @var $roleProvider \Chill\MainBundle\Security\RoleProvider */
|
||||
$roleProvider = $this->get('chill.main.role_provider');
|
||||
$roleProvider = $this->roleProvider;
|
||||
$roleScopesSorted = array();
|
||||
foreach($roleScopes as $roleScope) {
|
||||
/* @var $roleScope RoleScope */
|
||||
@@ -138,7 +180,7 @@ class PermissionsGroupController extends Controller
|
||||
}
|
||||
ksort($roleScopesSorted);
|
||||
|
||||
return $this->render('ChillMainBundle:PermissionsGroup:show.html.twig', array(
|
||||
return $this->render('@ChillMain/PermissionsGroup/show.html.twig', array(
|
||||
'entity' => $permissionsGroup,
|
||||
'role_scopes_sorted' => $roleScopesSorted,
|
||||
'expanded_roles' => $this->getExpandedRoles($roleScopes)
|
||||
@@ -158,11 +200,10 @@ class PermissionsGroupController extends Controller
|
||||
if (!array_key_exists($roleScope->getRole(), $expandedRoles)) {
|
||||
$expandedRoles[$roleScope->getRole()] =
|
||||
array_map(
|
||||
function(RoleInterface $role) {
|
||||
|
||||
function(Role $role) {
|
||||
return $role->getRole();
|
||||
},
|
||||
$this->get('security.role_hierarchy')
|
||||
$this->roleHierarchy
|
||||
->getReachableRoles(
|
||||
array(new Role($roleScope->getRole()))
|
||||
)
|
||||
@@ -198,8 +239,7 @@ class PermissionsGroupController extends Controller
|
||||
$addRoleScopesForm = $this->createAddRoleScopeForm($permissionsGroup);
|
||||
|
||||
// sort role scope by title
|
||||
/* @var $roleProvider \Chill\MainBundle\Security\RoleProvider */
|
||||
$roleProvider = $this->get('chill.main.role_provider');
|
||||
$roleProvider = $this->roleProvider;
|
||||
$roleScopesSorted = array();
|
||||
foreach($permissionsGroup->getRoleScopes()->toArray() as $roleScope) {
|
||||
/* @var $roleScope RoleScope */
|
||||
@@ -208,7 +248,7 @@ class PermissionsGroupController extends Controller
|
||||
}
|
||||
ksort($roleScopesSorted);
|
||||
|
||||
return $this->render('ChillMainBundle:PermissionsGroup:edit.html.twig', array(
|
||||
return $this->render('@ChillMain/PermissionsGroup/edit.html.twig', array(
|
||||
'entity' => $permissionsGroup,
|
||||
'role_scopes_sorted' => $roleScopesSorted,
|
||||
'edit_form' => $editForm->createView(),
|
||||
@@ -276,8 +316,7 @@ class PermissionsGroupController extends Controller
|
||||
$addRoleScopesForm = $this->createAddRoleScopeForm($permissionsGroup);
|
||||
|
||||
// sort role scope by title
|
||||
/* @var $roleProvider \Chill\MainBundle\Security\RoleProvider */
|
||||
$roleProvider = $this->get('chill.main.role_provider');
|
||||
$roleProvider = $this->roleProvider;
|
||||
$roleScopesSorted = array();
|
||||
foreach($permissionsGroup->getRoleScopes()->toArray() as $roleScope) {
|
||||
/* @var $roleScope RoleScope */
|
||||
@@ -286,7 +325,7 @@ class PermissionsGroupController extends Controller
|
||||
}
|
||||
ksort($roleScopesSorted);
|
||||
|
||||
return $this->render('ChillMainBundle:PermissionsGroup:edit.html.twig', array(
|
||||
return $this->render('@ChillMain/PermissionsGroup/edit.html.twig', array(
|
||||
'entity' => $permissionsGroup,
|
||||
'role_scopes_sorted' => $roleScopesSorted,
|
||||
'edit_form' => $editForm->createView(),
|
||||
@@ -352,10 +391,10 @@ class PermissionsGroupController extends Controller
|
||||
$permissionsGroup->removeRoleScope($roleScope);
|
||||
} catch (\RuntimeException $ex) {
|
||||
$this->addFlash('notice',
|
||||
$this->get('translator')->trans("The role '%role%' and circle "
|
||||
$this->translator->trans("The role '%role%' and circle "
|
||||
. "'%scope%' is not associated with this permission group", array(
|
||||
'%role%' => $this->get('translator')->trans($roleScope->getRole()),
|
||||
'%scope%' => $this->get('chill.main.helper.translatable_string')
|
||||
'%role%' => $this->translator->trans($roleScope->getRole()),
|
||||
'%scope%' => $this->translatableStringHelper
|
||||
->localize($roleScope->getScope()->getName())
|
||||
)));
|
||||
|
||||
@@ -367,16 +406,16 @@ class PermissionsGroupController extends Controller
|
||||
|
||||
if ($roleScope->getScope() !== NULL ) {
|
||||
$this->addFlash('notice',
|
||||
$this->get('translator')->trans("The role '%role%' on circle "
|
||||
$this->translator->trans("The role '%role%' on circle "
|
||||
. "'%scope%' has been removed", array(
|
||||
'%role%' => $this->get('translator')->trans($roleScope->getRole()),
|
||||
'%scope%' => $this->get('chill.main.helper.translatable_string')
|
||||
'%role%' => $this->translator->trans($roleScope->getRole()),
|
||||
'%scope%' => $this->translatableStringHelper
|
||||
->localize($roleScope->getScope()->getName())
|
||||
)));
|
||||
} else {
|
||||
$this->addFlash('notice',
|
||||
$this->get('translator')->trans("The role '%role%' has been removed", array(
|
||||
'%role%' => $this->get('translator')->trans($roleScope->getRole())
|
||||
$this->translator->trans("The role '%role%' has been removed", array(
|
||||
'%role%' => $this->translator->trans($roleScope->getRole())
|
||||
)));
|
||||
}
|
||||
|
||||
@@ -417,7 +456,7 @@ class PermissionsGroupController extends Controller
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('notice',
|
||||
$this->get('translator')->trans("The permissions have been added"));
|
||||
$this->translator->trans("The permissions have been added"));
|
||||
|
||||
return $this->redirect($this->generateUrl('admin_permissionsgroup_edit',
|
||||
array('id' => $id)));
|
||||
@@ -454,7 +493,7 @@ class PermissionsGroupController extends Controller
|
||||
}
|
||||
ksort($roleScopesSorted);
|
||||
|
||||
return $this->render('ChillMainBundle:PermissionsGroup:edit.html.twig', array(
|
||||
return $this->render('@ChillMain/PermissionsGroup/edit.html.twig', array(
|
||||
'entity' => $permissionsGroup,
|
||||
'edit_form' => $editForm->createView(),
|
||||
'role_scopes_sorted' => $roleScopesSorted,
|
||||
|
Reference in New Issue
Block a user