2019-05-28 15:54:32 +00:00
|
|
|
class EPapersController < ApplicationController
|
2022-12-07 03:10:10 +00:00
|
|
|
FrontendMethods = ["papers", "topics"]
|
2022-12-08 15:42:02 +00:00
|
|
|
EmptyImg = "data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA="
|
|
|
|
EmptyImgUrl = "#{EmptyImg}\" style=\"display: none;"
|
|
|
|
def self.custom_widget_data
|
|
|
|
ac = ActionController::Base.new
|
2023-07-05 01:15:08 +00:00
|
|
|
ac.instance_variable_set(:@custom_data_field, @custom_data_field)
|
|
|
|
ac.instance_variable_set(:@field_name, @field_name)
|
|
|
|
ac.render_to_string("e_papers/custom_widget_data")
|
2022-12-08 15:42:02 +00:00
|
|
|
end
|
2019-05-28 15:54:32 +00:00
|
|
|
def index
|
2022-12-08 15:42:02 +00:00
|
|
|
page_no = OrbitHelper.page_number
|
|
|
|
data_count = OrbitHelper.page_data_count
|
|
|
|
page = (OrbitHelper.page rescue Page.where(:url=>params[:url]).first)
|
|
|
|
page_layout = page.layout
|
|
|
|
custom_data_field = page.custom_data_field
|
|
|
|
if custom_data_field
|
|
|
|
criteria_id = (custom_data_field["criteria_id"] || "all" rescue "all")
|
|
|
|
epaper_topics = nil
|
|
|
|
if criteria_id == "all"
|
|
|
|
epaper_topics = EPaperTopic.all
|
|
|
|
else
|
|
|
|
criteria = PaperCriteria.where(:id => criteria_id).first
|
|
|
|
epaper_topics = criteria.epaper_topics
|
|
|
|
end
|
|
|
|
else
|
|
|
|
epaper_topics = EPaperTopic.all
|
|
|
|
criteria = nil
|
|
|
|
end
|
|
|
|
topics = epaper_topics.filter_by_categories.filter_by_tags.desc(:period).page(page_no).per(data_count)
|
|
|
|
total_pages = topics.total_pages
|
|
|
|
page_url = page.get_url rescue page.url
|
|
|
|
if page_layout.include?("_latest")
|
|
|
|
topics_group = topics.group_by(&:category)
|
|
|
|
data = topics_group.collect do |category, topics|
|
|
|
|
category_title = (category ? category.title : "")
|
|
|
|
topics_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 || EmptyImgUrl,
|
|
|
|
"img_url_thumb" => topic.image.thumb.url || EmptyImgUrl,
|
|
|
|
"category" => category_title,
|
|
|
|
"category_title" => category_title,
|
|
|
|
"publish_date" => topic.period
|
|
|
|
}
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"category_title" => category_title,
|
|
|
|
"category_link" => "#{page_url}?method=topics&category=#{category.id.to_s}",
|
|
|
|
"topics" => topics_data
|
|
|
|
}
|
|
|
|
end
|
2019-05-28 15:54:32 +00:00
|
|
|
{
|
2022-12-08 15:42:02 +00:00
|
|
|
"categories" => data,
|
|
|
|
"extras" => {
|
|
|
|
|
|
|
|
},
|
|
|
|
"total_pages" => total_pages
|
2019-05-28 15:54:32 +00:00
|
|
|
}
|
2022-12-08 15:42:02 +00:00
|
|
|
else
|
|
|
|
data = topics.to_a.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 || EmptyImgUrl,
|
|
|
|
"img_url_thumb" => topic.image.thumb.url || EmptyImgUrl,
|
|
|
|
"category" => (topic.category.title rescue ""),
|
|
|
|
"category_title" => (topic.category.title rescue ""),
|
|
|
|
"publish_date" => topic.period
|
|
|
|
}
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"topics" => data,
|
|
|
|
"extras" => {
|
2019-05-28 15:54:32 +00:00
|
|
|
|
2022-12-08 15:42:02 +00:00
|
|
|
},
|
|
|
|
"total_pages" => total_pages
|
|
|
|
}
|
|
|
|
end
|
2019-05-28 15:54:32 +00:00
|
|
|
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,
|
2022-12-08 15:42:02 +00:00
|
|
|
"image_url" => epaper.image.url || EmptyImgUrl,
|
|
|
|
"image_thumb_url" => epaper.image.thumb.url || EmptyImgUrl,
|
2019-05-28 15:54:32 +00:00
|
|
|
"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
|
2022-12-08 15:42:02 +00:00
|
|
|
if params[:uid].present?
|
|
|
|
criteria = PaperCriteria.where(:uid => params[:uid]).first
|
|
|
|
return if criteria.nil?
|
|
|
|
epaper_topics = criteria.epaper_topics
|
|
|
|
else
|
|
|
|
epaper_topics = EPaperTopic.all
|
|
|
|
end
|
2019-05-28 15:54:32 +00:00
|
|
|
if params["category"].present?
|
2022-12-08 15:42:02 +00:00
|
|
|
papers = epaper_topics.where(:category_id => params["category"]).group_by(&:category)
|
2019-05-28 15:54:32 +00:00
|
|
|
else
|
2022-12-08 15:42:02 +00:00
|
|
|
papers = epaper_topics.group_by(&:category)
|
2019-05-28 15:54:32 +00:00
|
|
|
end
|
|
|
|
data = []
|
2020-04-25 03:29:52 +00:00
|
|
|
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,
|
2022-12-08 15:42:02 +00:00
|
|
|
"img_url" => topic.image.url || EmptyImgUrl,
|
|
|
|
"img_url_thumb" => topic.image.thumb.url || EmptyImgUrl,
|
2020-04-25 03:29:52 +00:00
|
|
|
"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
|
2019-05-28 15:54:32 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"categories" => data,
|
|
|
|
"extras" => {}
|
|
|
|
}
|
|
|
|
end
|
2020-03-08 12:32:05 +00:00
|
|
|
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
|
2019-05-28 15:54:32 +00:00
|
|
|
def criteria_list
|
|
|
|
params = OrbitHelper.params
|
|
|
|
criterias = PaperCriteria.all.desc(:start_date).limit(OrbitHelper.widget_data_count)
|
2020-03-24 15:01:49 +00:00
|
|
|
data = Array(criterias).compact.collect do |criteria|
|
2019-05-28 15:54:32 +00:00
|
|
|
{
|
|
|
|
"title" => criteria.title,
|
|
|
|
"description" => criteria.description,
|
2019-05-31 10:06:55 +00:00
|
|
|
"link_to_show" => OrbitHelper.widget_item_url(criteria.to_param) + "?method=topics"
|
2019-05-28 15:54:32 +00:00
|
|
|
}
|
|
|
|
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
|
2020-06-11 10:57:15 +00:00
|
|
|
topics = EPaperTopic.filter_by_widget_categories.filter_by_tags(OrbitHelper.widget_tags).desc(:period)
|
2020-03-24 15:01:49 +00:00
|
|
|
data = Array(topics).compact.collect do |topic|
|
2019-05-28 15:54:32 +00:00
|
|
|
{
|
|
|
|
"title" => topic.title,
|
2019-05-31 10:06:55 +00:00
|
|
|
"link_to_show" => OrbitHelper.widget_item_url(topic.to_param),
|
2019-05-28 15:54:32 +00:00
|
|
|
"description" => topic.description,
|
2022-12-08 15:42:02 +00:00
|
|
|
"img_url" => topic.image.url || EmptyImgUrl,
|
|
|
|
"img_url_thumb" => topic.image.thumb.url || EmptyImgUrl,
|
2020-03-24 15:01:49 +00:00
|
|
|
"category" => (topic.category.title rescue nil),
|
2019-05-31 10:06:55 +00:00
|
|
|
"link_to_show_wise" => OrbitHelper.widget_more_url + "/" + topic.to_param
|
2019-05-28 15:54:32 +00:00
|
|
|
}
|
|
|
|
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 = []
|
2020-04-25 03:29:52 +00:00
|
|
|
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,
|
2022-12-08 15:42:02 +00:00
|
|
|
"img_url" => topic.image.url || EmptyImgUrl,
|
|
|
|
"img_url_thumb" => topic.image.thumb.url || EmptyImgUrl,
|
2020-04-25 03:29:52 +00:00
|
|
|
"category" => (category.title rescue nil)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
data << {
|
|
|
|
"category_title" => (category.title rescue nil),
|
|
|
|
"topics" => topics_data
|
2019-05-28 15:54:32 +00:00
|
|
|
}
|
|
|
|
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 = []
|
2020-04-25 03:29:52 +00:00
|
|
|
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,
|
2022-12-08 15:42:02 +00:00
|
|
|
"img_url" => topic.image.url || EmptyImgUrl,
|
|
|
|
"img_url_thumb" => topic.image.thumb.url || EmptyImgUrl,
|
2020-04-25 03:29:52 +00:00
|
|
|
"category" => (category.title rescue nil)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
data << {
|
|
|
|
"category_title" => (category.title rescue nil),
|
|
|
|
"topics" => topics_data
|
2019-05-28 15:54:32 +00:00
|
|
|
}
|
|
|
|
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!!!"}
|
2022-05-23 14:20:09 +00:00
|
|
|
else
|
|
|
|
data = {"success" => false, "msg" => "You are not a subscriber!!!"}
|
2019-05-28 15:54:32 +00:00
|
|
|
end
|
|
|
|
render :json => data.to_json
|
|
|
|
end
|
2020-04-25 03:29:52 +00:00
|
|
|
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
|
2019-05-28 15:54:32 +00:00
|
|
|
end
|