original_string: public static function get_tag_cloud($tagcollid, $isstandard = false, $limit = 150, $sort = 'name',
              $search = '', $fromctx = 0, $ctx = 0, $rec = 1) {
          global $DB;
  
          $fromclause = 'FROM {tag_instance} ti JOIN {tag} tg ON tg.id = ti.tagid';
          $whereclause = 'WHERE ti.itemtype <> \'tag\'';
          list($sql, $params) = $DB->get_in_or_equal($tagcollid ? array($tagcollid) :
              array_keys(self::get_collections(true)));
          $whereclause .= ' AND tg.tagcollid ' . $sql;
          if ($isstandard) {
              $whereclause .= ' AND tg.isstandard = 1';
          }
          $context = $ctx ? context::instance_by_id($ctx) : context_system::instance();
          if ($rec && $context->contextlevel != CONTEXT_SYSTEM) {
              $fromclause .= ' JOIN {context} ctx ON ctx.id = ti.contextid ';
              $whereclause .= ' AND ctx.path LIKE ?';
              $params[] = $context->path . '%';
          } else if (!$rec) {
              $whereclause .= ' AND ti.contextid = ?';
              $params[] = $context->id;
          }
          if (strval($search) !== '') {
              $whereclause .= ' AND tg.name LIKE ?';
              $params[] = '%' . core_text::strtolower($search) . '%';
          }
          $tagsincloud = $DB->get_records_sql(
                  "SELECT tg.id, tg.rawname, tg.name, tg.isstandard, COUNT(ti.id) AS count, tg.flag, tg.tagcollid
                  $fromclause
                  $whereclause
                  GROUP BY tg.id, tg.rawname, tg.name, tg.flag, tg.isstandard, tg.tagcollid
                  ORDER BY count DESC, tg.name ASC",
              $params, 0, $limit);
  
          $tagscount = count($tagsincloud);
          if ($tagscount == $limit) {
              $tagscount = $DB->get_field_sql("SELECT COUNT(DISTINCT tg.id) $fromclause $whereclause", $params);
          }
  
          self::$cloudsortfield = $sort;
          usort($tagsincloud, "self::cloud_sort");
  
          return new core_tag\output\tagcloud($tagsincloud, $tagscount, $fromctx, $ctx, $rec);
      }
code: public static function get_tag_cloud($tagcollid, $isstandard = false, $limit = 150, $sort = 'name',
              $search = '', $fromctx = 0, $ctx = 0, $rec = 1) {
          global $DB;
  
          $fromclause = 'FROM {tag_instance} ti JOIN {tag} tg ON tg.id = ti.tagid';
          $whereclause = 'WHERE ti.itemtype <> \'tag\'';
          list($sql, $params) = $DB->get_in_or_equal($tagcollid ? array($tagcollid) :
              array_keys(self::get_collections(true)));
          $whereclause .= ' AND tg.tagcollid ' . $sql;
          if ($isstandard) {
              $whereclause .= ' AND tg.isstandard = 1';
          }
          $context = $ctx ? context::instance_by_id($ctx) : context_system::instance();
          if ($rec && $context->contextlevel != CONTEXT_SYSTEM) {
              $fromclause .= ' JOIN {context} ctx ON ctx.id = ti.contextid ';
              $whereclause .= ' AND ctx.path LIKE ?';
              $params[] = $context->path . '%';
          } else if (!$rec) {
              $whereclause .= ' AND ti.contextid = ?';
              $params[] = $context->id;
          }
          if (strval($search) !== '') {
              $whereclause .= ' AND tg.name LIKE ?';
              $params[] = '%' . core_text::strtolower($search) . '%';
          }
          $tagsincloud = $DB->get_records_sql(
                  "SELECT tg.id, tg.rawname, tg.name, tg.isstandard, COUNT(ti.id) AS count, tg.flag, tg.tagcollid
                  $fromclause
                  $whereclause
                  GROUP BY tg.id, tg.rawname, tg.name, tg.flag, tg.isstandard, tg.tagcollid
                  ORDER BY count DESC, tg.name ASC",
              $params, 0, $limit);
  
          $tagscount = count($tagsincloud);
          if ($tagscount == $limit) {
              $tagscount = $DB->get_field_sql("SELECT COUNT(DISTINCT tg.id) $fromclause $whereclause", $params);
          }
  
          self::$cloudsortfield = $sort;
          usort($tagsincloud, "self::cloud_sort");
  
          return new core_tag\output\tagcloud($tagsincloud, $tagscount, $fromctx, $ctx, $rec);
      }
