module MaterialsHelper
  def get_pretty_file_size(size_in_bytes)
    suffixes = ["B", "KB", "MB", "GB"]
    size = size_in_bytes
    size_current_units = size_in_bytes
    unit = 0
    while size_current_units > 1024 and unit < suffixes.length do
      size_current_units = size_current_units / 1024.0
      unit += 1
    end
    size_rounded = sprintf "%.2f", size_current_units
    size_rounded + " " + suffixes[unit]
  end

  def get_materials_display_name
    preferable = @course.student_sidebar_display.joins(:preferable_item).
      where(preferable_items: {name: 'materials'}).first
    preferable.prefer_value
  end
end

module MaterialsHelper
  def get_pretty_file_size(size_in_bytes)
    suffixes = ["B", "KB", "MB", "GB"]
    size = size_in_bytes
    size_current_units = size_in_bytes
    unit = 0
    while size_current_units > 1024 and unit < suffixes.length do
      size_current_units = size_current_units / 1024.0
      unit += 1
    end
    size_rounded = sprintf "%.2f", size_current_units
    size_rounded + " " + suffixes[unit]
  end

  def get_materials_display_name
    preferable = @course.student_sidebar_items.joins(:preferable_item).
      where(preferable_items: {name: 'materials'}).first
    preferable.prefer_value
  end
end

Allow access to the customised materials component name even if it is disabled by the lecturer (e.g. by direct URL access)
Allow access to the customised materials component name even if it is disabled by the lecturer (e.g. by direct URL access)
