示例#1
0
 /**
  * @param string $attribute
  * @param CompetencyInterface $competency
  * @param UserInterface $user
  * @return bool
  */
 protected function isGranted($attribute, $competency, $user = null)
 {
     if (!$user instanceof UserInterface) {
         return false;
     }
     switch ($attribute) {
         // grant VIEW privileges
         // if the user's primary school is the the competency's owning school
         // - or -
         // if the user has READ rights on the competency's owning school
         // via the permissions system.
         case self::VIEW:
             return $this->schoolsAreIdentical($competency->getSchool(), $user->getSchool()) || $this->permissionManager->userHasReadPermissionToSchool($user, $competency->getSchool());
             break;
         case self::CREATE:
         case self::EDIT:
         case self::DELETE:
             // grant CREATE, EDIT and DELETE privileges
             // if the user has the 'Developer' role
             // - and -
             //   if the user's primary school is the the competency's owning school
             //   - or -
             //   if the user has WRITE rights on the competency's owning school
             // via the permissions system.
             return $this->userHasRole($user, ['Developer']) && ($this->schoolsAreIdentical($competency->getSchool(), $user->getSchool()) || $this->permissionManager->userHasWritePermissionToSchool($user, $competency->getSchool()));
             break;
     }
     return false;
 }
 /**
  * @param string $attribute
  * @param CompetencyInterface $competency
  * @param TokenInterface $token
  * @return bool
  */
 protected function voteOnAttribute($attribute, $competency, TokenInterface $token)
 {
     $user = $token->getUser();
     if (!$user instanceof UserInterface) {
         return false;
     }
     switch ($attribute) {
         case self::VIEW:
             // do not enforce special view permissions.
             return true;
             break;
         case self::CREATE:
         case self::EDIT:
         case self::DELETE:
             // grant CREATE, EDIT and DELETE privileges
             // if the user has the 'Developer' role
             // - and -
             //   if the user's primary school is the the competency's owning school
             //   - or -
             //   if the user has WRITE rights on the competency's owning school
             // via the permissions system.
             return $this->userHasRole($user, ['Developer']) && ($this->schoolsAreIdentical($competency->getSchool(), $user->getSchool()) || $this->permissionManager->userHasWritePermissionToSchool($user, $competency->getSchool()->getId()));
             break;
     }
     return false;
 }
 /**
  * @param array $data
  * @param CompetencyInterface $entity
  */
 protected function assertDataEquals(array $data, $entity)
 {
     // `competency_id`,`pcrs_id`
     $this->assertEquals($data[0], $entity->getId());
     // find the PCRS
     $pcrsId = $data[1];
     $pcrs = $entity->getAamcPcrses()->filter(function (AamcPcrsInterface $pcrs) use($pcrsId) {
         return $pcrs->getId() === $pcrsId;
     })->first();
     $this->assertNotEmpty($pcrs);
 }
示例#4
0
 /**
  * @param CompetencyInterface $entity
  * @param array $data
  * @return CompetencyInterface
  *
  * @see AbstractFixture::populateEntity()
  */
 protected function populateEntity($entity, array $data)
 {
     // `competency_id`,`title`,`parent_competency_id`,`school_id`, `active`
     $entity->setId($data[0]);
     $entity->setTitle($data[1]);
     if (!empty($data[2])) {
         $entity->setParent($this->getReference($this->getKey() . $data[2]));
     }
     $entity->setSchool($this->getReference('school' . $data[3]));
     $entity->setActive((bool) $data[4]);
     return $entity;
 }
 /**
  * @param array $data
  * @param CompetencyInterface $entity
  */
 protected function assertDataEquals(array $data, $entity)
 {
     // `competency_id`,`title`,`parent_competency_id`,`school_id`,`active`
     $this->assertEquals($data[0], $entity->getId());
     $this->assertEquals($data[1], $entity->getTitle());
     if (empty($data[2])) {
         $this->assertNull($entity->getParent());
     } else {
         $this->assertEquals($data[2], $entity->getParent()->getId());
     }
     $this->assertEquals($data[3], $entity->getSchool()->getId());
     $this->assertEquals((bool) $data[4], $entity->isActive());
 }