|
- class OrgCoursesController < ApplicationController
- def create
- org_ids = params[:orgNames]
- @course = Course.find(params[:course_id])
- org_ids.each do |org_id|
- if OrgCourse.where("organization_id =? and course_id =?", org_id.to_i, params[:course_id].to_i).count == 0
- OrgCourse.create(:organization_id => org_id.to_i, :course_id => params[:course_id].to_i, :created_at => Time.now)
- end
- end
- respond_to do |format|
- format.js
- end
- end
-
- def destroy
- @course = Course.find(params[:course_id])
- @org_course = OrgCourse.find(params[:id])
- @org_course.destroy
- course_org_ids = OrgCourse.find_by_sql("select distinct organization_id from org_courses where course_id = #{@course.id}").map(&:organization_id)
- if course_org_ids.empty?
- @orgs_not_in_course = User.current.organizations
- else
- course_org_ids = "(" + course_org_ids.join(',') + ")"
- @orgs_not_in_course = User.current.organizations.where("organizations.id not in #{course_org_ids}")
- end
- respond_to do |format|
- format.js
- end
- end
- end
|