original_string: public function setUserAccess($userLogin, $access, $idSites)
      {
          if ($access != 'noaccess') {
              $this->checkAccessType($access);
          }
  
          $idSites = $this->getIdSitesCheckAdminAccess($idSites);
  
          if ($userLogin === 'anonymous' &&
              (is_array($access) || !in_array($access, array('view', 'noaccess'), true))
          ) {
              throw new Exception(Piwik::translate("UsersManager_ExceptionAnonymousAccessNotPossible", array('noaccess', 'view')));
          }
  
          $roles = array();
          $capabilities = array();
  
          if (is_array($access)) {
              // we require one role, and optionally multiple capabilties
              list($roles, $capabilities) = $this->getRoleAndCapabilitiesFromAccess($access);
  
              if (count($roles) < 1) {
                  $ids = implode(', ', $this->roleProvider->getAllRoleIds());
                  throw new Exception(Piwik::translate('UsersManager_ExceptionNoRoleSet', $ids));
              }
  
              if (count($roles) > 1) {
                  $ids = implode(', ', $this->roleProvider->getAllRoleIds());
                  throw new Exception(Piwik::translate('UsersManager_ExceptionMultipleRoleSet', $ids));
              }
  
          } else {
              // as only one access is set, we require it to be a role or "noaccess"...
              if ($access !== 'noaccess') {
                  $this->roleProvider->checkValidRole($access);
                  $roles[] = $access;
              }
          }
  
          $this->checkUserExist($userLogin);
          $this->checkUsersHasNotSuperUserAccess($userLogin);
  
          $this->model->deleteUserAccess($userLogin, $idSites);
  
          if ($access === 'noaccess') {
              // if the access is noaccess then we don't save it as this is the default value
              // when no access are specified
              Piwik::postEvent('UsersManager.removeSiteAccess', array($userLogin, $idSites));
          } else {
              $role = array_shift($roles);
              $this->model->addUserAccess($userLogin, $role, $idSites);
          }
  
          if (!empty($capabilities)) {
              $this->addCapabilities($userLogin, $capabilities, $idSites);
          }
  
          // we reload the access list which doesn't yet take in consideration this new user access
          $this->reloadPermissions();
      }
code: public function setUserAccess($userLogin, $access, $idSites)
      {
          if ($access != 'noaccess') {
              $this->checkAccessType($access);
          }
  
          $idSites = $this->getIdSitesCheckAdminAccess($idSites);
  
          if ($userLogin === 'anonymous' &&
              (is_array($access) || !in_array($access, array('view', 'noaccess'), true))
          ) {
              throw new Exception(Piwik::translate("UsersManager_ExceptionAnonymousAccessNotPossible", array('noaccess', 'view')));
          }
  
          $roles = array();
          $capabilities = array();
  
          if (is_array($access)) {
              // we require one role, and optionally multiple capabilties
              list($roles, $capabilities) = $this->getRoleAndCapabilitiesFromAccess($access);
  
              if (count($roles) < 1) {
                  $ids = implode(', ', $this->roleProvider->getAllRoleIds());
                  throw new Exception(Piwik::translate('UsersManager_ExceptionNoRoleSet', $ids));
              }
  
              if (count($roles) > 1) {
                  $ids = implode(', ', $this->roleProvider->getAllRoleIds());
                  throw new Exception(Piwik::translate('UsersManager_ExceptionMultipleRoleSet', $ids));
              }
  
          } else {
              // as only one access is set, we require it to be a role or "noaccess"...
              if ($access !== 'noaccess') {
                  $this->roleProvider->checkValidRole($access);
                  $roles[] = $access;
              }
          }
  
          $this->checkUserExist($userLogin);
          $this->checkUsersHasNotSuperUserAccess($userLogin);
  
          $this->model->deleteUserAccess($userLogin, $idSites);
  
          if ($access === 'noaccess') {
              // if the access is noaccess then we don't save it as this is the default value
              // when no access are specified
              Piwik::postEvent('UsersManager.removeSiteAccess', array($userLogin, $idSites));
          } else {
              $role = array_shift($roles);
              $this->model->addUserAccess($userLogin, $role, $idSites);
          }
  
          if (!empty($capabilities)) {
              $this->addCapabilities($userLogin, $capabilities, $idSites);
          }
  
          // we reload the access list which doesn't yet take in consideration this new user access
          $this->reloadPermissions();
      }
code_tokens: public function setUserAccess ( $ userLogin , $ access , $ idSites ) { if ( $ access != 'noaccess' ) { $ this -> checkAccessType ( $ access ) ; } $ idSites = $ this -> getIdSitesCheckAdminAccess ( $ idSites ) ; if ( $ userLogin === 'anonymous' && ( is_array ( $ access ) || ! in_array ( $ access , array ( 'view' , 'noaccess' ) , true ) ) ) { throw new Exception ( Piwik :: translate ( "UsersManager_ExceptionAnonymousAccessNotPossible" , array ( 'noaccess' , 'view' ) ) ) ; } $ roles = array ( ) ; $ capabilities = array ( ) ; if ( is_array ( $ access ) ) { // we require one role, and optionally multiple capabilties list ( $ roles , $ capabilities ) = $ this -> getRoleAndCapabilitiesFromAccess ( $ access ) ; if ( count ( $ roles ) < 1 ) { $ ids = implode ( ', ' , $ this -> roleProvider -> getAllRoleIds ( ) ) ; throw new Exception ( Piwik :: translate ( 'UsersManager_ExceptionNoRoleSet' , $ ids ) ) ; } if ( count ( $ roles ) > 1 ) { $ ids = implode ( ', ' , $ this -> roleProvider -> getAllRoleIds ( ) ) ; throw new Exception ( Piwik :: translate ( 'UsersManager_ExceptionMultipleRoleSet' , $ ids ) ) ; } } else { // as only one access is set, we require it to be a role or "noaccess"... if ( $ access !== 'noaccess' ) { $ this -> roleProvider -> checkValidRole ( $ access ) ; $ roles [ ] = $ access ; } } $ this -> checkUserExist ( $ userLogin ) ; $ this -> checkUsersHasNotSuperUserAccess ( $ userLogin ) ; $ this -> model -> deleteUserAccess ( $ userLogin , $ idSites ) ; if ( $ access === 'noaccess' ) { // if the access is noaccess then we don't save it as this is the default value // when no access are specified Piwik :: postEvent ( 'UsersManager.removeSiteAccess' , array ( $ userLogin , $ idSites ) ) ; } else { $ role = array_shift ( $ roles ) ; $ this -> model -> addUserAccess ( $ userLogin , $ role , $ idSites ) ; } if ( ! empty ( $ capabilities ) ) { $ this -> addCapabilities ( $ userLogin , $ capabilities , $ idSites ) ; } // we reload the access list which doesn't yet take in consideration this new user access $ this -> reloadPermissions ( ) ; }
docstring: Set an access level to a given user for a list of websites ID.
  
  If access = 'noaccess' the current access (if any) will be deleted.
  If access = 'view' or 'admin' the current access level is deleted and updated with the new value.
  
  @param string $userLogin The user login
  @param string|array $access Access to grant. Must have one of the following value : noaccess, view, write, admin.
  May also be an array to sent additional capabilities
  @param int|array $idSites The array of idSites on which to apply the access level for the user.
  If the value is "all" then we apply the access level to all the websites ID for which the current authentificated user has an 'admin' access.
  @throws Exception if the user doesn't exist
  @throws Exception if the access parameter doesn't have a correct value
  @throws Exception if any of the given website ID doesn't exist
docstring_tokens: Set an access level to a given user for a list of websites ID .