hps_learning/app/controllers/hps_learnings_controller.rb

51 lines
2.0 KiB
Ruby
Raw Normal View History

2017-07-04 16:58:50 +00:00
class HpsLearningsController < ApplicationController
def index
table_fields = ["hps_learning.course_pic", "hps_learning.title", :category, "hps_learning.runtime", "hps_learning.lectures"].collect{|x| {"head" => t(x.to_sym)}}
classes = []
HpsClass.all.desc(:created_at).each do |hpsclass|
if hpsclass.hps_lectures.count > 0
classes << {
"course_pic_thumb" => (hpsclass.course_pic.thumb.url rescue "http://www.placehold.it/150x150/EFEFEF/AAAAAA"),
"course_pic" => (hpsclass.course_pic.url rescue ""),
"title" => hpsclass.title,
"category" => hpsclass.category.title,
"runtime" => hpsclass.get_runtime,
"link_to_lectures" => OrbitHelper.url_to_show(hpsclass.to_param)
}
end
end
{
"fields" => table_fields,
"classes" => classes,
"extra" => {}
}
end
def show
params = OrbitHelper.params
request = OrbitHelper.request
hpsclass = HpsClass.where(:uid => params[:uid]).first
table_fields = ["hps_learning.lecture_pic", "hps_learning.subject", "hps_learning.presenter" , "hps_learning.runtime", "hps_learning.link_to_lecture"].collect{|x| {"head" => t(x.to_sym)}}
lectures = []
hpsclass.hps_lectures.each do |lecture|
if !lecture.hps_lecture_file.nil? && !lecture.hps_lecture_file.index_path.nil?
lectures << {
"lecture_pic_thumb" => (lecture.lecture_pic.thumb.url rescue "http://www.placehold.it/150x150/EFEFEF/AAAAAA"),
"lecture_pic" => (lecture.lecture_pic.url rescue ""),
"subject" => lecture.subject,
"presenter" => lecture.presenter,
"runtime" => lecture.get_runtime,
"link_to_lecture" => "http://#{request.host_with_port}/#{lecture.hps_lecture_file.index_path}"
}
end
end
{
"lectures" => lectures,
"fields" => table_fields,
"data" => {
"class-title" => hpsclass.title,
"view-lecture" => t("hps_learning.view_lecture")
}
}
end
end