Class: AdminsController

Inherits:
Admin::AdminController
  • Object
show all
Defined in:
app/controllers/admins_controller.rb

Defined Under Namespace

Classes: UserSearch

Instance Method Summary collapse

Instance Method Details

#add_invitesObject


31
32
33
34
# File 'app/controllers/admins_controller.rb', line 31

def add_invites
  InvitationCode.find_by_token(params[:invite_code_id]).add_invites!
  redirect_to user_search_path
end

#admin_inviterObject


17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/admins_controller.rb', line 17

def admin_inviter
  inviter = InvitationCode.default_inviter_or(current_user)
  email = params[:identifier]
  user = User.find_by_email(email)

  unless user
    EmailInviter.new(email, inviter).send!
    flash[:notice] = "invitation sent to #{email}"
  else
    flash[:notice]= "error sending invite to #{email}"
  end
  redirect_to user_search_path, :notice => flash[:notice]
end

#correlationsObject


80
81
82
# File 'app/controllers/admins_controller.rb', line 80

def correlations
  @correlations_hash = Statistics.new.generate_correlations
end

#statsObject


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/admins_controller.rb', line 48

def stats
  @popular_tags = ActsAsTaggableOn::Tagging.joins(:tag).limit(50).count(:group => :tag, :order => 'count(taggings.id) DESC')

  case params[:range]
  when "week"
    range = 1.week
    @segment = t('admins.stats.week')
  when "2weeks"
    range = 2.weeks
    @segment = t('admins.stats.2weeks')
  when "month"
    range = 1.month
    @segment = t('admins.stats.month')
  else
    range = 1.day
    @segment = t('admins.stats.daily')
  end

  [Post, Comment, AspectMembership, User].each do |model|
    create_hash(model, :range => range)
  end

  @posts_per_day = Post.count(:group => "DATE(created_at)", :conditions => ["created_at >= ?", Date.today - 21.days], :order => "DATE(created_at) ASC")
  @most_posts_within = @posts_per_day.values.max.to_f

  @user_count = User.count

  #@posts[:new_public] = Post.where(:type => ['StatusMessage','ActivityStreams::Photo'],
  #                                 :public => true).order('created_at DESC').limit(15).all

end

#user_searchObject


5
6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/admins_controller.rb', line 5

def user_search
  if params[:admins_controller_user_search]
    search_params = params.require(:admins_controller_user_search)
                          .permit(:username, :email, :guid, :under13)
    @search = UserSearch.new(search_params)
    @users = @search.perform
  end

  @search ||= UserSearch.new
  @users ||= []
end

#weekly_user_statsObject


36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/admins_controller.rb', line 36

def weekly_user_stats
  @created_users_by_week = Hash.new{ |h,k| h[k] = [] }
  @created_users = User.where("username IS NOT NULL and created_at IS NOT NULL")
  @created_users.find_each do |u|
    week = u.created_at.beginning_of_week.strftime("%Y-%m-%d")
    @created_users_by_week[week] << u.username
  end

  @selected_week = params[:week] || @created_users_by_week.keys.first
  @counter = @created_users_by_week[@selected_week].count
end