Module: Plugins::VisibilityPost::VisibilityPostHelper

Defined in:
app/apps/plugins/visibility_post/visibility_post_helper.rb

Instance Method Summary collapse

Instance Method Details

#plugin_visibility_can_visit(args) ⇒ Object



30
31
32
33
34
35
36
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 30

def plugin_visibility_can_visit(args)
  post = args[:post]
  return args[:flag] = false if post.published_at.present? && post.published_at > Time.now
  return if post.visibility != 'private'

  args[:flag] = false unless signin? && post.visibility_value.split(',').include?(current_site.visitor_role)
end

#plugin_visibility_create_post(args) ⇒ Object



22
23
24
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 22

def plugin_visibility_create_post(args)
  save_visibility(args[:post])
end

#plugin_visibility_extra_columns(args) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 38

def plugin_visibility_extra_columns(args)
  if args[:from_body]
    args[:content] =
      "<td><i class='fa fa-#{{ 'private' => 'lock', '' => 'lock', 'public' => 'eye',
                               'password' => 'eye-slash' }[args[:post].visibility]}'></i> #{args[:post].visibility}</td>"
    args[:content] =
      "<td>#{args[:post].published_at.present? ? args[:post].published_at.strftime('%B %e, %Y %H:%M') : args[:post].the_created_at}</td>"
  else
    args[:content] = "<th>#{t('camaleon_cms.admin.table.visibility')}</th>"
    args[:content] = "<th>#{t('camaleon_cms.admin.table.date_published')}</th>"
  end
end

#plugin_visibility_filter_post(args) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 51

def plugin_visibility_filter_post(args)
  args[:active_record] =
    args[:active_record].where(
      "(#{CamaleonCms::Post.table_name}.published_at is null or #{CamaleonCms::Post.table_name}.published_at <= ?)", Time.now
    )
  args[:active_record] = if signin?
                           if ActiveRecord::Base.connection.adapter_name.downcase.include?('mysql')
                             args[:active_record].where("visibility != 'private' or (visibility = 'private' and FIND_IN_SET(?, #{CamaleonCms::Post.table_name}.visibility_value))", current_site.visitor_role)
                           else
                             args[:active_record].where("visibility != 'private' or (visibility = 'private' and (',' || #{CamaleonCms::Post.table_name}.visibility_value || ',') LIKE '%,#{current_site.visitor_role},%')")
                           end
                         else
                           args[:active_record].where("visibility != 'private'")
                         end
end

#plugin_visibility_new_post(args) ⇒ Object



26
27
28
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 26

def plugin_visibility_new_post(args)
  args[:extra_settings] << form_html(args[:post])
end

#plugin_visibility_on_active(plugin) ⇒ Object



12
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 12

def plugin_visibility_on_active(plugin); end

#plugin_visibility_on_inactive(plugin) ⇒ Object



14
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 14

def plugin_visibility_on_inactive(plugin); end

#plugin_visibility_post_list(args) ⇒ Object



16
17
18
19
20
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 16

def plugin_visibility_post_list(args)
  args[:posts] = args[:posts].where(visibility: 'private') if params[:s] == 'private'
  args[:btns][:private] =
    "#{t('camaleon_cms.admin.table.private')} (#{args[:all_posts].where(visibility: 'private').size})"
end

#plugin_visibility_post_the_content(args) ⇒ Object

object.content.translate(@_deco_locale), post: object



5
6
7
8
9
10
# File 'app/apps/plugins/visibility_post/visibility_post_helper.rb', line 5

def plugin_visibility_post_the_content(args)
  return unless args[:post].visibility == 'password'
  return if params[:post_password].present? && params[:post_password] == args[:post].visibility_value

  args[:content] = _password_form
end