Ejemplo n.º 1
0
 protected function body()
 {
     if (!$this->userHasPrivileges(User::usersPrivPresets)) {
         return false;
     }
     $privilegeGroups = array('users', 'subscriptions', 'plugins', 'assignments', 'submissions', 'lectures', 'groups', 'other');
     $inputs = array_merge(array('name' => array('isAlphaNumeric', 'isNotEmpty')), array_combine($privilegeGroups, array_pad(array(), count($privilegeGroups), array())));
     if (!$this->isInputValid($inputs)) {
         return false;
     }
     $id = $this->getParams('id');
     $name = $this->getParams('name');
     $privileges = array();
     foreach ($privilegeGroups as $i => $group) {
         $value = $this->getParams($group);
         $privileges = array_merge($privileges, $value != '' ? explode(';', $value) : array());
     }
     if (count($privileges)) {
         $privileges = array_combine($privileges, array_pad(array(), count($privileges), true));
     }
     $privileges = User::instance()->packPrivileges($privileges);
     if ($id === null || $id === '') {
         $usertype = new \UserType();
         $usertype->setName($name);
         $usertype->setPrivileges($privileges);
         Repositories::persistAndFlush($usertype);
     } else {
         /** @var \UserType $usertype */
         $usertype = Repositories::findEntity(Repositories::UserType, $id);
         $usertype->setName($name);
         $usertype->setPrivileges($privileges);
         Repositories::persistAndFlush($usertype);
     }
     return true;
 }