original_string: public static function update_tool_type($id, $name, $description, $state) {
          $params = self::validate_parameters(self::update_tool_type_parameters(),
                                              array(
                                                  'id' => $id,
                                                  'name' => $name,
                                                  'description' => $description,
                                                  'state' => $state,
                                              ));
          $id = $params['id'];
          $name = $params['name'];
          $description = $params['description'];
          $state = $params['state'];
  
          $context = context_system::instance();
          self::validate_context($context);
          require_capability('moodle/site:config', $context);
  
          $type = lti_get_type($id);
  
          if (empty($type)) {
              throw new moodle_exception('unabletofindtooltype', 'mod_lti', '', array('id' => $id));
          }
  
          if (!empty($name)) {
              $type->name = $name;
          }
  
          if (!empty($description)) {
              $type->description = $description;
          }
  
          if (!empty($state)) {
              // Valid state range.
              if (in_array($state, array(1, 2, 3))) {
                  $type->state = $state;
              } else {
                  throw new moodle_exception("Invalid state: $state - must be 1, 2, or 3");
              }
          }
  
          lti_update_type($type, new stdClass());
  
          return serialise_tool_type($type);
      }
code: public static function update_tool_type($id, $name, $description, $state) {
          $params = self::validate_parameters(self::update_tool_type_parameters(),
                                              array(
                                                  'id' => $id,
                                                  'name' => $name,
                                                  'description' => $description,
                                                  'state' => $state,
                                              ));
          $id = $params['id'];
          $name = $params['name'];
          $description = $params['description'];
          $state = $params['state'];
  
          $context = context_system::instance();
          self::validate_context($context);
          require_capability('moodle/site:config', $context);
  
          $type = lti_get_type($id);
  
          if (empty($type)) {
              throw new moodle_exception('unabletofindtooltype', 'mod_lti', '', array('id' => $id));
          }
  
          if (!empty($name)) {
              $type->name = $name;
          }
  
          if (!empty($description)) {
              $type->description = $description;
          }
  
          if (!empty($state)) {
              // Valid state range.
              if (in_array($state, array(1, 2, 3))) {
                  $type->state = $state;
              } else {
                  throw new moodle_exception("Invalid state: $state - must be 1, 2, or 3");
              }
          }
  
          lti_update_type($type, new stdClass());
  
          return serialise_tool_type($type);
      }
code_tokens: public static function update_tool_type ( $ id , $ name , $ description , $ state ) { $ params = self :: validate_parameters ( self :: update_tool_type_parameters ( ) , array ( 'id' => $ id , 'name' => $ name , 'description' => $ description , 'state' => $ state , ) ) ; $ id = $ params [ 'id' ] ; $ name = $ params [ 'name' ] ; $ description = $ params [ 'description' ] ; $ state = $ params [ 'state' ] ; $ context = context_system :: instance ( ) ; self :: validate_context ( $ context ) ; require_capability ( 'moodle/site:config' , $ context ) ; $ type = lti_get_type ( $ id ) ; if ( empty ( $ type ) ) { throw new moodle_exception ( 'unabletofindtooltype' , 'mod_lti' , '' , array ( 'id' => $ id ) ) ; } if ( ! empty ( $ name ) ) { $ type -> name = $ name ; } if ( ! empty ( $ description ) ) { $ type -> description = $ description ; } if ( ! empty ( $ state ) ) { // Valid state range. if ( in_array ( $ state , array ( 1 , 2 , 3 ) ) ) { $ type -> state = $ state ; } else { throw new moodle_exception ( "Invalid state: $state - must be 1, 2, or 3" ) ; } } lti_update_type ( $ type , new stdClass ( ) ) ; return serialise_tool_type ( $ type ) ; }
docstring: Update a tool type.
  
  @param int $id The id of the tool type to update
  @param string $name The name of the tool type
  @param string $description The name of the tool type
  @param int $state The state of the tool type
  @return array updated tool type
  @since Moodle 3.1
  @throws moodle_exception
docstring_tokens: Update a tool type .