class RecruitmentsController < PseudoSessionController
include ActionView::Helpers::TextHelper
before_filter :set_key_for_this, :except => ["index", "show"]
before_filter :load_profile, :except => ["newprofile", "createprofile", "index", "show", "advancedform"]
before_filter :is_user_authorized?, :except => ["index", "show", "advancedform"]
layout :get_layout
def index
params = OrbitHelper.params
if params[:page_id] == "jobs"
load_jobs(params)
elsif params[:page_id] == "candidates"
load_candidates(params)
end
end
def load_candidates(params)
data = []
if params[:type].present? && params[:type] == "aq"
candidates = advanced_filter_candidates(params)
criteria = "- "
elsif params[:q].present?
candidates = filter_candidates(params)
criteria = "- " + params[:q] + " "
else
criteria = ""
candidates = EmployeeProfile.job_seekers
end
if !candidates.nil? && !candidates.is_a?(Array)
candidates = candidates.desc(:updated_at).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count)
total_pages = candidates.total_pages
else
candidates = []
total_pages = 0
end
candidates.each do |candidate|
company = !candidate.current_company.nil? && candidate.current_company != "" ? candidate.current_company : candidate.get_current_exp
company = "N/A" if company.nil?
if candidate.experience_years == 0 && candidate.experience_months == 0
wey = t("recruitment.fresher")
wem = ""
else
wey = (candidate.experience_years.to_s rescue "0") + " year(s)"
wem = (candidate.experience_months.to_s rescue "0") + " month(s)"
end
data << {
"name" => candidate.recruit_profile.name,
"designation" => candidate.desired_job_title,
"company_name" => company,
"location" => candidate.desired_place,
"url_to_show" => OrbitHelper.url_to_show(candidate.recruit_profile.to_param),
"work_experience_years" => wey,
"work_experience_months" => wem,
"introduction" => candidate.introduction,
"skills" => candidate.skills.collect{|skill| {"skill-tag" => skill}},
"avatar" => candidate.get_avatar
}
end
{
"candidates" => data,
"extras" => {
"criteria" => criteria
},
"total_pages" => total_pages
}
end
def load_jobs(params)
jobs = []
if params[:type].present? && params[:type] == "aq"
rjobs = advanced_filter_jobs(params)
criteria = "- "
elsif params[:q].present?
rjobs = filter_jobs(params)
criteria = "- " + params[:q] + " "
else
criteria = ""
rjobs = RecruitmentJob.not_filled
end
if !rjobs.nil? && !rjobs.is_a?(Array)
rjobs = rjobs.desc(:created_at).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count)
total_pages = rjobs.total_pages
else
rjobs = []
total_pages = 0
end
rjobs.each do |rj|
if rj.work_experience_years == 0 && rj.work_experience_months == 0
wey = t("recruitment.fresher")
wem = ""
else
wey = (rj.work_experience_years.to_s rescue "0") + " year(s)"
wem = (rj.work_experience_months.to_s rescue "0") + " month(s)"
end
jobs << {
"company_name" => rj.employer_profile.company_name,
"industry" => rj.employer_profile.get_industry,
"avatar" => rj.employer_profile.get_avatar,
"title" => rj.job_title,
"url_to_show" => OrbitHelper.url_to_show(rj.to_param),
"description" => simple_format(truncate(rj.job_description, :length => 50)),
"postdate" => rj.created_at,
"work_type" => rj.work_type,
"location" => rj.location_of_work,
"work_experience_years" => wey,
"work_experience_months" => wem,
"category" => rj.category,
"skills" => rj.skills.collect{|skill| {"skill-tag" => skill}}
}
end
{
"jobs" => jobs,
"extras" => {
"criteria" => criteria
},
"total_pages" => total_pages
}
end
def show
params = OrbitHelper.params
if params[:page_id] == "jobs"
show_job(params)
elsif params[:page_id] == "candidates"
show_candidate(params)
end
end
def get_show_type
{
"type" => OrbitHelper.params[:page_id]
}
end
def show_candidate(params)
{
"data" => {}
}
end
def show_job(params)
job = RecruitmentJob.where(:uid => params[:uid]).first
profile = job.employer_profile
infos = []
if !profile.company_profile.nil? && profile.company_profile != ""
infos << {
"title" => t("recruitment.company_profile"),
"text" => simple_format(profile.company_profile)
}
end
["job_description", "responsibility", "other_conditions"].each do |jj|
if !job.send(jj).nil? && job.send(jj) != ""
infos << {
"title" => t("recruitment.#{jj}"),
"text" => simple_format(job.send(jj))
}
end
end
if !job.skills.empty?
skills = job.skills.collect{|skill| "#{skill}"}
else
skills = t("recruitment.not_available")
end
if job.work_experience_years == 0 && job.work_experience_months == 0
experience = t("recruitment.fresher")
else
experience = (job.work_experience_years.to_s rescue "0") + " year(s) " + (job.work_experience_months.to_s rescue "0") + " month(s)"
end
if !job.holiday_system.nil? || job.holiday_system != ""
if job.holiday_system == "type2" && !job.holiday_system_other.nil? && job.holiday_system_other != ""
holiday = job.holiday_system_other
else
holiday = t("recruitment.holiday_system.#{job.holiday_system}")
end
else
holiday = t("recruitment.not_available")
end
{
"infos" => infos,
"data" => {
"job-title" => job.job_title,
"job-category" => job.get_category,
"avatar" => profile.get_avatar,
"company-name" => profile.company_name,
"industry" => profile.get_industry,
"post-date" => job.created_at,
"location-title" => t("recruitment.location"),
"location" => (!job.location_of_work.nil? && job.location_of_work != "" ? job.location_of_work : t("recruitment.not_available")),
"skills-title" => t("recruitment.skills_title"),
"skills" => skills.join(" "),
"experience-title" => t("recruitment.experience_title"),
"experience" => experience,
"qualification-title" => t("recruitment.qualification"),
"qualification" => (!job.academic_requirement.nil? && job.academic_requirement != "" ? simple_format(job.academic_requirement) : t("recruitment.not_available")),
"salary-title" => t("recruitment.salary-title"),
"salary" => (!job.salary.nil? && job.salary != "" ? t("recruitment.salary.#{job.salary}") : t("recruitment.not_available")),
"travel-title" => t("recruitment.travel"),
"travel" => (!job.travel_assignment.nil? && job.travel_assignment != "" ? t("recruitment.travel_assignment.#{job.travel_assignment}") : t("recruitment.not_available")),
"joining-title" => t("recruitment.joining"),
"joining" => (!job.joining_time.nil? && job.joining_time != "" ? t("recruitment.joining_time.#{job.joining_time}") : t("recruitment.not_available")),
"worktype-title" => t("recruitment.worktype_title"),
"worktype" => (!job.work_type.nil? && job.work_type != "" ? t("recruitment.work_type.#{job.work_type}") : t("recruitment.not_available")),
"language-title" => t("recruitment.language"),
"language" => (!job.language_requirement.nil? && job.language_requirement != "" ? job.language_requirement : t("recruitment.not_available")),
"workingtime-title" => t("recruitment.workingtime_title"),
"workingtime" => (!job.working_time.nil? && job.working_time != "" ? t("recruitment.working_time.#{job.working_time}") : t("recruitment.not_available")),
"holiday-title" => t("recruitment.holiday_title"),
"holiday" => holiday,
}
}
end
def firstruncheck
if @profile.nil?
redirect_to select_profile_path
else
redirect_to mydashboard_path
end
end
def advancedform
@industries = RecruitmentIndustry.all.asc(:industry_title).collect{|ri| [ri.industry_title, ri.id]}
@categories = RecruitmentCategory.all.asc(:job_category).collect{|ri| [ri.job_category, ri.id]}
@locations = RecruitmentJob.all.asc(:location_of_work).pluck(:location_of_work).uniq
render :layout => false
end
def select_profile
end
def newprofile
@profile = RecruitProfile.new
if params[:type] == "1"
@profile.build_employee_profile
elsif params[:type] == "2"
@profile.build_employer_profile
end
end
def createprofile
profile = RecruitProfile.create(profile_params)
if profile.is_employer?
redirect_to mydashboard_path
elsif profile.is_employee?
if params[:commit] == "Next" && params[:step] == "step1"
redirect_to employee_academics_path
elsif params[:commit] == "Save"
redirect_to mydashboard_path
end
end
end
def employee_academics
@academic = EmployeeAcademic.new
@academics = @profile.profile.employee_academics
@academic_types = ["type1","type2","type3","type4"].collect{|t| [t("recruitment.academic_type.#{t}"), t]}
end
def edit_employee_academic
@academic = EmployeeAcademic.find(params[:id])
@academic_types = ["type1","type2","type3","type4"].collect{|t| [t("recruitment.academic_type.#{t}"), t]}
end
def update_academic
academic = EmployeeAcademic.find(params[:id])
academic.update_attributes(employee_academic_params)
redirect_to employee_academics_path
end
def create_academic
if params[:commit] == "Add"
academic = EmployeeAcademic.create(employee_academic_params)
redirect_to employee_academics_path
elsif params[:commit] = "Next"
if params[:employee_academic][:degree_name].present?
academic = EmployeeAcademic.create(employee_academic_params)
end
redirect_to employee_portfolio_path
end
end
def employee_portfolio
end
def recruitment_dashboard
if @profile.is_employer?
@jobsposted = @profile.profile.recruitment_jobs.desc(:created_at)
@page = "/#{I18n.locale.to_s}" + Page.where(:module => "recruitment").first.url rescue "#"
elsif @profile.is_employee?
@applications = @profile.profile.employee_job_applications.desc(:created_at)
@page = "/#{I18n.locale.to_s}" + Page.where(:module => "recruitment").first.url rescue "#"
end
end
def editprofile
end
def updateprofile
@profile.update_attributes(profile_params)
if @profile.is_employer?
redirect_to mydashboard_path
elsif @profile.is_employee?
if params[:commit] == "Next"
if params[:step] == "step3"
redirect_to employee_experience_path
elsif params[:step] == "step1"
redirect_to employee_academics_path
end
elsif params[:commit] == "Save"
redirect_to mydashboard_path
end
end
end
def employee_experience
@exeperiences = @profile.employee_profile.employee_experiences.desc(:created_at)
@experience = EmployeeExperience.new
end
def create_experience
if params[:commit] == "Add"
academic = EmployeeExperience.create(employee_exp_params)
redirect_to employee_experience_path
elsif params[:commit] = "Finish"
if params[:employee_experience][:job_title].present? || params[:employee_experience][:company_name].present?
academic = EmployeeExperience.create(employee_exp_params)
end
redirect_to mydashboard_path
end
end
def edit_employee_experience
@experience = EmployeeExperience.find(params[:id])
end
def update_exmployee_experience
experience = EmployeeExperience.find(params[:id])
experience.update_attributes(employee_exp_params)
redirect_to employee_experience_path
end
def addjob
@job = RecruitmentJob.new
end
def editjob
@job = RecruitmentJob.find(params[:id])
end
def createjob
job = RecruitmentJob.create(recruitment_job_params)
redirect_to mydashboard_path
end
def updatejob
job = RecruitmentJob.find(params[:id])
job.update_attributes(recruitment_job_params)
redirect_to mydashboard_path
end
def markfilled
job = RecruitmentJob.find(params[:id])
if job.employer_profile_id.to_s == @profile.profile.id.to_s
job.filled = true
job.save
end
redirect_to mydashboard_path
end
def unmarkfilled
job = RecruitmentJob.find(params[:id])
if job.employer_profile_id.to_s == @profile.profile.id.to_s
job.filled = false
job.save
end
redirect_to mydashboard_path
end
def deletejob
job = RecruitmentJob.find(params[:id])
job.destroy
redirect_to mydashboard_path
end
private
def filter_jobs(params)
rjobs = []
keywords = params[:q].split(",").collect{|s| /#{s.strip}/i}
companies = EmployerProfile.where(:company_name.in => keywords).pluck(:id)
skills = RecruitmentJob.where(:skills.in => keywords)
designations = RecruitmentJob.where(:job_title.in => keywords)
query = []
if companies.count > 0
query << {:employer_profile_id.in => companies}
end
if skills.count > 0
query << {:skills.in => keywords}
end
if designations.count > 0
query << {:job_title.in => keywords}
end
if !query.empty?
rjobs = RecruitmentJob.any_of(query).not_filled
end
rjobs
end
def advanced_filter_jobs(params)
if params[:q].present?
rjobs = filter_jobs(params)
else
rjobs = []
end
query = []
if params[:exp].present?
if params[:exp].to_i > 0
query << {:work_experience_years.gte => params[:exp].to_i}
else
query << {:work_experience_years => params[:exp]}
end
end
if params[:industry].present?
companies = EmployerProfile.where(:industry => params[:industry]).pluck(:id)
if companies.count > 0
query << {:employer_profile_id.in => companies}
end
end
if params[:category].present?
query << {:category => params[:category]}
end
if params[:location].present?
query << {:location_of_work => /#{params[:location]}/i}
end
if !query.empty?
if !rjobs.empty?
rjobs = rjobs.where(query.reduce({}, :merge))
else
rjobs = RecruitmentJob.where(query.reduce({}, :merge))
end
end
rjobs
end
def filter_candidates
end
def advanced_filter_candidates
end
def get_layout
"recruit"
end
def load_profile
@profile = RecruitProfile.where(:pseudo_member_id => current_pseudo_user.user_name).first rescue nil
end
def profile_params
par = params.require(:recruit_profile).permit!
if par[:employee_profile_attributes][:skills].present?
par[:employee_profile_attributes][:skills] = par[:employee_profile_attributes][:skills].split(",")
par[:employee_profile_attributes][:skills].collect!{|sk| sk.strip}
end
par
end
def employee_academic_params
params.require(:employee_academic).permit!
end
def employee_exp_params
params.require(:employee_experience).permit!
end
def recruitment_job_params
par = params.require(:recruitment_job).permit!
if par[:skills].present?
par[:skills] = par[:skills].split(",")
par[:skills].collect!{|sk| sk.strip}
end
par
end
end