code_tokens: public static function get_tag_cloud ( $ tagcollid , $ isstandard = false , $ limit = 150 , $ sort = 'name' , $ search = '' , $ fromctx = 0 , $ ctx = 0 , $ rec = 1 ) { global $ DB ; $ fromclause = 'FROM {tag_instance} ti JOIN {tag} tg ON tg.id = ti.tagid' ; $ whereclause = 'WHERE ti.itemtype <> \'tag\'' ; list ( $ sql , $ params ) = $ DB -> get_in_or_equal ( $ tagcollid ? array ( $ tagcollid ) : array_keys ( self :: get_collections ( true ) ) ) ; $ whereclause .= ' AND tg.tagcollid ' . $ sql ; if ( $ isstandard ) { $ whereclause .= ' AND tg.isstandard = 1' ; } $ context = $ ctx ? context :: instance_by_id ( $ ctx ) : context_system :: instance ( ) ; if ( $ rec && $ context -> contextlevel != CONTEXT_SYSTEM ) { $ fromclause .= ' JOIN {context} ctx ON ctx.id = ti.contextid ' ; $ whereclause .= ' AND ctx.path LIKE ?' ; $ params [ ] = $ context -> path . '%' ; } else if ( ! $ rec ) { $ whereclause .= ' AND ti.contextid = ?' ; $ params [ ] = $ context -> id ; } if ( strval ( $ search ) !== '' ) { $ whereclause .= ' AND tg.name LIKE ?' ; $ params [ ] = '%' . core_text :: strtolower ( $ search ) . '%' ; } $ tagsincloud = $ DB -> get_records_sql ( "SELECT tg.id, tg.rawname, tg.name, tg.isstandard, COUNT(ti.id) AS count, tg.flag, tg.tagcollid
                  $fromclause
                  $whereclause
                  GROUP BY tg.id, tg.rawname, tg.name, tg.flag, tg.isstandard, tg.tagcollid
                  ORDER BY count DESC, tg.name ASC" , $ params , 0 , $ limit ) ; $ tagscount = count ( $ tagsincloud ) ; if ( $ tagscount == $ limit ) { $ tagscount = $ DB -> get_field_sql ( "SELECT COUNT(DISTINCT tg.id) $fromclause $whereclause" , $ params ) ; } self :: $ cloudsortfield = $ sort ; usort ( $ tagsincloud , "self::cloud_sort" ) ; return new core_tag \ output \ tagcloud ( $ tagsincloud , $ tagscount , $ fromctx , $ ctx , $ rec ) ; }
docstring: Returns the list of tags with number of items tagged
  
  @param int $tagcollid
  @param null|bool $isstandard return only standard tags
  @param int $limit maximum number of tags to retrieve, tags are sorted by the instance count
  descending here regardless of $sort parameter
  @param string $sort sort order for display, default 'name' - tags will be sorted after they are retrieved
  @param string $search search string
  @param int $fromctx context id where this tag cloud is displayed
  @param int $ctx only retrieve tag instances in this context
  @param int $rec retrieve tag instances in the $ctx context and it's children (default 1)
  @return \core_tag\output\tagcloud
docstring_tokens: Returns the list of tags with number of items tagged