Exemplo n.º 1
0
 /**
  * @param string $attribute
  * @param SessionTypeInterface $sessionType
  * @param UserInterface $user
  * @return bool
  */
 protected function isGranted($attribute, $sessionType, $user = null)
 {
     if (!$user instanceof UserInterface) {
         return false;
     }
     switch ($attribute) {
         // grant VIEW privileges
         // if the user's primary school is the session type's owning school
         // - or -
         // if the user has READ rights on the session type's owning school
         // via the permissions system.
         case self::VIEW:
             return $this->schoolsAreIdentical($sessionType->getSchool(), $user->getSchool()) || $this->permissionManager->userHasReadPermissionToSchool($user, $sessionType->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 session type's owning school
             //   - or -
             //   if the user has WRITE rights on the session type's owning school
             // via the permissions system.
             return $this->userHasRole($user, ['Developer']) && ($this->schoolsAreIdentical($sessionType->getSchool(), $user->getSchool()) || $this->permissionManager->userHasWritePermissionToSchool($user, $sessionType->getSchool()));
             break;
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * @param string $attribute
  * @param SessionTypeInterface $sessionType
  * @param TokenInterface $token
  * @return bool
  */
 protected function voteOnAttribute($attribute, $sessionType, TokenInterface $token)
 {
     $user = $token->getUser();
     if (!$user instanceof UserInterface) {
         return false;
     }
     switch ($attribute) {
         // grant VIEW privileges
         // do not impose any restrictions.
         case self::VIEW:
             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 session type's owning school
             //   - or -
             //   if the user has WRITE rights on the session type's owning school
             // via the permissions system.
             return $this->userHasRole($user, ['Developer']) && ($this->schoolsAreIdentical($sessionType->getSchool(), $user->getSchool()) || $this->permissionManager->userHasWritePermissionToSchool($user, $sessionType->getSchool()->getId()));
             break;
     }
     return false;
 }
 /**
  * @param array $data
  * @param SessionTypeInterface $entity
  */
 protected function assertDataEquals(array $data, $entity)
 {
     // `session_type_id`,`method_id`
     $this->assertEquals($data[0], $entity->getId());
     // find the AAMC method
     $methodId = $data[1];
     $method = $entity->getAamcMethods()->filter(function (AamcMethodInterface $method) use($methodId) {
         return $method->getId() === $methodId;
     })->first();
     $this->assertNotEmpty($method);
 }
Exemplo n.º 4
0
 /**
  * @param SessionTypeInterface $entity
  * @param array $data
  * @return SessionTypeInterface
  *
  * @see AbstractFixture::populateEntity()
  */
 protected function populateEntity($entity, array $data)
 {
     // `session_type_id`,`title`,`school_id`,`session_type_css_class`,`assessment`,`assessment_option_id`
     $entity->setId($data[0]);
     $entity->setTitle($data[1]);
     $entity->setSchool($this->getReference('school' . $data[2]));
     $entity->setSessionTypeCssClass($data[3]);
     $entity->setAssessment((bool) $data[4]);
     if (!empty($data[5])) {
         $entity->setAssessmentOption($this->getReference('assessment_option' . $data[5]));
     }
     return $entity;
 }
Exemplo n.º 5
0
 /**
  * @param array $data
  * @param SessionTypeInterface $entity
  */
 protected function assertDataEquals(array $data, $entity)
 {
     // `session_type_id`,`title`,`school_id`,`session_type_css_class`,`assessment`,`assessment_option_id`
     $this->assertEquals($data[0], $entity->getId());
     $this->assertEquals($data[1], $entity->getTitle());
     $this->assertEquals($data[2], $entity->getSchool()->getId());
     $this->assertEquals($data[3], $entity->getSessionTypeCssClass());
     $this->assertEquals((bool) $data[4], $entity->isAssessment());
     if (empty($data[5])) {
         $this->assertNull($entity->getAssessmentOption());
     } else {
         $this->assertEquals($data[5], $entity->getAssessmentOption());
     }
 }