Edit the tutoring sessions
# File app/controllers/tutoring_sessions_controller.rb, line 14 def edit @tutor = @tutoring_session.tutor @tutoring_session.attachments.build unless @tutoring_session.attachments.exists? render layout: false end
Get all the tutoring session, courses and events between start date and end date related to current user.
# File app/controllers/tutoring_sessions_controller.rb, line 33 def index @start_date = Date.parse(params[:start]) @end_date = Date.parse(params[:end]) if params[:other_user].present? @other_user = User.find_by_id(params[:other_user]) @other_user_tutoring_sessions = @other_user.related_sessions(start_date: @start_date, end_date: @end_date).not_rejected @other_user_schedule_events = @other_user.events.responded_by_user(@other_user).except_rejected_by(@other_user).for_date_range(@start_date, @end_date) end unless params[:view] @tutoring_sessions = current_user.related_sessions(start_date: @start_date, end_date: @end_date).not_rejected @tutoring_sessions = @tutoring_sessions.includes(:invoice, :user).not_offline @schedule_events = current_user.events.responded_by_user(current_user).except_rejected_by(current_user).for_date_range(@start_date, @end_date) else if params[:view] == 'list' associations = [:tutor, :user, :subject, :resource, :invoice, :messages] @tutoring_sessions = current_user.related_sessions.not_offline.includes(*associations) @tutoring_sessions = @tutoring_sessions.page(params[:page]).per(params[:per_page]) end end respond_to do |format| format.html do render partial: "#{params[:view]}_view" if params[:view] end format.json end end
Used to mark session unoccured(i.e. session that is omitted by some reason) only if it is not paid.
# File app/controllers/tutoring_sessions_controller.rb, line 116 def mark_unoccured respond_to do |format| unless @tutoring_session.paid? if @tutoring_session.update_attributes(mark_unoccured_params) format.js {} else format.js {render partial: 'session_omitted_reason', within: "#session-omitted-reason"} end else redirect_to dashboard_path, notice: 'This session has already been paid.' end end end
Add review for tutoring session.(i.e. rate the session)
# File app/controllers/tutoring_sessions_controller.rb, line 84 def rate save_review respond_to do |format| format.js { redirect_via_turbolinks_to dashboard_path} format.html {redirect_to dashboard_path } end end
Find or create invoice for tutoring sessions and if not paid it proceed for payment.
# File app/controllers/tutoring_sessions_controller.rb, line 93 def rate_and_pay @invoice = @tutoring_session.find_or_create_invoice! unless @invoice.paid? confirm_session! if @invoice.pay_tutor save_review respond_to do |format| format.js {} end else if @invoice.manually_billed? or @tutoring_session.video_session? message = "Your amount for this invoice has been transfered to #{Configurations::General.application_name} escrow account. But unable to make payment to the #{Tutor.model_name.human}. Please contact #{Configurations::General.application_name} team." else message = "Unable to make payment to #{Tutor.model_name.human}. Please contact #{Configurations::General.application_name} team." end redirect_to request.referer || root_path, notice: message end else redirect_to dashboard_path, notice: 'This session has already been paid.' end end
Build review for tutoring sessions.
# File app/controllers/tutoring_sessions_controller.rb, line 76 def rating @tutoring_session.build_review unless @tutoring_session.review @tutoring_session.build_session_omitted_reason unless @tutoring_session.session_omitted_reason @tutoring_session.invoice render layout: false end
Show related sessions of the current user.
# File app/controllers/tutoring_sessions_controller.rb, line 8 def show @tutoring_session = current_user.related_sessions.find(params[:id]) render layout: false end
Returns pending and confirmed sessions.
# File app/controllers/tutoring_sessions_controller.rb, line 61 def upcoming sessions = {pending: [], confirmed: []} current_user.related_sessions.upcoming.rejected.includes(:user, :tutor).each do |session| if session.pending? sessions[:pending] << session.for_appointment_sidebar else sessions[:confirmed] << session.for_appointment_sidebar end end respond_to do |format| format.json {render json: sessions} end end
Find and update tutoring session
# File app/controllers/tutoring_sessions_controller.rb, line 21 def update respond_to do |format| if @tutoring_session.update_attributes(tutoring_session_params) @tutoring_session.send_tutoring_session_update_mail format.js {} else format.js {render partial: 'form', locals: {tutoring_session: @tutoring_session}, replace: "form#edit_tutoring_session_#{@tutoring_session.id}"} end end end