Created
May 8, 2014 01:24
-
-
Save arturdent/25074881b393a357bff2 to your computer and use it in GitHub Desktop.
first method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AdminDashboardHelper | |
def users_registered_today | |
"#{users_registered_by_date(Date.today)} (#{social_profiles_created_by_date(Date.today)})" | |
end | |
def users_registered_by_date(date) | |
User.where('created_at > ?', date.beginning_of_day).count | |
end | |
def social_profiles_created_by_date(date) | |
SocialProfile.where('created_at > ? AND user_id IS NOT NULL', date.beginning_of_day).count | |
end | |
def new_users_for_the_last_week | |
new_users_count = 0 | |
7.times do |n| | |
date = (7-n).days.ago | |
new_users_count += users_registered_by_date(date) | |
end | |
"#{new_users_count}" | |
end | |
def users_registered_total | |
"#{User.count} (#{SocialProfile.where('user_id IS NOT NULL').count})" | |
end | |
def count_social_profiles_for(service_name) | |
SocialProfile.where(active: true, service_name: service_name).where('user_id IS NOT NULL').count | |
end | |
def activities_registered_today | |
Activity.where('created_at > ?', Date.today.beginning_of_day).count | |
end | |
def activities_total | |
Activity.count | |
end | |
def job_status(done) | |
done ? 'Finished' : 'In Progress' | |
end | |
def activities_for_service(user, service) | |
user_activities_for_service(user, service).count | |
end | |
def last_activity_created_time(user, service) | |
last_activity = user_activities_for_service(user, service).order('created_at ASC').limit(1).first | |
last_activity.present? ? l(Time.zone.at(last_activity.trackable_created_time)) : 'None' | |
end | |
def user_activities_for_service(user, service) | |
Activity.visible_by_user(user).by_service(service) | |
end | |
def user_selector_title(user) | |
title = user.authentication_token.present? ? user.authentication_token : 'unknown' | |
title += " | #{user.name}" if user.name.present? | |
title += " | #{user.email}" if user.email.present? | |
title | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment