diff --git a/app/helpers/recordings_helper.rb b/app/helpers/recordings_helper.rb index 06296457..2cc2dc82 100644 --- a/app/helpers/recordings_helper.rb +++ b/app/helpers/recordings_helper.rb @@ -24,18 +24,13 @@ module RecordingsHelper # Helper for converting BigBlueButton dates into a nice length string. def recording_length(playbacks) - # Stats format currently doesn't support length. - valid_playbacks = playbacks.reject { |p| p[:type] == "statistics" } - return "0 min" if valid_playbacks.empty? - - len = valid_playbacks.first[:length] - if len > 60 - "#{(len / 60).to_i} h #{len % 60} min" - elsif len.zero? - "< 1 min" - else - "#{len} min" + # Looping through playbacks array and returning first non-zero length value + playbacks.each do |playback| + length = playback[:length] + return recording_length_string(length) unless length.zero? end + # Return '< 1 min' if length values are zero + "< 1 min" end # Prevents single images from erroring when not passed as an array. @@ -51,4 +46,15 @@ module RecordingsHelper def recording_thumbnails? Rails.configuration.recording_thumbnails end + + private + + # Returns length of the recording as a string + def recording_length_string(len) + if len > 60 + "#{(len / 60).to_i} h #{len % 60} min" + else + "#{len} min" + end + end end