Created
November 27, 2013 18:32
-
-
Save EminenceHC/7680797 to your computer and use it in GitHub Desktop.
Module problem
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 DrugAssessmentMethods | |
def index | |
@users = User.all | |
@users_array = User.where(loginable_type: 'Student').includes(:loginable).all.map { |u| [u.full_name, u.loginable.id] } | |
if current_user.loginable_type == 'Student' | |
@sid = current_user.loginable.id | |
elsif current_user.loginable_type != 'Student' | |
if | |
params[:student_id].present? | |
@sid = params[:student_id] | |
else | |
@sid = 0 | |
end | |
end | |
@l = DrugAssessment.order('cweek DESC').where(student_id: @sid).search(params[:l]) | |
@da = @l.result | |
@test = Array.new | |
@da.each do |r| | |
unless r.cweek.nil? or r.cweek == 0 | |
@test.push(r.cweek) | |
end | |
end | |
@test = @test.uniq | |
@year = Date.today.cwyear | |
@current_cweek = Date.today.cweek | |
@start_cweek = 34 | |
@emptycount = 0 | |
while @current_cweek > @start_cweek do | |
if @test.include?(@current_cweek) | |
else | |
charles = DrugAssessment.new(cweek: @current_cweek) | |
@da << charles | |
@emptycount = @emptycount + 1 | |
end | |
@current_cweek = @current_cweek - 1 | |
end | |
@da = @da.sort_by{|a| -(a.cweek)} | |
end | |
end |
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
class HomeController < ApplicationController | |
before_filter :authenticate_user! | |
include DrugAssessmentMethods, SurveysToBeTaken | |
end |
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 SurveysToBeTaken | |
def index | |
@today = Date.today.strftime("%m/%d/%Y") | |
@map_survey_ids = Survey.pluck(:id) | |
@map_result_ids = ResultSet.where(user_id: current_user.id).pluck(:survey_id) | |
@compare = @map_survey_ids - @map_result_ids | |
runquery = Survey | |
if is_student | |
runquery = runquery.where(privilege: [1, 3]) | |
elsif is_counselor && is_admin == false | |
runquery = runquery.where(privilege:[2, 3]) | |
elsif is_counselor && is_admin | |
runquery = runquery.where(privilege:[1, 2, 3]) | |
end | |
runquery = runquery.select('surveys.*') | |
@surveys = runquery | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment