Class: CloudObject::Discussion
- Inherits:
-
ApplicationLesliRecord
- Object
- ApplicationLesliRecord
- CloudObject::Discussion
- Defined in:
- app/models/lesli/cloud_object/discussion.rb
Class Method Summary collapse
-
.cloud_object_model ⇒ Class
The class of the association ‘belongs_to’.
-
.index(current_user, cloud_id, query) ⇒ Array
Array of discussions.
Instance Method Summary collapse
-
#show(current_user = nil) ⇒ Hash
Information about the discussion.
-
#user_main ⇒ User
This method will always return nil.
Class Method Details
.cloud_object_model ⇒ Class
Returns 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.
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 account_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.("#{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.
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_main ⇒ User
Returns 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 |