original_string: public static function remove_item_tag($component, $itemtype, $itemid, $tagname, $tiuserid = 0) {
          global $DB;
  
          if (static::is_enabled($component, $itemtype) === false) {
              // Tagging area is properly defined but not enabled - do nothing.
              return array();
          }
  
          $rawname = clean_param($tagname, PARAM_TAG);
          $normalisedname = core_text::strtolower($rawname);
  
          $usersql = $tiuserid ? " AND tiuserid = :tiuserid " : "";
          $componentsql = $component ? " AND ti.component = :component " : "";
          $sql = 'SELECT t.*, ti.id AS taginstanceid, ti.contextid AS taginstancecontextid, ti.ordering
                  FROM {tag} t JOIN {tag_instance} ti ON ti.tagid = t.id ' . $usersql . '
                  WHERE t.name = :name AND ti.itemtype = :itemtype
                  AND ti.itemid = :itemid ' . $componentsql;
          $params = array('name' => $normalisedname,
              'itemtype' => $itemtype, 'itemid' => $itemid, 'component' => $component,
              'tiuserid' => $tiuserid);
          if ($record = $DB->get_record_sql($sql, $params)) {
              $taginstance = (object)array('id' => $record->taginstanceid,
                  'itemtype' => $itemtype, 'itemid' => $itemid,
                  'contextid' => $record->taginstancecontextid, 'tiuserid' => $tiuserid);
              $tag = new static($record);
              $tag->delete_instance_as_record($taginstance, false);
              $componentsql = $component ? " AND component = :component " : "";
              $sql = "UPDATE {tag_instance} SET ordering = ordering - 1
                      WHERE itemtype = :itemtype
                  AND itemid = :itemid $componentsql $usersql
                  AND ordering > :ordering";
              $params['ordering'] = $record->ordering;
              $DB->execute($sql, $params);
          }
      }
code: public static function remove_item_tag($component, $itemtype, $itemid, $tagname, $tiuserid = 0) {
          global $DB;
  
          if (static::is_enabled($component, $itemtype) === false) {
              // Tagging area is properly defined but not enabled - do nothing.
              return array();
          }
  
          $rawname = clean_param($tagname, PARAM_TAG);
          $normalisedname = core_text::strtolower($rawname);
  
          $usersql = $tiuserid ? " AND tiuserid = :tiuserid " : "";
          $componentsql = $component ? " AND ti.component = :component " : "";
          $sql = 'SELECT t.*, ti.id AS taginstanceid, ti.contextid AS taginstancecontextid, ti.ordering
                  FROM {tag} t JOIN {tag_instance} ti ON ti.tagid = t.id ' . $usersql . '
                  WHERE t.name = :name AND ti.itemtype = :itemtype
                  AND ti.itemid = :itemid ' . $componentsql;
          $params = array('name' => $normalisedname,
              'itemtype' => $itemtype, 'itemid' => $itemid, 'component' => $component,
              'tiuserid' => $tiuserid);
          if ($record = $DB->get_record_sql($sql, $params)) {
              $taginstance = (object)array('id' => $record->taginstanceid,
                  'itemtype' => $itemtype, 'itemid' => $itemid,
                  'contextid' => $record->taginstancecontextid, 'tiuserid' => $tiuserid);
              $tag = new static($record);
              $tag->delete_instance_as_record($taginstance, false);
              $componentsql = $component ? " AND component = :component " : "";
              $sql = "UPDATE {tag_instance} SET ordering = ordering - 1
                      WHERE itemtype = :itemtype
                  AND itemid = :itemid $componentsql $usersql
                  AND ordering > :ordering";
              $params['ordering'] = $record->ordering;
              $DB->execute($sql, $params);
          }
      }
code_tokens: public static function remove_item_tag ( $ component , $ itemtype , $ itemid , $ tagname , $ tiuserid = 0 ) { global $ DB ; if ( static :: is_enabled ( $ component , $ itemtype ) === false ) { // Tagging area is properly defined but not enabled - do nothing. return array ( ) ; } $ rawname = clean_param ( $ tagname , PARAM_TAG ) ; $ normalisedname = core_text :: strtolower ( $ rawname ) ; $ usersql = $ tiuserid ? " AND tiuserid = :tiuserid " : "" ; $ componentsql = $ component ? " AND ti.component = :component " : "" ; $ sql = 'SELECT t.*, ti.id AS taginstanceid, ti.contextid AS taginstancecontextid, ti.ordering
                  FROM {tag} t JOIN {tag_instance} ti ON ti.tagid = t.id ' . $ usersql . '
                  WHERE t.name = :name AND ti.itemtype = :itemtype
                  AND ti.itemid = :itemid ' . $ componentsql ; $ params = array ( 'name' => $ normalisedname , 'itemtype' => $ itemtype , 'itemid' => $ itemid , 'component' => $ component , 'tiuserid' => $ tiuserid ) ; if ( $ record = $ DB -> get_record_sql ( $ sql , $ params ) ) { $ taginstance = ( object ) array ( 'id' => $ record -> taginstanceid , 'itemtype' => $ itemtype , 'itemid' => $ itemid , 'contextid' => $ record -> taginstancecontextid , 'tiuserid' => $ tiuserid ) ; $ tag = new static ( $ record ) ; $ tag -> delete_instance_as_record ( $ taginstance , false ) ; $ componentsql = $ component ? " AND component = :component " : "" ; $ sql = "UPDATE {tag_instance} SET ordering = ordering - 1
                      WHERE itemtype = :itemtype
                  AND itemid = :itemid $componentsql $usersql
                  AND ordering > :ordering" ; $ params [ 'ordering' ] = $ record -> ordering ; $ DB -> execute ( $ sql , $ params ) ; } }
docstring: Removes the tag from an item without changing the other tags
  
  @param string $component the component that was tagged
  @param string $itemtype the type of record to tag ('post' for blogs, 'user' for users, etc.)
  @param int $itemid the id of the record to tag
  @param string $tagname the tag to remove
  @param int $tiuserid tag instance user id, only needed for tag areas with user tagging (such as core/course)
docstring_tokens: Removes the tag from an item without changing the other tags