original_string: public final function can_be_edited_by_user() {
          global $USER;
  
          // We need to be able to explore the repository.
          try {
              $this->check_capability();
          } catch (repository_exception $e) {
              return false;
          }
  
          $repocontext = context::instance_by_id($this->instance->contextid);
          if ($repocontext->contextlevel == CONTEXT_USER && $repocontext->instanceid != $USER->id) {
              // If the context of this instance is a user context, we need to be this user.
              return false;
          } else if ($repocontext->contextlevel == CONTEXT_MODULE && !has_capability('moodle/course:update', $repocontext)) {
              // We need to have permissions on the course to edit the instance.
              return false;
          } else if ($repocontext->contextlevel == CONTEXT_SYSTEM && !has_capability('moodle/site:config', $repocontext)) {
              // Do not meet the requirements for the context system.
              return false;
          }
  
          return true;
      }
code: public final function can_be_edited_by_user() {
          global $USER;
  
          // We need to be able to explore the repository.
          try {
              $this->check_capability();
          } catch (repository_exception $e) {
              return false;
          }
  
          $repocontext = context::instance_by_id($this->instance->contextid);
          if ($repocontext->contextlevel == CONTEXT_USER && $repocontext->instanceid != $USER->id) {
              // If the context of this instance is a user context, we need to be this user.
              return false;
          } else if ($repocontext->contextlevel == CONTEXT_MODULE && !has_capability('moodle/course:update', $repocontext)) {
              // We need to have permissions on the course to edit the instance.
              return false;
          } else if ($repocontext->contextlevel == CONTEXT_SYSTEM && !has_capability('moodle/site:config', $repocontext)) {
              // Do not meet the requirements for the context system.
              return false;
          }
  
          return true;
      }
code_tokens: public final function can_be_edited_by_user ( ) { global $ USER ; // We need to be able to explore the repository. try { $ this -> check_capability ( ) ; } catch ( repository_exception $ e ) { return false ; } $ repocontext = context :: instance_by_id ( $ this -> instance -> contextid ) ; if ( $ repocontext -> contextlevel == CONTEXT_USER && $ repocontext -> instanceid != $ USER -> id ) { // If the context of this instance is a user context, we need to be this user. return false ; } else if ( $ repocontext -> contextlevel == CONTEXT_MODULE && ! has_capability ( 'moodle/course:update' , $ repocontext ) ) { // We need to have permissions on the course to edit the instance. return false ; } else if ( $ repocontext -> contextlevel == CONTEXT_SYSTEM && ! has_capability ( 'moodle/site:config' , $ repocontext ) ) { // Do not meet the requirements for the context system. return false ; } return true ; }
docstring: Can the instance be edited by the current user?
  
  The property $readonly must not be used within this method because
  it only controls if the options from self::get_instance_option_names()
  can be edited.
  
  @return bool true if the user can edit the instance.
  @since Moodle 2.5
docstring_tokens: Can the instance be edited by the current user?