class EPapersController < ApplicationController def index topics = EPaperTopic.filter_by_categories.desc(:period) data = topics.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" => topic.category.title, "category_title" => topic.category.title, "publish_date" => topic.period } end { "topics" => data, "extras" => { }, "total_pages" => topics.total_pages } 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.each do |category, topics| topics_data = topics.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 { "categories" => data, "extras" => {} } end def criteria_list params = OrbitHelper.params criterias = PaperCriteria.all.desc(:start_date).limit(OrbitHelper.widget_data_count) data = criterias.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.desc(:period) data = topics.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, "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.each do |category, topics| topics_data = topics.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 } end data << { "category_title" => category.title, "topics" => topics_data } 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.each do |category, topics| topics_data = topics.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 } end data << { "category_title" => category.title, "topics" => topics_data } 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!!!"} end render :json => data.to_json end end