Class: CloudObject::Discussion

Inherits:
ApplicationLesliRecord
  • Object
show all
Defined in:
app/models/lesli/cloud_object/discussion.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cloud_object_modelClass

Returns The class of the association ‘belongs_to’.

Examples:

puts DeutscheLeibrenten::Project::Discussion.cloud_object_model.new # This will display an instance of DeutscheLeibrenten::Project

Returns:

  • (Class)

    The class of the association ‘belongs_to’



111
112
113
# File 'app/models/lesli/cloud_object/discussion.rb', line 111

def self.cloud_object_model
    self.reflect_on_association(:cloud_object).klass
end

.index(current_user, cloud_id, query) ⇒ Array

Returns Array of discussions. Each discussion contains a responses element, which is an array that has all its responses ordered by date.

Examples:

current_user = the user making this request
employee_id = params[:employee_id]
discussions = CloudTeam::Employee::Discussion.index( , employee_id, @query )

Parameters:

  • account (Account)

    Account from current user

  • cloud_id (Integer)

    Id of the cloud_object to which this discussion belongs to

  • query (Query)

    that contains the search and pagination information

Returns:

  • (Array)

    Array of discussions. Each discussion contains a responses element, which is an array that has all its responses ordered by date



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/models/lesli/cloud_object/discussion.rb', line 55

def self.index(current_user, cloud_id, query)
    cloud_object_model = self.cloud_object_model
     = cloud_object_model.reflect_on_association(:account).klass
    
    # get search string from query params
    #search_string = query[:search].downcase.gsub(" ","%") unless query[:search].blank?
    
    discussions = self.joins(:cloud_object)
    .joins("inner join lesli_users u on #{self.table_name}.user_id = u.id")
    .where("#{cloud_object_model.table_name}.id = #{cloud_id}")
    .where("#{cloud_object_model.table_name}.account_id = #{current_user.account.id}")
    .select(
        "#{self.table_name}.id",
        "#{self.table_name}.user_id",
        "#{self.table_name}.content",
        Date2.new.date_time.db_timestamps("#{self.table_name}"),
        "u.email",
        "CONCAT_WS(' ', u.first_name, u.last_name) as user_name"
    )

    # Filter results by search string
    # unless search_string.blank?
    #     discussions = discussions.where("
    #     (LOWER(ud.first_name) SIMILAR TO '%#{search_string}%') OR 
    #     (LOWER(ud.last_name) SIMILAR TO '%#{search_string}%') OR 
    #     (LOWER(#{self.table_name}.content) SIMILAR TO '%#{search_string}%')
    #     ")
    # end

    discussions = self.format_discussions(discussions)

    Kaminari.paginate_array(discussions).page(query[:pagination][:page]).per(query[:pagination][:perPage])
end

Instance Method Details

#show(current_user = nil) ⇒ Hash

Returns Information about the discussion.

Examples:

discussion = CloudHelp::Ticket::Discussion.first
puts discussion.show #This will display extra information about the discussion, like the user's name

Returns:

  • (Hash)

    Information about the discussion



95
96
97
98
99
100
101
102
103
104
# File 'app/models/lesli/cloud_object/discussion.rb', line 95

def show(current_user = nil)
    discussion_attributes = attributes.merge({
        editable: is_editable_by?(current_user),
        email: user_creator.email,
        user_name: user_creator.full_name
    })
    discussion_attributes["created_at"] = LC::Date.to_string_datetime(discussion_attributes["created_at"])

    discussion_attributes
end

#user_mainUser

Returns This method will always return nil.

Returns:

  • (User)

    This method will always return nil



40
41
42
# File 'app/models/lesli/cloud_object/discussion.rb', line 40

def user_main
    return nil
end