Sha256: c1900f5d4e7ff1c928177b75316e02cb01f8addef5637252d1116ae2accb64c9

Contents?: true

Size: 1.4 KB

Versions: 22

Compression:

Stored size: 1.4 KB

Contents

module Alchemy
  module Page::PageUsers
    extend ActiveSupport::Concern

    # Returns the creator of this page.
    #
    def creator
      get_page_user(creator_id)
    end

    # Returns the last updater of this page.
    #
    def updater
      get_page_user(updater_id)
    end

    # Returns the user currently editing this page.
    #
    def locker
      get_page_user(locked_by)
    end

    # Returns the name of the creator of this page.
    #
    # If no creator could be found or associated user model
    # does not respond to +#name+ it returns +'unknown'+
    #
    def creator_name
      (creator && creator.try(:name)) || Alchemy.t('unknown')
    end

    # Returns the name of the last updater of this page.
    #
    # If no updater could be found or associated user model
    # does not respond to +#name+ it returns +'unknown'+
    #
    def updater_name
      (updater && updater.try(:name)) || Alchemy.t('unknown')
    end

    # Returns the name of the user currently editing this page.
    #
    # If no locker could be found or associated user model
    # does not respond to +#name+ it returns +'unknown'+
    #
    def locker_name
      (locker && locker.try(:name)) || Alchemy.t('unknown')
    end

    private

    def get_page_user(id)
      if Alchemy.user_class.respond_to? :primary_key
        Alchemy.user_class.try(:find_by, {Alchemy.user_class.primary_key => id})
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
alchemy_cms-3.6.7 app/models/alchemy/page/page_users.rb
alchemy_cms-3.6.6 app/models/alchemy/page/page_users.rb
alchemy_cms-3.6.5 app/models/alchemy/page/page_users.rb
alchemy_cms-3.6.4 app/models/alchemy/page/page_users.rb
alchemy_cms-3.6.3 app/models/alchemy/page/page_users.rb
alchemy_cms-3.6.2 app/models/alchemy/page/page_users.rb
alchemy_cms-3.6.1 app/models/alchemy/page/page_users.rb
alchemy_cms-4.0.0.beta app/models/alchemy/page/page_users.rb
alchemy_cms-3.6.0 app/models/alchemy/page/page_users.rb
alchemy_cms-3.5.0 app/models/alchemy/page/page_users.rb
alchemy_cms-3.4.2 app/models/alchemy/page/page_users.rb
alchemy_cms-3.5.0.rc2 app/models/alchemy/page/page_users.rb
alchemy_cms-3.5.0.rc1 app/models/alchemy/page/page_users.rb
alchemy_cms-3.4.1 app/models/alchemy/page/page_users.rb
alchemy_cms-3.3.3 app/models/alchemy/page/page_users.rb
alchemy_cms-3.3.2 app/models/alchemy/page/page_users.rb
alchemy_cms-3.4.0 app/models/alchemy/page/page_users.rb
alchemy_cms-3.4.0.rc1 app/models/alchemy/page/page_users.rb
alchemy_cms-3.3.1 app/models/alchemy/page/page_users.rb
alchemy_cms-3.3.0 app/models/alchemy/page/page_users.rb