aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/workgroup.rb
blob: 499441cd3dcd57ce6c6170c6c0c9d8aae5aa72da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class Workgroup < ApplicationModel
  belongs_to :line_referential
  belongs_to :stop_area_referential
  belongs_to :owner, class_name: "Organisation"

  has_many :workbenches
  has_many :calendars
  has_many :organisations, through: :workbenches
  has_many :referentials, through: :workbenches

  validates_uniqueness_of :name

  validates_presence_of :line_referential_id
  validates_presence_of :stop_area_referential_id
  validates_uniqueness_of :stop_area_referential_id
  validates_uniqueness_of :line_referential_id

  has_many :custom_fields

  accepts_nested_attributes_for :workbenches

  def custom_fields_definitions
    Hash[*custom_fields.map{|cf| [cf.code, cf]}.flatten]
  end

  def has_export? export_name
    export_types.include? export_name
  end

  def available_compliance_control_sets
    %i(
      import
      merge
      automatic
      workgroup
      workbench
    ).inject({}) do |h, k|
      h[k] = "workgroups.available_compliance_control_sets.#{k}".t.capitalize
      h
    end
  end
  def import_compliance_control_sets
    %i(
      import
      workbench
    ).inject({}) do |h, k|
      h[k] = "workgroups.available_compliance_control_sets.#{k}".t.capitalize
      h
    end
  end

  # XXX
  # def import_compliance_control_sets
  #   @import_compliance_control_sets ||= import_compliance_control_set_ids.map{|id| ComplianceControlSet.find(id)}
  # end
end