MagratheaModel
in package
Table of Contents
Properties
- $autoLoad : mixed
- $dbAlias : mixed
- $dbPk : mixed
- $dbTable : mixed
- $dbValues : mixed
- $dirtyValues : mixed
- $relations : mixed
Methods
- __get() : string
- MAGIC FUNCTION: gets required property
- __set() : object|null
- MAGIC FUNCTION: updates required property
- __toString() : string
- To String! =)
- Assign() : MagratheaModel
- Gets an array of whatever and assign it to the properties of model
- Delete() : bool
- Deletes the object in database
- Get() : string
- gets required property
- GetAutoLoad() : array<string|int, mixed>
- Gets autoload objects
- GetById() : object|null
- Returns object by Id. If null, creates a null instance of the object.
- GetDataTypeFromField() : mixed
- Get (Magrathea) data type from field
- GetDbTable() : string
- Gets table related to model
- GetDbValues() : array<string|int, mixed>
- Gets array of table column values
- GetFields() : array<string|int, mixed>
- Get fields from model
- GetFieldsForSelect() : string
- Prepare fields for this model for a select statement
- GetID() : int|string
- Gets id value
- GetNextID() : int
- Gets the next auto increment id for this object
- GetPkName() : string
- Gets PK Name
- GetProperties() : array<string|int, mixed>
- Get all properties from model
- IncludeAllModels() : mixed
- Include all classes presents on `Models` folder
- Insert() : int
- Inserts the object in database
- IsEmpty() : bool
- Checks if the object exists (id not null)
- LoadObjectFromTableRow() : mixed
- Receives an array with the columns and values and associates then internally into the object
- ModelName() : string
- returns the name of the class without the namespace
- Ref() : string
- returns a string for identifying the object in a relation
- Save() : int|bool
- Saves: Using a insert if pk is not set and an update if pk is set Basically, Inserts if id does not exists and updates if id does exists
- Set() : object|null
- Sets given property
- ToArray() : mixed
- ToJson() : array<string|int, mixed>
- Gets a Json
- ToString() : string
- To String! =)
- Update() : bool
- Updates the object in database
- GetRelationId() : int
- When updating an object with a relation returns the relation ID or inserts it.
Properties
$autoLoad
protected
mixed
$autoLoad
= null
$dbAlias
protected
mixed
$dbAlias
= array()
$dbPk
protected
mixed
$dbPk
$dbTable
protected
mixed
$dbTable
$dbValues
protected
mixed
$dbValues
= array()
$dirtyValues
protected
mixed
$dirtyValues
= array()
$relations
protected
mixed
$relations
= array()
Methods
__get()
MAGIC FUNCTION: gets required property
public
__get(string $key) : string
Parameters
- $key : string
-
property
Tags
Return values
string —property value
__set()
MAGIC FUNCTION: updates required property
public
__set(string $key, object $value) : object|null
Parameters
- $key : string
-
property
- $value : object
-
value
Tags
Return values
object|null —property value
__toString()
To String! =)
public
__toString() : string
Return values
string —Object.toString()
Assign()
Gets an array of whatever and assign it to the properties of model
public
Assign(array<string|int, mixed> $data) : MagratheaModel
Parameters
- $data : array<string|int, mixed>
-
data
Return values
MagratheaModel —itself
Delete()
Deletes the object in database
public
Delete() : bool
Return values
bool —successfully updated
Get()
gets required property
public
Get(string $key[, bool $supressException = false ]) : string
Parameters
- $key : string
-
property
- $supressException : bool = false
-
if set to true, function will not throw Exception if property does not exist
Tags
Return values
string —property value
GetAutoLoad()
Gets autoload objects
public
GetAutoLoad() : array<string|int, mixed>
Return values
array<string|int, mixed> —auto load objects or null if none
GetById()
Returns object by Id. If null, creates a null instance of the object.
public
GetById(int|string $id) : object|null
This will also load any related objects that are set as "autoload" internally. if an object with the given id can not be found, or any of the auto-load related objects can not be found an exception will be thrown.
Parameters
- $id : int|string
-
id for the referred object
Tags
Return values
object|null —desired object
GetDataTypeFromField()
Get (Magrathea) data type from field
public
static GetDataTypeFromField(string $field) : mixed
Parameters
- $field : string
-
magrathea-related type
GetDbTable()
Gets table related to model
public
GetDbTable() : string
Return values
string —model's table
GetDbValues()
Gets array of table column values
public
GetDbValues() : array<string|int, mixed>
Return values
array<string|int, mixed> —model's columns
GetFields()
Get fields from model
public
GetFields() : array<string|int, mixed>
Return values
array<string|int, mixed> —model's fields
GetFieldsForSelect()
Prepare fields for this model for a select statement
public
GetFieldsForSelect() : string
Return values
string —fields for select clause built
GetID()
Gets id value
public
GetID() : int|string
Return values
int|string —Id value
GetNextID()
Gets the next auto increment id for this object
public
GetNextID() : int
Return values
int —next auto-increment value
GetPkName()
Gets PK Name
public
GetPkName() : string
Return values
string —PK name column
GetProperties()
Get all properties from model
public
GetProperties() : array<string|int, mixed>
Return values
array<string|int, mixed> —model's properties
IncludeAllModels()
Include all classes presents on `Models` folder
public
static IncludeAllModels() : mixed
Insert()
Inserts the object in database
public
Insert() : int
Tags
Return values
int —id of inserted object
IsEmpty()
Checks if the object exists (id not null)
public
IsEmpty() : bool
Return values
bool —does it?
LoadObjectFromTableRow()
Receives an array with the columns and values and associates then internally into the object
public
LoadObjectFromTableRow(array<string|int, mixed> $row) : mixed
Parameters
- $row : array<string|int, mixed>
-
mysql result for the object
ModelName()
returns the name of the class without the namespace
public
ModelName() : string
Return values
stringRef()
returns a string for identifying the object in a relation
public
Ref() : string
Return values
stringSave()
Saves: Using a insert if pk is not set and an update if pk is set Basically, Inserts if id does not exists and updates if id does exists
public
Save() : int|bool
Return values
int|bool —id if inserted and true if updated
Set()
Sets given property
public
Set(string $key, mixed $value[, bool $supressException = false ]) : object|null
Parameters
- $key : string
-
property
- $value : mixed
-
value
- $supressException : bool = false
-
if set to true, function will not throw Exception if property does not exist
Tags
Return values
object|null —property value
ToArray()
public
ToArray() : mixed
ToJson()
Gets a Json
public
ToJson() : array<string|int, mixed>
Return values
array<string|int, mixed> —json
ToString()
To String! =)
public
ToString() : string
Return values
string —Object.toString()
Update()
Updates the object in database
public
Update() : bool
Return values
bool —successfully updated
GetRelationId()
When updating an object with a relation returns the relation ID or inserts it.
private
GetRelationId(mixed $obj) : int
Parameters
- $obj : mixed
Return values
int —object id