Beispiel #1
0
 /**
  * Tests the setters.
  */
 public function testSetters()
 {
     $user = new User();
     $this->assertEquals(null, $user->getSalt());
     $this->assertEquals(['ROLE_USER'], $user->getRoles());
     // set username
     $user->setUsername('Joanne');
     $this->assertEquals('Joanne', $user->getUsername());
     // set pw and salt
     $user->setPassword('hostile');
     $this->assertEquals('hostile', $user->getPassword());
     $this->assertEquals(null, $user->getSalt());
     // set email
     $user->setEmail('test2@localhost');
     $this->assertEquals('test2@localhost', $user->getEmail());
     // set roles
     $roles = ['ROLE_ACP_ACCESS', 'ROLE_USER'];
     $user->setRoles($roles);
     $this->assertEquals($roles, $user->getRoles());
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function getEffective(User $user, $superCategory, $category, $optionName)
 {
     $groupNames = $user->getGroupNames();
     /** @var Option[] $options */
     $options = [];
     foreach ($groupNames as $name) {
         $options[$name] = $this->get($name, $superCategory, $category, $optionName);
     }
     $returnValue = null;
     foreach ($options as $name => $option) {
         if (!isset($this->optionTypes[$superCategory][$category][$optionName])) {
             // if this happens, somebody somewhere screwed up
             // we must return null, as there is no way to simply
             // ignore this
             $returnValue = null;
             break;
         }
         /** @var OptionTypeInterface $type */
         $type = $this->optionTypes[$superCategory][$category][$optionName];
         $returnValue = $type->getBestValue($returnValue, $option);
     }
     return $returnValue;
 }
 /**
  * Updates the group assignment of given user.
  *
  * @param Form $form
  * @param User $user
  */
 private function updateGroupAssignment(Form $form, User $user)
 {
     /** @var ObjectManager $objectManager */
     $objectManager = $this->get('twomartens.core.db_manager');
     $repository = $objectManager->getRepository('TwoMartensCoreBundle:Group');
     /** @var Collection $groups */
     $groups = new ArrayCollection($repository->findAll());
     $submittedGroups = $form->get('groups')->getData();
     foreach ($groups as $group) {
         /** @var Group $group */
         if (in_array($group->getRoleName(), $submittedGroups)) {
             $user->addGroup($group);
             $group->addUser($user);
         } else {
             // don't remove user from group if he is last user and group
             // must not be empty
             if (!$group->canBeEmpty() && $group->getUsers()->count() <= 1) {
                 continue;
             }
             $user->removeGroup($group);
             $group->removeUser($user);
         }
     }
 }