コード例 #1
0
ファイル: RoleRepository.php プロジェクト: mhilker/user
 /**
  * @param Role $role
  */
 public function save(Role $role)
 {
     if (!$role->getId()) {
         $role->setId(null);
         $this->_em->persist($role);
     }
     $this->_em->flush($role);
 }
コード例 #2
0
 public function getAdminRole()
 {
     $guest = $this->getOneObjectByField(Role::getClass(), 'roleId', Role::ROLE_GUEST);
     if (!$guest) {
         $guest = new Role();
         $guest->setRoleId(Role::ROLE_GUEST);
         $guest = $this->saveObject($guest);
     }
     $user = $this->getOneObjectByField(Role::getClass(), 'roleId', Role::ROLE_USER);
     if (!$user) {
         $user = new Role();
         $user->setRoleId(Role::ROLE_USER);
         $user->setParent($guest);
         $user = $this->saveObject($user);
     }
     $admin = $this->getOneObjectByField(Role::getClass(), 'roleId', Role::ROLE_ADMIN);
     if (!$admin) {
         $admin = new Role();
         $admin->setRoleId(Role::ROLE_ADMIN);
         $admin->setParent($user);
         $admin = $this->saveObject($admin);
     }
     return $admin;
 }