Event
extends Model
in package
Event entity representing a calendar event.
Attributes
- #[Table]
- 'events'
Table of Contents
Constants
- STATUS_DRAFT = 'draft'
- Event status constants
- STATUS_PUBLISHED = 'published'
Properties
- $_loadedRelations : array<string|int, mixed>
- Loaded relations cache
- $_pdo : PDO|null
- Database connection
- $_relationCache : array<string|int, mixed>
- Relation metadata cache
- $_allDay : bool
- $_category : EventCategory|null
- $_categoryId : int|null
- $_contactEmail : string|null
- $_contactPhone : string|null
- $_contentRaw : string
- $_createdAt : DateTimeImmutable|null
- $_createdBy : int|null
- $_creator : User|null
- $_description : string|null
- $_endDate : DateTimeImmutable|null
- $_featuredImage : string|null
- $_id : int|null
- $_location : string|null
- $_organizer : string|null
- $_slug : string
- $_startDate : DateTimeImmutable
- $_status : string
- $_title : string
- $_updatedAt : DateTimeImmutable|null
- $_viewCount : int
Methods
- __construct() : mixed
- __get() : mixed
- Magic method to access relations.
- all() : array<string|int, mixed>
- Get all models.
- beginTransaction() : bool
- Begin a database transaction.
- commit() : bool
- Commit the current transaction.
- create() : static
- Create a new model and save it to the database.
- delete() : bool
- Delete the model without handling dependents (simple delete).
- destroy() : bool
- Delete the model from the database with dependent cascade.
- destroyMany() : int
- Delete one or more models by ID.
- exists() : bool
- Check if the model exists in the database.
- fill() : self
- Fill the model with an array of attributes.
- find() : static|null
- Find a model by primary key.
- fromArray() : static
- Create Event from array data
- getAttribute() : mixed
- Get an attribute value from the model.
- getCategory() : EventCategory|null
- Get category
- getCategoryId() : int|null
- Get category ID
- getContactEmail() : string|null
- Get contact email
- getContactPhone() : string|null
- Get contact phone
- getContent() : array<string|int, mixed>
- Get content as array (decoded Editor.js JSON)
- getContentRaw() : string
- Get raw content JSON string
- getCreatedAt() : DateTimeImmutable|null
- Get created timestamp
- getCreatedBy() : int|null
- Get creator ID
- getCreator() : User|null
- Get creator
- getDescription() : string|null
- Get description
- getEndDate() : DateTimeImmutable|null
- Get end date
- getFeaturedImage() : string|null
- Get featured image
- getId() : int|null
- Get event ID
- getLocation() : string|null
- Get location
- getOrganizer() : string|null
- Get organizer
- getPrimaryKey() : string
- Get the primary key column name.
- getSlug() : string
- Get slug
- getStartDate() : DateTimeImmutable
- Get start date
- getStatus() : string
- Get status
- getTableName() : string
- Get the table name for this model from the Table attribute.
- getTitle() : string
- Get title
- getUpdatedAt() : DateTimeImmutable|null
- Get updated timestamp
- getViewCount() : int
- Get view count
- incrementViewCount() : self
- Increment view count
- inTransaction() : bool
- Check if currently inside a transaction.
- isAllDay() : bool
- Check if event is all day
- isDraft() : bool
- Check if event is draft
- isOngoing() : bool
- Check if event is currently happening
- isPast() : bool
- Check if event is past (ended in the past)
- isPublished() : bool
- Check if event is published
- isUpcoming() : bool
- Check if event is upcoming (starts in the future)
- limit() : QueryBuilder
- Set result limit.
- loadRelations() : void
- Eager load relations.
- offset() : QueryBuilder
- Set result offset.
- orderBy() : QueryBuilder
- Add an order by clause.
- query() : QueryBuilder
- Create a new query builder for this model.
- relation() : BelongsToRelation|HasManyRelation|HasOneRelation|BelongsToManyRelation
- Get a relation instance (for calling sync/attach/detach methods).
- rollBack() : bool
- Roll back the current transaction.
- save() : bool
- Save the model to the database (insert or update).
- setAllDay() : self
- Set all day flag
- setAttribute() : void
- Set an attribute value on the model.
- setCategory() : self
- Set category
- setCategoryId() : self
- Set category ID
- setContactEmail() : self
- Set contact email
- setContactPhone() : self
- Set contact phone
- setContent() : self
- Set content from Editor.js JSON string
- setContentArray() : self
- Set content from array (will be JSON encoded)
- setCreatedAt() : self
- Set created timestamp
- setCreatedBy() : self
- Set creator ID
- setCreator() : self
- Set creator
- setDescription() : self
- Set description
- setEndDate() : self
- Set end date
- setFeaturedImage() : self
- Set featured image
- setId() : self
- Set event ID
- setLoadedRelation() : void
- Set a loaded relation (used by eager loading).
- setLocation() : self
- Set location
- setOrganizer() : self
- Set organizer
- setPdo() : void
- Set the PDO connection for all models.
- setSlug() : self
- Set slug
- setStartDate() : self
- Set start date
- setStatus() : self
- Set status
- setTitle() : self
- Set title
- setUpdatedAt() : self
- Set updated timestamp
- setViewCount() : self
- Set view count
- toArray() : array<string|int, mixed>
- Convert event to array
- transaction() : mixed
- Execute a closure within a database transaction.
- update() : bool
- Update the model's attributes and save to database.
- where() : QueryBuilder
- Start a query with a where clause.
- whereIn() : QueryBuilder
- Start a query with a where in clause.
- with() : QueryBuilder
- Eager load relations.
- createRelation() : BelongsToRelation|HasManyRelation|HasOneRelation|BelongsToManyRelation
- Create a relation instance.
- getForeignKeyName() : string
- Get the foreign key name for this model.
- getPdo() : PDO
- Get the PDO connection.
- getPivotTableName() : string
- Get the pivot table name for a many-to-many relationship.
- getRelatedForeignKeyName() : string
- Get the foreign key name for a related model.
- getRelationMetadata() : array<string|int, mixed>|null
- Get relation metadata for a property.
- handleDependentRelations() : void
- Handle dependent relations before destroying the model.
- performInsert() : bool
- Perform an insert operation.
- performUpdate() : bool
- Perform an update operation.
- propertyToColumn() : string
- Convert property name to database column name.
Constants
STATUS_DRAFT
Event status constants
Use ContentStatus enum instead
public
mixed
STATUS_DRAFT
= 'draft'
STATUS_PUBLISHED
public
mixed
STATUS_PUBLISHED
= 'published'
Properties
$_loadedRelations
Loaded relations cache
protected
array<string|int, mixed>
$_loadedRelations
= []
$_pdo
Database connection
protected
static PDO|null
$_pdo
= null
$_relationCache
Relation metadata cache
protected
static array<string|int, mixed>
$_relationCache
= []
$_allDay
private
bool
$_allDay
= false
$_category
private
EventCategory|null
$_category
= null
Attributes
- #[BelongsTo]
- \Neuron\Cms\Models\EventCategory::class
- $foreignKey: 'category_id'
$_categoryId
private
int|null
$_categoryId
= null
$_contactEmail
private
string|null
$_contactEmail
= null
$_contactPhone
private
string|null
$_contactPhone
= null
$_contentRaw
private
string
$_contentRaw
= '{"blocks":[]}'
$_createdAt
private
DateTimeImmutable|null
$_createdAt
= null
$_createdBy
private
int|null
$_createdBy
= null
$_creator
private
User|null
$_creator
= null
Attributes
- #[BelongsTo]
- \Neuron\Cms\Models\User::class
- $foreignKey: 'created_by'
$_description
private
string|null
$_description
= null
$_endDate
private
DateTimeImmutable|null
$_endDate
= null
$_featuredImage
private
string|null
$_featuredImage
= null
$_id
private
int|null
$_id
= null
$_location
private
string|null
$_location
= null
$_organizer
private
string|null
$_organizer
= null
$_slug
private
string
$_slug
$_startDate
private
DateTimeImmutable
$_startDate
$_status
private
string
$_status
= 'draft'
$_title
private
string
$_title
$_updatedAt
private
DateTimeImmutable|null
$_updatedAt
= null
$_viewCount
private
int
$_viewCount
= 0
Methods
__construct()
public
__construct() : mixed
__get()
Magic method to access relations.
public
__get(string $name) : mixed
Parameters
- $name : string
Tags
all()
Get all models.
public
static all() : array<string|int, mixed>
Return values
array<string|int, mixed>beginTransaction()
Begin a database transaction.
public
static beginTransaction() : bool
Tags
Return values
bool —True on success
commit()
Commit the current transaction.
public
static commit() : bool
Tags
Return values
bool —True on success
create()
Create a new model and save it to the database.
public
static create(array<string|int, mixed> $attributes) : static
Parameters
- $attributes : array<string|int, mixed>
Tags
Return values
staticdelete()
Delete the model without handling dependents (simple delete).
public
delete() : bool
Tags
Return values
booldestroy()
Delete the model from the database with dependent cascade.
public
destroy() : bool
Tags
Return values
booldestroyMany()
Delete one or more models by ID.
public
static destroyMany(int|array<string|int, mixed> $ids) : int
Parameters
- $ids : int|array<string|int, mixed>
Tags
Return values
int —Number of records deleted
exists()
Check if the model exists in the database.
public
exists() : bool
Return values
boolfill()
Fill the model with an array of attributes.
public
fill(array<string|int, mixed> $attributes) : self
Parameters
- $attributes : array<string|int, mixed>
Return values
selffind()
Find a model by primary key.
public
static find(int $id) : static|null
Parameters
- $id : int
Return values
static|nullfromArray()
Create Event from array data
public
static fromArray(array<string|int, mixed> $data) : static
Parameters
- $data : array<string|int, mixed>
-
Associative array of event data
Tags
Return values
staticgetAttribute()
Get an attribute value from the model.
public
getAttribute(string $key) : mixed
Parameters
- $key : string
getCategory()
Get category
public
getCategory() : EventCategory|null
Return values
EventCategory|nullgetCategoryId()
Get category ID
public
getCategoryId() : int|null
Return values
int|nullgetContactEmail()
Get contact email
public
getContactEmail() : string|null
Return values
string|nullgetContactPhone()
Get contact phone
public
getContactPhone() : string|null
Return values
string|nullgetContent()
Get content as array (decoded Editor.js JSON)
public
getContent() : array<string|int, mixed>
Return values
array<string|int, mixed>getContentRaw()
Get raw content JSON string
public
getContentRaw() : string
Return values
stringgetCreatedAt()
Get created timestamp
public
getCreatedAt() : DateTimeImmutable|null
Return values
DateTimeImmutable|nullgetCreatedBy()
Get creator ID
public
getCreatedBy() : int|null
Return values
int|nullgetCreator()
Get creator
public
getCreator() : User|null
Return values
User|nullgetDescription()
Get description
public
getDescription() : string|null
Return values
string|nullgetEndDate()
Get end date
public
getEndDate() : DateTimeImmutable|null
Return values
DateTimeImmutable|nullgetFeaturedImage()
Get featured image
public
getFeaturedImage() : string|null
Return values
string|nullgetId()
Get event ID
public
getId() : int|null
Return values
int|nullgetLocation()
Get location
public
getLocation() : string|null
Return values
string|nullgetOrganizer()
Get organizer
public
getOrganizer() : string|null
Return values
string|nullgetPrimaryKey()
Get the primary key column name.
public
static getPrimaryKey() : string
Return values
stringgetSlug()
Get slug
public
getSlug() : string
Return values
stringgetStartDate()
Get start date
public
getStartDate() : DateTimeImmutable
Return values
DateTimeImmutablegetStatus()
Get status
public
getStatus() : string
Return values
stringgetTableName()
Get the table name for this model from the Table attribute.
public
static getTableName() : string
Tags
Return values
stringgetTitle()
Get title
public
getTitle() : string
Return values
stringgetUpdatedAt()
Get updated timestamp
public
getUpdatedAt() : DateTimeImmutable|null
Return values
DateTimeImmutable|nullgetViewCount()
Get view count
public
getViewCount() : int
Return values
intincrementViewCount()
Increment view count
public
incrementViewCount() : self
Return values
selfinTransaction()
Check if currently inside a transaction.
public
static inTransaction() : bool
Tags
Return values
bool —True if inside a transaction
isAllDay()
Check if event is all day
public
isAllDay() : bool
Return values
boolisDraft()
Check if event is draft
public
isDraft() : bool
Return values
boolisOngoing()
Check if event is currently happening
public
isOngoing() : bool
Return values
boolisPast()
Check if event is past (ended in the past)
public
isPast() : bool
Return values
boolisPublished()
Check if event is published
public
isPublished() : bool
Return values
boolisUpcoming()
Check if event is upcoming (starts in the future)
public
isUpcoming() : bool
Return values
boollimit()
Set result limit.
public
static limit(int $limit) : QueryBuilder
Parameters
- $limit : int
Return values
QueryBuilderloadRelations()
Eager load relations.
public
static loadRelations(array<string|int, mixed> $relations, array<string|int, mixed> $models) : void
Parameters
- $relations : array<string|int, mixed>
-
Relation names to load
- $models : array<string|int, mixed>
-
Array of models to load relations for
offset()
Set result offset.
public
static offset(int $offset) : QueryBuilder
Parameters
- $offset : int
Return values
QueryBuilderorderBy()
Add an order by clause.
public
static orderBy(string $column[, string $direction = 'ASC' ]) : QueryBuilder
Parameters
- $column : string
- $direction : string = 'ASC'
Return values
QueryBuilderquery()
Create a new query builder for this model.
public
static query() : QueryBuilder
Return values
QueryBuilderrelation()
Get a relation instance (for calling sync/attach/detach methods).
public
relation(string $name) : BelongsToRelation|HasManyRelation|HasOneRelation|BelongsToManyRelation
Parameters
- $name : string
-
Relation name
Tags
Return values
BelongsToRelation|HasManyRelation|HasOneRelation|BelongsToManyRelationrollBack()
Roll back the current transaction.
public
static rollBack() : bool
Tags
Return values
bool —True on success
save()
Save the model to the database (insert or update).
public
save() : bool
Tags
Return values
boolsetAllDay()
Set all day flag
public
setAllDay(bool $allDay) : self
Parameters
- $allDay : bool
Return values
selfsetAttribute()
Set an attribute value on the model.
public
setAttribute(string $key, mixed $value) : void
Parameters
- $key : string
- $value : mixed
setCategory()
Set category
public
setCategory(EventCategory|null $category) : self
Parameters
- $category : EventCategory|null
Return values
selfsetCategoryId()
Set category ID
public
setCategoryId(int|null $categoryId) : self
Parameters
- $categoryId : int|null
Return values
selfsetContactEmail()
Set contact email
public
setContactEmail(string|null $contactEmail) : self
Parameters
- $contactEmail : string|null
Return values
selfsetContactPhone()
Set contact phone
public
setContactPhone(string|null $contactPhone) : self
Parameters
- $contactPhone : string|null
Return values
selfsetContent()
Set content from Editor.js JSON string
public
setContent(string $jsonContent) : self
Parameters
- $jsonContent : string
Return values
selfsetContentArray()
Set content from array (will be JSON encoded)
public
setContentArray(array<string|int, mixed> $content) : self
Parameters
- $content : array<string|int, mixed>
-
Content array to encode
Tags
Return values
selfsetCreatedAt()
Set created timestamp
public
setCreatedAt(DateTimeImmutable $createdAt) : self
Parameters
- $createdAt : DateTimeImmutable
Return values
selfsetCreatedBy()
Set creator ID
public
setCreatedBy(int $createdBy) : self
Parameters
- $createdBy : int
Return values
selfsetCreator()
Set creator
public
setCreator(User|null $creator) : self
Parameters
- $creator : User|null
Return values
selfsetDescription()
Set description
public
setDescription(string|null $description) : self
Parameters
- $description : string|null
Return values
selfsetEndDate()
Set end date
public
setEndDate(DateTimeImmutable|null $endDate) : self
Parameters
- $endDate : DateTimeImmutable|null
Return values
selfsetFeaturedImage()
Set featured image
public
setFeaturedImage(string|null $featuredImage) : self
Parameters
- $featuredImage : string|null
Return values
selfsetId()
Set event ID
public
setId(int $id) : self
Parameters
- $id : int
Return values
selfsetLoadedRelation()
Set a loaded relation (used by eager loading).
public
setLoadedRelation(string $name, mixed $value) : void
Parameters
- $name : string
- $value : mixed
setLocation()
Set location
public
setLocation(string|null $location) : self
Parameters
- $location : string|null
Return values
selfsetOrganizer()
Set organizer
public
setOrganizer(string|null $organizer) : self
Parameters
- $organizer : string|null
Return values
selfsetPdo()
Set the PDO connection for all models.
public
static setPdo(PDO $pdo) : void
Parameters
- $pdo : PDO
setSlug()
Set slug
public
setSlug(string $slug) : self
Parameters
- $slug : string
Return values
selfsetStartDate()
Set start date
public
setStartDate(DateTimeImmutable $startDate) : self
Parameters
- $startDate : DateTimeImmutable
Return values
selfsetStatus()
Set status
public
setStatus(string $status) : self
Parameters
- $status : string
Return values
selfsetTitle()
Set title
public
setTitle(string $title) : self
Parameters
- $title : string
Return values
selfsetUpdatedAt()
Set updated timestamp
public
setUpdatedAt(DateTimeImmutable|null $updatedAt) : self
Parameters
- $updatedAt : DateTimeImmutable|null
Return values
selfsetViewCount()
Set view count
public
setViewCount(int $viewCount) : self
Parameters
- $viewCount : int
Return values
selftoArray()
Convert event to array
public
toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>transaction()
Execute a closure within a database transaction.
public
static transaction(callable $callback) : mixed
If the closure executes successfully, the transaction is committed. If an exception is thrown, the transaction is rolled back and the exception is re-thrown.
Parameters
- $callback : callable
-
Function to execute within transaction
Tags
Return values
mixed —The return value of the callback
update()
Update the model's attributes and save to database.
public
update(array<string|int, mixed> $attributes) : bool
Parameters
- $attributes : array<string|int, mixed>
Tags
Return values
boolwhere()
Start a query with a where clause.
public
static where(string $column, mixed $operator[, mixed|null $value = null ]) : QueryBuilder
Parameters
- $column : string
- $operator : mixed
- $value : mixed|null = null
Return values
QueryBuilderwhereIn()
Start a query with a where in clause.
public
static whereIn(string $column, array<string|int, mixed> $values) : QueryBuilder
Parameters
- $column : string
- $values : array<string|int, mixed>
Return values
QueryBuilderwith()
Eager load relations.
public
static with(array<string|int, mixed>|string $relations) : QueryBuilder
Parameters
- $relations : array<string|int, mixed>|string
Return values
QueryBuildercreateRelation()
Create a relation instance.
protected
createRelation(string $propertyName, array<string|int, mixed> $metadata) : BelongsToRelation|HasManyRelation|HasOneRelation|BelongsToManyRelation
Parameters
- $propertyName : string
- $metadata : array<string|int, mixed>
Tags
Return values
BelongsToRelation|HasManyRelation|HasOneRelation|BelongsToManyRelationgetForeignKeyName()
Get the foreign key name for this model.
protected
getForeignKeyName() : string
Return values
stringgetPdo()
Get the PDO connection.
protected
static getPdo() : PDO
Tags
Return values
PDOgetPivotTableName()
Get the pivot table name for a many-to-many relationship.
protected
getPivotTableName(string $relatedModel) : string
Parameters
- $relatedModel : string
Return values
stringgetRelatedForeignKeyName()
Get the foreign key name for a related model.
protected
getRelatedForeignKeyName(string $relatedModel) : string
Parameters
- $relatedModel : string
Return values
stringgetRelationMetadata()
Get relation metadata for a property.
protected
getRelationMetadata(string $propertyName) : array<string|int, mixed>|null
Parameters
- $propertyName : string
Return values
array<string|int, mixed>|nullhandleDependentRelations()
Handle dependent relations before destroying the model.
protected
handleDependentRelations() : void
Tags
performInsert()
Perform an insert operation.
protected
performInsert() : bool
Tags
Return values
boolperformUpdate()
Perform an update operation.
protected
performUpdate() : bool
Tags
Return values
boolpropertyToColumn()
Convert property name to database column name.
protected
propertyToColumn(string $propertyName) : string
Parameters
- $propertyName : string