Class: Course
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Course
- Includes:
- HasOwner, Toggleable
- Defined in:
- app/models/course.rb
Constant Summary collapse
- PER_PAGE =
24
- DESCRIPTION_LIMIT =
50000
- DURATION_LIMIT =
50
- LEAD_LIMIT =
1000
- META_LIMIT =
255
- PRIORITY_RANGE =
(1..999)
- SLUG_LIMIT =
250
- SLUG_PATTERN =
/\A[a-z][-0-9a-z]*[0-9a-z]\z/i
- SLUG_PATTERN_HTML =
'^[a-zA-Z][-0-9a-zA-Z]*[0-9a-zA-Z]$'
- TITLE_LIMIT =
250
Class Method Summary collapse
- .entity_parameters ⇒ Object
- .page_for_administration(page = 1) ⇒ Object
- .page_for_visitors(page = 1) ⇒ Object
Instance Method Summary collapse
Class Method Details
.entity_parameters ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'app/models/course.rb', line 65 def self.entity_parameters texts = %i(title subtitle slug lead description duration) decoration = %i(price special_price special_price_end image image_alt_text) = %i(meta_title meta_keywords meta_description metadata) = %i(course_category_id priority visible highlight online) texts + decoration + + end |
.page_for_administration(page = 1) ⇒ Object
56 57 58 |
# File 'app/models/course.rb', line 56 def self.page_for_administration(page = 1) ordered_by_priority.page(page).per(PER_PAGE) end |
.page_for_visitors(page = 1) ⇒ Object
61 62 63 |
# File 'app/models/course.rb', line 61 def self.page_for_visitors(page = 1) list_for_visitors.page(page).per(PER_PAGE) end |
Instance Method Details
#change_priority(delta) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/models/course.rb', line 85 def change_priority(delta) new_priority = priority + delta criteria = { course_category_id: course_category_id, priority: new_priority } adjacent = self.class.find_by(criteria) if adjacent.is_a?(self.class) && (adjacent.id != id) adjacent.update!(priority: priority) end self.update(priority: new_priority) self.class.for_tree(course_category_id).map { |e| [e.id, e.priority] }.to_h end |
#editable_by?(user) ⇒ Boolean
75 76 77 |
# File 'app/models/course.rb', line 75 def editable_by?(user) owned_by?(user) || UserPrivilege.user_has_privilege?(user, :chief_course_manager) end |
#lockable_by?(user) ⇒ Boolean
80 81 82 |
# File 'app/models/course.rb', line 80 def lockable_by?(user) UserPrivilege.user_has_privilege?(user, :chief_course_manager) end |