original_string: public static function guess_by_name($name, $returnfields='id, name, rawname, tagcollid') {
          global $DB;
          if (empty($name)) {
              return array();
          }
          $tagcolls = core_tag_collection::get_collections();
          list($sql, $params) = $DB->get_in_or_equal(array_keys($tagcolls), SQL_PARAMS_NAMED);
          $params['name'] = core_text::strtolower($name);
          $tags = $DB->get_records_select('tag', 'name = :name AND tagcollid ' . $sql, $params, '', $returnfields);
          if (count($tags) > 1) {
              // Sort in the same order as tag collections.
              $tagcolls = core_tag_collection::get_collections();
              uasort($tags, function($a, $b) use ($tagcolls) {
                  return $tagcolls[$a->tagcollid]->sortorder < $tagcolls[$b->tagcollid]->sortorder ? -1 : 1;
              });
          }
          $rv = array();
          foreach ($tags as $id => $tag) {
              $rv[$id] = new static($tag);
          }
          return $rv;
      }
code: public static function guess_by_name($name, $returnfields='id, name, rawname, tagcollid') {
          global $DB;
          if (empty($name)) {
              return array();
          }
          $tagcolls = core_tag_collection::get_collections();
          list($sql, $params) = $DB->get_in_or_equal(array_keys($tagcolls), SQL_PARAMS_NAMED);
          $params['name'] = core_text::strtolower($name);
          $tags = $DB->get_records_select('tag', 'name = :name AND tagcollid ' . $sql, $params, '', $returnfields);
          if (count($tags) > 1) {
              // Sort in the same order as tag collections.
              $tagcolls = core_tag_collection::get_collections();
              uasort($tags, function($a, $b) use ($tagcolls) {
                  return $tagcolls[$a->tagcollid]->sortorder < $tagcolls[$b->tagcollid]->sortorder ? -1 : 1;
              });
          }
          $rv = array();
          foreach ($tags as $id => $tag) {
              $rv[$id] = new static($tag);
          }
          return $rv;
      }
code_tokens: public static function guess_by_name ( $ name , $ returnfields = 'id, name, rawname, tagcollid' ) { global $ DB ; if ( empty ( $ name ) ) { return array ( ) ; } $ tagcolls = core_tag_collection :: get_collections ( ) ; list ( $ sql , $ params ) = $ DB -> get_in_or_equal ( array_keys ( $ tagcolls ) , SQL_PARAMS_NAMED ) ; $ params [ 'name' ] = core_text :: strtolower ( $ name ) ; $ tags = $ DB -> get_records_select ( 'tag' , 'name = :name AND tagcollid ' . $ sql , $ params , '' , $ returnfields ) ; if ( count ( $ tags ) > 1 ) { // Sort in the same order as tag collections. $ tagcolls = core_tag_collection :: get_collections ( ) ; uasort ( $ tags , function ( $ a , $ b ) use ( $ tagcolls ) { return $ tagcolls [ $ a -> tagcollid ] -> sortorder < $ tagcolls [ $ b -> tagcollid ] -> sortorder ? - 1 : 1 ; } ) ; } $ rv = array ( ) ; foreach ( $ tags as $ id => $ tag ) { $ rv [ $ id ] = new static ( $ tag ) ; } return $ rv ; }
docstring: Looking in all tag collections for the tag with the given name
  
  @param string $name tag name
  @param string $returnfields
  @return array array of core_tag_tag instances
docstring_tokens: Looking in all tag collections for the tag with the given name