Пример #1
0
 public function rolesAction(Request $request, $id)
 {
     if (false === $this->get('security.context')->isGranted('ROLE_SUPER_ADMIN') && false === $this->get('security.context')->isGranted('ROLE_ADMIN')) {
         throw $this->createAccessDeniedException();
     }
     $user = $this->getUserService()->getUser($id);
     $currentUser = $this->getCurrentUser();
     if ($request->getMethod() == 'POST') {
         $roles = $request->request->get('roles');
         $this->getUserService()->changeUserRoles($user['id'], $roles);
         $dataDict = new UserRoleDict();
         $roleDict = $dataDict->getDict();
         $role = "";
         $roleCount = count($roles);
         $deletedRoles = array_diff($user['roles'], $roles);
         $addedRoles = array_diff($roles, $user['roles']);
         if (!empty($deletedRoles) || !empty($addedRoles)) {
             for ($i = 0; $i < $roleCount; $i++) {
                 $role .= $roleDict[$roles[$i]];
                 if ($i < $roleCount - 1) {
                     $role .= "、";
                 }
             }
             $message = array('userId' => $currentUser['id'], 'userName' => $currentUser['nickname'], 'role' => $role);
             $this->getNotifiactionService()->notify($user['id'], 'role', $message);
         }
         if (in_array('ROLE_TEACHER', $user['roles']) && !in_array('ROLE_TEACHER', $roles)) {
             $this->getCourseService()->cancelTeacherInAllCourses($user['id']);
         }
         $user = $this->getUserService()->getUser($id);
         return $this->render('TopxiaAdminBundle:User:user-table-tr.html.twig', array('user' => $user));
     }
     $default = $this->getSettingService()->get('default', array());
     return $this->render('TopxiaAdminBundle:User:roles-modal.html.twig', array('user' => $user, 'default' => $default));
 }
Пример #2
0
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $dataDict = new UserRoleDict();
     $resolver->setDefaults(array('choices' => $dataDict->getGroupedDict()));
 }