2019-09-13 01:01:17 +02:00
|
|
|
defmodule Mobilizon.Events.EventOptions do
|
2019-08-28 11:28:27 +02:00
|
|
|
@moduledoc """
|
2019-09-13 01:01:17 +02:00
|
|
|
Represents an event options.
|
2019-08-28 11:28:27 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
use Ecto.Schema
|
|
|
|
|
2019-09-13 01:01:17 +02:00
|
|
|
import Ecto.Changeset
|
2019-08-28 11:28:27 +02:00
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
alias Mobilizon.Discussions.CommentModeration
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-08-28 11:28:27 +02:00
|
|
|
alias Mobilizon.Events.{
|
|
|
|
EventOffer,
|
2019-09-22 16:26:23 +02:00
|
|
|
EventParticipationCondition
|
2019-08-28 11:28:27 +02:00
|
|
|
}
|
|
|
|
|
2019-09-13 01:01:17 +02:00
|
|
|
@type t :: %__MODULE__{
|
|
|
|
maximum_attendee_capacity: integer,
|
|
|
|
remaining_attendee_capacity: integer,
|
|
|
|
show_remaining_attendee_capacity: boolean,
|
2019-12-20 13:04:34 +01:00
|
|
|
anonymous_participation: boolean,
|
2019-09-13 01:01:17 +02:00
|
|
|
attendees: [String.t()],
|
|
|
|
program: String.t(),
|
|
|
|
comment_moderation: CommentModeration.t(),
|
|
|
|
show_participation_price: boolean,
|
|
|
|
offers: [EventOffer.t()],
|
2019-10-14 19:29:18 +02:00
|
|
|
participation_condition: [EventParticipationCondition.t()],
|
|
|
|
show_start_time: boolean,
|
2020-02-18 08:57:00 +01:00
|
|
|
show_end_time: boolean,
|
|
|
|
hide_organizer_when_group_event: boolean
|
2019-09-13 01:01:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@attrs [
|
|
|
|
:maximum_attendee_capacity,
|
|
|
|
:remaining_attendee_capacity,
|
|
|
|
:show_remaining_attendee_capacity,
|
2019-12-20 13:04:34 +01:00
|
|
|
:anonymous_participation,
|
2019-09-13 01:01:17 +02:00
|
|
|
:attendees,
|
|
|
|
:program,
|
|
|
|
:comment_moderation,
|
2019-10-14 19:29:18 +02:00
|
|
|
:show_participation_price,
|
|
|
|
:show_start_time,
|
2020-02-18 08:57:00 +01:00
|
|
|
:show_end_time,
|
|
|
|
:hide_organizer_when_group_event
|
2019-09-13 01:01:17 +02:00
|
|
|
]
|
|
|
|
|
2019-08-28 11:28:27 +02:00
|
|
|
@primary_key false
|
2019-09-09 09:31:08 +02:00
|
|
|
@derive Jason.Encoder
|
2019-08-28 11:28:27 +02:00
|
|
|
embedded_schema do
|
|
|
|
field(:maximum_attendee_capacity, :integer)
|
|
|
|
field(:remaining_attendee_capacity, :integer)
|
|
|
|
field(:show_remaining_attendee_capacity, :boolean)
|
2019-12-20 13:04:34 +01:00
|
|
|
field(:anonymous_participation, :boolean)
|
2019-08-28 11:28:27 +02:00
|
|
|
field(:attendees, {:array, :string})
|
|
|
|
field(:program, :string)
|
|
|
|
field(:comment_moderation, CommentModeration)
|
|
|
|
field(:show_participation_price, :boolean)
|
2019-10-14 20:00:58 +02:00
|
|
|
field(:show_start_time, :boolean, default: true)
|
|
|
|
field(:show_end_time, :boolean, default: true)
|
2020-02-18 08:57:00 +01:00
|
|
|
field(:hide_organizer_when_group_event, :boolean, default: false)
|
2019-09-13 01:01:17 +02:00
|
|
|
|
|
|
|
embeds_many(:offers, EventOffer)
|
|
|
|
embeds_many(:participation_condition, EventParticipationCondition)
|
2019-08-28 11:28:27 +02:00
|
|
|
end
|
|
|
|
|
2019-09-13 01:01:17 +02:00
|
|
|
@doc false
|
2021-09-24 16:46:42 +02:00
|
|
|
@spec changeset(t | Ecto.Schema.t(), map) :: Ecto.Changeset.t()
|
2019-09-13 01:55:45 +02:00
|
|
|
def changeset(%__MODULE__{} = event_options, attrs) do
|
2020-06-05 11:38:49 +02:00
|
|
|
event_options
|
|
|
|
|> cast(attrs, @attrs)
|
|
|
|
|> validate_number(:maximum_attendee_capacity, greater_than_or_equal_to: 0)
|
2019-08-28 11:28:27 +02:00
|
|
|
end
|
|
|
|
end
|