class EPapersController < ApplicationController def index topics = EPaperTopic.filter_by_categories.filter_by_tags.desc(:period) data = topics.collect do |topic| { "title" => topic.title, "criteria_title" => topic.criteria_title, "link_to_show" => OrbitHelper.url_to_show(topic.to_param), "description" => topic.description, "img_url" => topic.image.url, "img_url_thumb" => topic.image.thumb.url, "category" => (topic.category.title rescue ""), "category_title" => (topic.category.title rescue ""), "publish_date" => topic.period } end { "topics" => data, "extras" => { }, "total_pages" => (topics.count * 1.0 / OrbitHelper.page_data_count).ceil } end def papers params = OrbitHelper.params criterias = PaperCriteria.all.desc(:start_date).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) data = criterias.collect do |criteria| { "title" => criteria.title, "description" => criteria.description, "link_to_show" => OrbitHelper.url_to_show(criteria.to_param) + "?method=topics" } end { "criterias" => data, "extras" => { "th_title" => t('e_paper.title'), "th_description" => t('e_paper.description') }, "total_pages" => criterias.total_pages } end def show params = OrbitHelper.params epaper = EPaperTopic.where(:uid => params[:uid]).first member = MemberProfile.find(epaper.article_authors.first) rescue nil if !member.nil? member_pic = member.get_avatar member_autobiography = member.autobiography member_name = member.name end { "content" => epaper.content, "publish_date" => epaper.period, "description" => epaper.description, "image_url" => epaper.image.url, "image_thumb_url" => epaper.image.thumb.url, "title" => epaper.title, "category_title" => epaper.category.title, "criteria_title" => epaper.criteria_title, "member_pic" => member_pic, "member_autobiography" => member_autobiography, "member_name" => member_name } end def topics params = OrbitHelper.params criteria = PaperCriteria.where(:uid => params[:uid]).first if params["category"].present? papers = criteria.epaper_topics.where(:category_id => params["category"]).group_by(&:category) else papers = criteria.epaper_topics.group_by(&:category) end data = [] papers_sorted = get_all_categories.map do |v| tmp = papers.select{|cat,topics| (cat.id==v.id rescue false)} if tmp.count==0 tmp = nil end tmp end.compact papers_sorted.each do |paper| paper.each do |category, topics| topics_data = Array(topics).compact.collect do |topic| { "title" => topic.title, "link_to_show" => OrbitHelper.url_to_show(topic.to_param), "description" => topic.description, "img_url" => topic.image.url, "img_url_thumb" => topic.image.thumb.url, "category" => category.title } end data << { "category_title" => category.title, "category_link" => params["url"] + "/" + params["page"] + "?method=topics&category=#{category.id.to_s}", "topics" => topics_data } end end { "categories" => data, "extras" => {} } end def widget subpart = OrbitHelper.get_current_widget case subpart.widget_type when /criteria_list.*/ criteria_list when /category_wise_articles.*/ category_wise_articles when /latest_criteria.*/ latest_criteria when /latest_slider.*/ latest_slider else subscribe end end def criteria_list params = OrbitHelper.params criterias = PaperCriteria.all.desc(:start_date).limit(OrbitHelper.widget_data_count) data = Array(criterias).compact.collect do |criteria| { "title" => criteria.title, "description" => criteria.description, "link_to_show" => OrbitHelper.widget_item_url(criteria.to_param) + "?method=topics" } end { "criterias" => data, "extras" => { "th_title" => t('e_paper.title'), "th_description" => t('e_paper.description'), "read_more" => OrbitHelper.widget_more_url + "?method=papers" } } end def category_wise_articles topics = EPaperTopic.filter_by_widget_categories.filter_by_tags(OrbitHelper.widget_tags).desc(:period) data = Array(topics).compact.collect do |topic| { "title" => topic.title, "link_to_show" => OrbitHelper.widget_item_url(topic.to_param), "description" => topic.description, "img_url" => topic.image.url, "img_url_thumb" => topic.image.thumb.url, "category" => (topic.category.title rescue nil), "link_to_show_wise" => OrbitHelper.widget_more_url + "/" + topic.to_param } end { "topics" => data, "extras" => { "more_url" => OrbitHelper.widget_more_url }, } end def latest_criteria criteria = PaperCriteria.last papers = criteria.epaper_topics.group_by(&:category) data = [] papers_sorted = get_all_categories.map do |v| tmp = papers.select{|cat,topics| (cat.id==v.id rescue false)} if tmp.count==0 tmp = nil end tmp end.compact papers_sorted.each do |paper| paper.each do |category, topics| topics_data = Array(topics).compact.collect do |topic| { "title" => topic.title, "link_to_show" => OrbitHelper.widget_item_url(topic.to_param), "description" => topic.description, "img_url" => topic.image.url, "img_url_thumb" => topic.image.thumb.url, "category" => (category.title rescue nil) } end data << { "category_title" => (category.title rescue nil), "topics" => topics_data } end end { "categories" => data, "extras" => { "read_more" => OrbitHelper.widget_more_url + "?method=topics" } } end def latest_slider criteria = PaperCriteria.last papers = criteria.epaper_topics.group_by(&:category) data = [] papers_sorted = get_all_categories.map do |v| tmp = papers.select{|cat,topics| (cat.id==v.id rescue false)} if tmp.count==0 tmp = nil end tmp end.compact papers_sorted.each do |paper| paper.each do |category, topics| topics_data = Array(topics).compact.collect do |topic| { "title" => topic.title, "link_to_show" => OrbitHelper.widget_item_url(topic.to_param), "description" => topic.description, "img_url" => topic.image.url, "img_url_thumb" => topic.image.thumb.url, "category" => (category.title rescue nil) } end data << { "category_title" => (category.title rescue nil), "topics" => topics_data } end end { "categories" => data, "extras" => { "read_more" => OrbitHelper.widget_more_url + "?method=topics" } } end def subscribe {} end def subscribeuser subscriber = EPaperSubscriber.where(:email => params[:email]) if subscriber.count == 0 subscriber = EPaperSubscriber.new subscriber.email = params[:email] subscriber.subscribed = true subscriber.language = params[:language] subscriber.save data = {"success" => true, "msg" => "Successfully Subscribed!!!"} elsif subscriber.first.subscribed data = {"success" => false, "msg" => "Already Subscribed!!!"} elsif !subscriber.first.subscribed su = subscriber.first su.subscribed = true su.save data = {"success" => true, "msg" => "Successfully Subscribed!!!"} end render :json => data.to_json end def unsubscribeuser subscriber = EPaperSubscriber.where(:email => params[:email]).first rescue nil if !subscriber.nil? subscriber.subscribed = false subscriber.save data = {"success" => true, "msg" => "Successfully Unsubscribed!!!"} else data = {"success" => false, "msg" => "You are not a subscriber!!!"} end render :json => data.to_json end def get_all_categories app = ModuleApp.where(key: 'e_paper').first asc_flag = app.asc rescue true app.categories.enabled.sort_by do |category| tmp = category.sort_number.to_i rescue 0 asc_flag ? tmp : -tmp end end end