Class: Lcms::Engine::Document

Inherits:
ApplicationRecord show all
Includes:
Partable
Defined in:
app/models/lcms/engine/document.rb

Constant Summary collapse

GOOGLE_URL_PREFIX =
'https://docs.google.com/document/d'

Instance Method Summary collapse

Methods included from Partable

#create_parts_for, #layout

Instance Method Details

#activate!Object



65
66
67
68
69
70
71
72
# File 'app/models/lcms/engine/document.rb', line 65

def activate!
  self.class.transaction do
    # deactive all other lessons for this resource
    self.class.where(resource_id: resource_id).where.not(id: id).update_all active: false
    # activate this lesson. PS: use a simple sql update, no callbacks
    update_columns active: true
  end
end

#assessment?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'app/models/lcms/engine/document.rb', line 74

def assessment?
  resource&.assessment?
end

#ela?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'app/models/lcms/engine/document.rb', line 78

def ela?
  ['subject'].to_s.casecmp('ela').zero?
end

#file_fs_urlObject



88
89
90
91
92
# File 'app/models/lcms/engine/document.rb', line 88

def file_fs_url
  return unless foundational_file_id.present?

  "#{GOOGLE_URL_PREFIX}/#{foundational_file_id}"
end

#file_urlObject



82
83
84
85
86
# File 'app/models/lcms/engine/document.rb', line 82

def file_url
  return unless file_id.present?

  "#{GOOGLE_URL_PREFIX}/#{file_id}"
end

#foundational?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'app/models/lcms/engine/document.rb', line 94

def foundational?
  ['type'].to_s.casecmp('fs').zero?
end

#gdoc_material_idsObject



98
99
100
# File 'app/models/lcms/engine/document.rb', line 98

def gdoc_material_ids
  materials.gdoc.pluck(:id)
end

#materials_anchorsObject



102
103
104
105
106
107
108
109
110
111
# File 'app/models/lcms/engine/document.rb', line 102

def materials_anchors
  {}.tap do |materials_with_anchors|
    toc.collect_children.each do |x|
      x.material_ids.each do |m|
        materials_with_anchors[m] ||= { optional: [], anchors: [] }
        materials_with_anchors[m][x.optional ? :optional : :anchors] << x.anchor
      end
    end
  end
end

#math?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'app/models/lcms/engine/document.rb', line 113

def math?
  ['subject'].to_s.casecmp('math').zero?
end

#ordered_material_idsObject



117
118
119
# File 'app/models/lcms/engine/document.rb', line 117

def ordered_material_ids
  toc.ordered_material_ids
end


121
122
123
124
125
126
127
128
# File 'app/models/lcms/engine/document.rb', line 121

def tmp_link(key)
  url = links[key]
  with_lock do
    reload.links.delete(key)
    update links: links
  end
  url
end