]> git.openstreetmap.org Git - rails.git/blob - app/helpers/user_blocks_helper.rb
put osmosis installation back
[rails.git] / app / helpers / user_blocks_helper.rb
1 module UserBlocksHelper
2   include ActionView::Helpers::TranslationHelper
3
4   ##
5   # returns a translated string representing the status of the
6   # user block (i.e: whether it's active, what the expiry time is)
7   def block_status(block)
8     if block.active?
9       # if the block hasn't expired yet show the date, if the user just needs to login show that
10       if block.needs_view?
11         if block.ends_at > Time.now.getutc
12           t("user_blocks.helper.time_future_and_until_login_html", :time => friendly_date(block.ends_at))
13         else
14           t("user_blocks.helper.until_login")
15         end
16       else
17         t("user_blocks.helper.time_future_html", :time => friendly_date(block.ends_at))
18       end
19     else
20       # the max of the last update time or the ends_at time is when this block finished
21       # either because the user viewed the block (updated_at) or it expired or was
22       # revoked (ends_at)
23       last_time = [block.ends_at, block.updated_at].max
24       t("user_blocks.helper.time_past_html", :time => friendly_date_ago(last_time))
25     end
26   end
27
28   def block_duration_in_words(duration)
29     parts = ActiveSupport::Duration.build(duration).parts
30     if duration < 1.day
31       t("user_blocks.helper.block_duration.hours", :count => parts[:hours])
32     elsif duration < 1.week
33       t("user_blocks.helper.block_duration.days", :count => parts[:days])
34     elsif duration < 1.month
35       t("user_blocks.helper.block_duration.weeks", :count => parts[:weeks])
36     elsif duration < 1.year
37       t("user_blocks.helper.block_duration.months", :count => parts[:months])
38     else
39       t("user_blocks.helper.block_duration.years", :count => parts[:years])
40     end
41   end
42 end