Models¶
Intro¶
This package uses a combination of ORM Entities and Service Models to manipulate the user records stored in the database tables. This package relies upon Doctrine as an ORM framework.
All interactions with the data model must be performed via entity models, and all interactions with the entities must be performed via service model methods.
Entities¶
The entities in this package relate directly to a mapped database table, and an instance of an entity represents a single table row.
All entity properties have a protected scope, and must use the provided getter/setters to retrieve and manipulate their values.
In addition to the getter/setters, all entities have a few lifecycle setters to set values based upon record creates and updates. These special case methods are indicated in this documentation.
Role¶
This entity represents theroles
table.
Properties¶
- protectedint$id
- Represents the autoincrement ID for Roles Table
- protectedint$active
- Integer flag representing boolean; Role is active if value is "1"/true, inactive if value is "0"/false
- protectedstring$name
- String representing the Role name
- protectedstring$created
- Date string for the timestamp when the record was created
- protectedstring$updated
- Date string for timestamp when the record was last updated
Methods¶
- publicgetId()
- Returns the current record $id
- publicsetId(int $id)
- Sets the current record $id with a provided value
- publicgetActive()
- Returns the current record $active value
- publicsetActive(string $active)
- Sets the current record $active with a provided value
- publicgetName()
- Returns the current record $name value
- publicsetName(string $name)
- Sets the current record $name with a provided value
- publicgetCreated()
- Returns the current record $created value
- publicsetCreated(string $created)
- Sets the current record $created with a provided value
- publicgetUpdated()
- Returns the current record $updated value
- publicsetUpdated(string $updated)
- Sets the current record $updated with a provided value
- publicdoStuffOnPrePersist()
- Lifecycle method called on initial record create via @PrePersist annotation
- Calls existingsetCreated() method with current timestamp as value
- publicdoStuffOnPreMerge()
- Lifecycle method called on record update via @PreUpdate annotation
- Calls existingsetUpdated() method with current timestamp as value
User¶
This entity represents theusers
table.
Properties¶
- protectedint$id
- Represents the autoincrement ID for Users Table
- protectedstring$email
- Represents the email for a user
- protectedstring$password
- Represents the user's hashed password
- protectedint$role
- Foreign Key ID to the role table; represents a user's role
- protectedstring$name
- Represents a user's name
- protectedstring$gateway_customer_id
- Foreign Key Id to a payment gateway table; represents a user's relationship to a payement gateway
- Please Note: this will be implemented in a future feature.
- protectedstring$last_login
- Timestamp of the user's last successful login
- protectedstring$created
- Timestamp when the record was created
- protectedstringupdated
- Timestamp when the record was last updated
Methods¶
- publicgetId()
- Returns the current record $id
- publicsetId(int $id)
- Sets the current record $id with a provided value
- publicgetEmail()
- Returns the current record $email value
- publicsetEmail(string $email)
- Sets the current record $email with a provided value
- publicgetPassword()
- Description: Returns the current record $password value
- publicsetPassword(password $password)
- Description: MD5 encodes the provided string and sets the current record's $password value to this hashed string
- publicgetRole()
- Description: Returns the current record $role value
- publicsetRole(string $role)
- Sets the current record $role value with a provided value
- publicgetName()
- Returns the current record $name value
- publicsetName(string $name)
- Sets the current record $name with a provided value
- publicgetGatewayCustomerId()
- Returns the current record gateway_customer_id value
- publicsetGatewayCustomerId(int $gateway_customer_id)
- Sets the current record $gateway_customer_id with a provided value
- publicgetLastLogin()
- Returns the current record $last_login value
- publicsetLastLogin(string $last_login)
- Sets the current record $last_login to the provided value
- publicgetCreatedAt()
- Returns the current record $created_at value
- publicsetCreatedAt(string $created_at)
- Sets the current record $created_at to the provided value
- publicgetUpdatedAt()
- Returns the current record $created_at value
- publicsetUpdatedAt()
- Sets the current record $updated_at to the provided value
- publicdoStuffOnPrePersist()
- Lifecycle method called on initial record create via @PrePersist annotation
- Calls existingsetCreatedAt() method with current timestamp as value
- publicdoStuffOnPreMerge()
- Lifecycle method called on record update via @PreUpdate annotation
- Calls existingsetUpdatedAt() method with current timestamp as value
- publicmarshall(string $type = 'json')
- Method that returns a current record as a 'safe' datatype
- Used for serializing a record
User/Log¶
This entity represents theuser_event_log
table.
Properties¶
- protectedint$id
- Represents the autoincrement ID for User Event Log Table
- protectedint$user_id
- Foreign Key ID to the role table; represents a user record and associates it to this log record
- protectedstring$event_log
- A string indicating the type of user event logged
- protectedstring$event_data
- A JSON serialized object string representing a user logged event
- protectedstring$created_at
- Date string for the timestamp when the record was created
Methods¶
- publicgetId()
- Returns the current record $id
- publicsetId(int $id)
- Sets the current record $id
- publicgetUserId()
- Returns the current record $user_id value
- publicsetUserId(string $userId)
- Sets the current record $user_id to the provided value
- publicgetEventLog()
- Returns the current record $event_log value
- publicsetEventLog(string $eventLog)
- Sets the current record $event_log to the provided value
- publicgetEventData()
json_decodes
and returns the current record $event_data value
- publicsetEventData(string $eventData)
json_encodes
the provided value and sets this to the current record $event_data value
- publicgetCreatedAt()
- Returns the current record $created_at value
- publicsetCreatedAt(string $created)
- Sets the current record $created_at to the provided value
- publicdoStuffOnPrePersist()
- Lifecycle method called on initial record create via @PrePersist annotation
- Calls existingsetCreatedAt() method with current timestamp as value
Service Models¶
Mailgun¶
The Mailgun service model provides an interface to Mailgun to send emails following user events.
This service model extends theMailgun\Mailgun
model provided by the Mailgun composer package.
Properties¶
- string$domain
- String representing the sender domain for this erdiko instance.
Methods¶
- public__construct()
- Creates an instance of the Mailgun service model.
- Loads a config file and sets some local variables from this loaded config, before calling the parent constructor in
Mailgun\Mailgun
- protectedgetDefaults()
- Returns an array of default values for mailgun settings
- publicsendMail(object $postData)
- Sends an email with provided data.
- Filters the provided $postData object after typecasting to an array, returns the method call to the parent class
sendMessage
method call
- publicforgotPassword(string $email,string $html)
- Sends an email to a provided email using the provided HTML template string
- Calls the class
sendMail
method with provided values
Role¶
The Role service model provides an interface to create and manipulate role records via the Role entity.
This class uses the Erdiko Doctrine EntityTrait to allow it to get & set the entity manager.
Properties¶
- privateEntityManager$_em
Methods¶
- public__construct()
- Creates an instance of the Role service model.
- publiccreate(object $data)
- Create a new role entity instance
- publicfindById(int|string $id)
- Return a Role entity by id
- publicfindByName(string $name)
- Return a Role entity with a name given
- publicfindByStatus(int $status)
- Return an array of Roles that have the provided status
- publicgetCountByRole(string $role)
- Return a count for role records for the provided role name
- publicgetUsersForRole(string $role)
- Return a list of users for a provided role name
- publicsave(array $data)
- Save/Persist a new role entity for the provided values
- publicgetEntity(array $filter)
- Returns a Role entity record based on the provided parameters, if none found return an empty entity
- publicdelete(string $id)
- Delete a Role entity record for the provided id
User¶
The User service model provides an interface to create and manipulate user records via the User entity.
This class uses the Erdiko Doctrine EntityTrait to allow it to get & set the entity manager.
Properties¶
- CONST PASSWORDSALT
- String used to salt a password before hashing
- Note This will eventually be moved to a config file, currently it is just a class constant
- protectedEntity/User $_user
- protectedEntityManager $_em
Methods¶
- public__construct(EntityManager $em = null)
- Creates an instance of the User service model.
- Optional EntityManager parameter to substitute the one provided by the trait
- publicsetEntity(Entity/User $entity)
- Sets $_user to a providedEntity/User
- publicgetEntity()
- Returns the current $_user value
- publicunmarshall(string $encoded)
- Unserializes a user object and returns a populated User Entity
- Required by the iErdikoUser Interface
- protectedcreateAnonymous()
- Returns a new anonymous user entity
- Required by the iErdikoUser Interface
- publicstaticgetAnonymous()
- Returns a new anonymous user entity
- Required by the iErdikoUser Interface
- publicmarshall(string $type = 'json')
- Serializes a populated User Entity
- publicgetUsername()
- Returns current $_user name value
- publicgetDisplayName()
- Returns current $_user name value
- publiccreateUser(array $data)
- Create a new entity and set it to current user model
- publicgetSalted(string $password)
- Returns password string concat'd with password salt
- publicauthenticate(string $email,string $password)
- Attempt to validate the user by querying the DB with the provided email and password. Returns populated User Entity if found, else returns false
- publicisLoggedIn()
- Returns true if the user is logged in
- publicisEmailUnique()
- Returns true if provided email was not found in the user table
- publicgetRoles()
- Return the friendly user role names
- publicisAdmin()
- Returns true if the current $_user has an Admin role
- publicisAnonymous()
- Returns true if the current $_user has an anonymous role
- publichasRole(string $role = 'anonymous')
- Returns true if current user has the provided role
- publicgetRole()
- Returns current $_user role value
- publicgetUsers(int $page = 0,int $pagesize = 100,string $sort = 'id',string $direction = 'asc')
- Return all the users paginated by parameters
- publicdeleteUser(int|string $id)
- Delete a user record for a provided id. Returns false if a user record is not found, and returns true if successful deletion
- publicgetUserId()
- Returns current $_user id value
- publicsave(object $data)
- Update an existing user or return a new user populated with data provided.
- publicgetById(int|string $id)
- Return a user by id
- publicgetByParams(array $params)
- Return users using params as query filter
- publicgetGatewayCustomerId(int|string $uid)
- Return the Gateway Customer ID for a provided user id
User/Event/Log¶
The User/Event/Log service model provides an interface to create an manipulate user event log records via the User/Log entity.
This class uses the Erdiko Doctrine EntityTrait to allow it to get & set the entity manager.
Properties¶
- protectedEntityManager $_em
Methods¶
- public__construct()
- Creates an instance of the User/Log service model.
- publicsave(Entity/User/Log $logEntity)
- Persist and save the provided User/Log entity
- publicgenerateEntity(int|string $uid,string $event_log,string $event_data = null)
- Return a populated User/Log entity with the provided values
- publicgetAllLogs()
- Return all User/Log records as an array of User/Log entities
- publicgetLogs(int $page = 0,int $pagesize = 100,string $sort = 'id', $direction = 'asc')
- Return an array of User/Log records based on provided parameters
- publicgetLogsByUserId(int $id,int $page = 0,int $pagesize = 100,string $sort = 'id',string $direction = 'asc')
- Return an array of User/Log records for a provided user, filtered by additional parameters
- publicfindById(int|string $id)
- Return a single User/Log entity for a provided ID
- publiccreate(int|string $user_id = null,string $event_log = null,string $event_data = null)
- Create a new User/Log entity, wrapper forgenerateEntity() method