src/App/Service/Content/ContentSchoolProvider.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\Service\Content;
  3. use App\Entity\Feed\AbstractEntry;
  4. use App\Entity\System\School;
  5. use App\Util\Permissions;
  6. use Cms\CoreBundle\Util\Doctrine\EntityManager;
  7. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  8. class ContentSchoolProvider
  9. {
  10.     private EntityManager $em;
  11.     private AuthorizationCheckerInterface $authorizationChecker;
  12.     /**
  13.      * @param EntityManager $em
  14.      * @param AuthorizationCheckerInterface $authorizationChecker
  15.      */
  16.     public function __construct(
  17.         EntityManager $em,
  18.         AuthorizationCheckerInterface $authorizationChecker
  19.     )
  20.     {
  21.         $this->em $em;
  22.         $this->authorizationChecker $authorizationChecker;
  23.     }
  24.     /**
  25.      * @return School[]
  26.      */
  27.     public function getSchools(): array
  28.     {
  29.         static $perms = [
  30.             'campussuite.cms.container.generic.manage',// schools only use generic departments right now...
  31.             'campussuite.cms.module.manage',
  32.             'campussuite.cms.modules.calendar.manage',
  33.             'campussuite.cms.modules.gallery.manage',
  34.             'campussuite.cms.modules.news.manage',
  35.         ];
  36.         $schools = [];
  37.         foreach ($this->em->getRepository(School::class)->findAll() as $school) {
  38.             if ($this->authorizationChecker->isGranted(Permissions::attributesExpression($perms), $school)) {
  39.                 $schools[] = $school;
  40.             }
  41.         }
  42.         return $schools;
  43.     }
  44.     /**
  45.      * @param School $school
  46.      * @return array
  47.      */
  48.     public function getSchoolAllowedEntryTypes(School $school): array
  49.     {
  50.         // NOTE: since the input is a school, we should only ever have a "generic" department tied to it...
  51.         static $mappings = [
  52.             AbstractEntry::TYPES__POST => [
  53.                 'campussuite.cms.container.generic.manage',
  54.                 'campussuite.cms.module.manage',
  55.                 'campussuite.cms.modules.news.manage',
  56.             ],
  57.             AbstractEntry::TYPES__GALLERY => [
  58.                 'campussuite.cms.container.generic.manage',
  59.                 'campussuite.cms.module.manage',
  60.                 'campussuite.cms.modules.gallery.manage',
  61.             ],
  62.             AbstractEntry::TYPES__EVENT => [
  63.                 'campussuite.cms.container.generic.manage',
  64.                 'campussuite.cms.module.manage',
  65.                 'campussuite.cms.modules.calendar.manage',
  66.             ],
  67.             AbstractEntry::TYPES__VIDEO => [
  68.                 'campussuite.cms.container.generic.manage',
  69.                 'campussuite.cms.module.manage',
  70.                 'campussuite.cms.modules.gallery.manage',
  71.             ],
  72.         ];
  73.         $types = [];
  74.         foreach ($mappings as $type => $perms) {
  75.             if ($this->authorizationChecker->isGranted(Permissions::attributesExpression($perms), [null$school->getDepartment()])) {
  76.                 $types[] = $type;
  77.             }
  78.         }
  79.         return $types;
  80.     }
  81. }