-
Notifications
You must be signed in to change notification settings - Fork 12
4.A. Reference Events
- 4.A.1.1. system-model-create
- 4.A.1.2. system-model-detail
- 4.A.1.3. system-model-remove
- 4.A.1.4. system-model-restore
- 4.A.1.5. system-model-search
- 4.A.1.6. system-model-update
- 4.A.2.1. system-relation-link
- 4.A.2.2. system-relation-unlink
- 4.A.2.3. system-relation-unlink-all
- 4.A.3.1. history-model-versions
- 4.A.4.1. auth-create
- 4.A.4.2. auth-detail
- 4.A.4.3. auth-forgot
- 4.A.4.4. auth-update
- 4.A.4.5. auth-login
- 4.A.4.6. auth-verify
The following events are used throughout the system and is encouraged that you try to use these before deciding to write your own events.
Model events are used to manage the objects defined by schemas.
Inserts a row into the database
| Name | Validation | Description | Example |
|---|---|---|---|
| schema | required | Name of the schema | profile |
| [fields] | required | Fields defined in the provided schema | {"profile_name": "John Doe"} |
cradle(function() {
//make a Request and Response
$payload = $this->makePayload();
//set the staging data
$payload['request']
->setStage('schema', 'profile')
->setStage('profile_name', 'John Doe');
$this->trigger('system-model-create', $payload['request'], $payload['response']);
});$ bin/cradle system-model-create schema=profile profile_name="John Doe"{
"error": false,
"results": {
"profile_id": 1,
"profile_name": "John Doe",
"profile_active": 1,
"profile_created": "2019-01-01 00:00:00"
"profile_updated": "2019-01-01 00:00:00"
}
}Retrieves a row from the database
| Name | Validation | Description | Example |
|---|---|---|---|
| schema | required | Name of the schema | profile |
| [unique field] | required | The primary ID or a unique field defined in the provided schema | {"profile_id": 1} |
cradle(function() {
//make a Request and Response
$payload = $this->makePayload();
//set the staging data
$payload['request']
->setStage('schema', 'profile')
->setStage('profile_id', 1);
$this->trigger('system-model-detail', $payload['request'], $payload['response']);
});$ bin/cradle system-model-detail schema=profile profile_id=1{
"error": false,
"results": {
"profile_id": 1,
"profile_name": "John Doe",
"profile_active": 1,
"profile_created": "2019-01-01 00:00:00"
"profile_updated": "2019-01-01 00:00:00"
}
}Removes a row from the database. If an active field is not provided in the
provided schema, this will permanently remove the row.
| Name | Validation | Description | Example |
|---|---|---|---|
| schema | required | Name of the schema | profile |
| [unique field] | required | The primary ID or a unique field defined in the provided schema | {"profile_id": 1} |
cradle(function() {
//make a Request and Response
$payload = $this->makePayload();
//set the staging data
$payload['request']
->setStage('schema', 'profile')
->setStage('profile_id', 1);
$this->trigger('system-model-remove', $payload['request'], $payload['response']);
});$ bin/cradle system-model-remove schema=profile profile_id=1{
"error": false,
"results": {
"profile_id": 1,
"profile_name": "John Doe",
"profile_active": 0,
"profile_created": "2019-01-01 00:00:00"
"profile_updated": "2019-01-01 00:00:00"
}
}Restores a row from the database. If an active field is not provided in the
provided schema, this will event will not work.
| Name | Validation | Description | Example |
|---|---|---|---|
| schema | required | Name of the schema | profile |
| [unique field] | required | The primary ID or a unique field defined in the provided schema | {"profile_id": 1} |
cradle(function() {
//make a Request and Response
$payload = $this->makePayload();
//set the staging data
$payload['request']
->setStage('schema', 'profile')
->setStage('profile_id', 1);
$this->trigger('system-model-restore', $payload['request'], $payload['response']);
});$ bin/cradle system-model-restore schema=profile profile_id=1{
"error": false,
"results": {
"profile_id": 1,
"profile_name": "John Doe",
"profile_active": 1,
"profile_created": "2019-01-01 00:00:00"
"profile_updated": "2019-01-01 00:00:00"
}
}Searches for rows in the database.
| Name | Validation | Description | Example |
|---|---|---|---|
| schema | required | Name of the schema | profile |
| q | optional | Search Term | John |
| filter | optional | Exact match given the column/s | {"filters": {"profile_name": "John Doe"}} |
| in | optional | Range match given the column/s | {"in": {"profile_name": ["John","Jane"]}} |
| like | optional | Partial match given the column/s | {"like": {"profile_name": John}} |
| span | optional | Number ranges | {"span": {"product_price": [0,100]}} |
| start | optional (default:0) | The starting index | 1 |
| range | optional (default:50) | Up to how many rows to return | 25 |
cradle(function() {
//make a Request and Response
$payload = $this->makePayload();
//set the staging data
$payload['request']
->setStage('schema', 'profile')
->setStage('q', 'John')
->setStage('filter', 'profile_name', 'John Doe')
->setStage('like', 'profile_name', 'John')
->setStage('in', 'profile_name', ['John Doe', 'Jane Doe'])
->setStage('start', 0)
->setStage('range', 10);
$this->trigger('system-model-search', $payload['request'], $payload['response']);
});$ bin/cradle system-model-search schema=profile q=John start=0 range=10 __json='{"filter":{"profile_name":"John Doe"},"in":{"profile_name":["John Doe", "Jane Doe"]},"like":{"profile_name":"John"}}'
$ bin/cradle system-model-search schema=profile q=John start=0 range=10 __query='filter[profile_name]=John+Doe&in[profile_name][]=John+Doe&in[profile_name][]=Jane+Doe&like[profile_name]=John'{
"error":false,
"results": {
"rows": [
{
"profile_id": 1,
"profile_name": "John Doe",
"profile_active": 1,
"profile_created": "2019-01-20 06:43:42",
"profile_updated": "2019-01-20 06:43:42"
},
{
"profile_id": 2,
"profile_name": "John Doe",
"profile_active": 1,
"profile_created": "2019-01-20 06:43:42",
"profile_updated": "2019-01-20 06:43:42"
}
],
"total": 2
}
}Updates a row in the database.
| Name | Validation | Description | Example |
|---|---|---|---|
| schema | required | Name of the schema | profile |
| [unique field] | required | The primary ID or a unique field defined in the provided schema | {"profile_id": 1} |
| [fields] | required | Fields defined in the provided schema | {"profile_name": "John Doe"} |
cradle(function() {
//make a Request and Response
$payload = $this->makePayload();
//set the staging data
$payload['request']
->setStage('schema', 'profile')
->setStage('profile_id', 1)
->setStage('profile_name', 'Jane Doe');
$this->trigger('system-model-update', $payload['request'], $payload['response']);
});$ bin/cradle system-model-update schema=profile profile_id=1 profile_name="Jane Doe"{
"error": false,
"results": {
"profile_id": 1,
"profile_name": "Jane Doe",
"profile_active": 1,
"profile_created": "2019-01-01 00:00:00"
"profile_updated": "2019-01-01 00:00:01"
}
}Relational events are used to manage the relations between objects.
Links an object with another object. The provided schemas for both the objects
should be already related to each other where schema1 is the base schema and
schema2 is the defined relation for example auth_profile table in the
database. This would make schema1=auth and schema2=profile
| Name | Validation | Description | Example |
|---|---|---|---|
| schema1 | required | Name of the base schema | auth |
| schema2 | required | Name of the defined relation | profile |
| [primary key 1] | required | The primary ID of the base schema | {"auth_id": 1} |
| [primary key 2] | required | The primary ID of the defined relation | {"profile_id": 1} |
cradle(function() {
//make a Request and Response
$payload = $this->makePayload();
//set the staging data
$payload['request']
->setStage('schema1', 'auth')
->setStage('schema2', 'profile')
->setStage('auth_id', 100)
->setStage('profile_id', 100);
$this->trigger('system-relation-link', $payload['request'], $payload['response']);
});$ bin/cradle system-relation-link schema1=auth schema2=profile auth_id=100 profile_id=100{
"error": false
}Unlinks an object from another object. The provided schemas for both the objects
should be already related to each other where schema1 is the base schema and
schema2 is the defined relation for example auth_profile table in the
database. This would make schema1=auth and schema2=profile
| Name | Validation | Description | Example |
|---|---|---|---|
| schema1 | required | Name of the base schema | auth |
| schema2 | required | Name of the defined relation | profile |
| [primary key 1] | required | The primary ID of the base schema | {"auth_id": 1} |
| [primary key 2] | required | The primary ID of the defined relation | {"profile_id": 1} |
cradle(function() {
//make a Request and Response
$payload = $this->makePayload();
//set the staging data
$payload['request']
->setStage('schema1', 'auth')
->setStage('schema2', 'profile')
->setStage('auth_id', 100)
->setStage('profile_id', 100);
$this->trigger('system-relation-link', $payload['request'], $payload['response']);
});$ bin/cradle system-relation-unlink schema1=auth schema2=profile auth_id=100 profile_id=100{
"error": false
}Unlinks all objects from another object. The provided schemas for both the objects
should be already related to each other where schema1 is the base schema and
schema2 is the defined relation for example auth_profile table in the
database. This would make schema1=auth and schema2=profile
| Name | Validation | Description | Example |
|---|---|---|---|
| schema1 | required | Name of the base schema | auth |
| schema2 | required | Name of the defined relation | profile |
| [primary key 1] | required | The primary ID of the base schema | {"auth_id": 1} |
cradle(function() {
//make a Request and Response
$payload = $this->makePayload();
//set the staging data
$payload['request']
->setStage('schema1', 'auth')
->setStage('schema2', 'profile')
->setStage('auth_id', 100);
$this->trigger('system-relation-link', $payload['request'], $payload['response']);
});$ bin/cradle system-relation-unlink-all schema1=auth schema2=profile auth_id=100{
"error": false
}History events manages the changes of content in the system
Retrieves the revision changes of a history item
| Name | Validation | Description | Example |
|---|---|---|---|
| history_id | required | The primary history ID | 1 |
cradle(function() {
//make a Request and Response
$payload = $this->makePayload();
//set the staging data
$payload['request']->setStage('history_id', 75);
$this->trigger('history-model-versions', $payload['request'], $payload['response']);
});$ bin/cradle history-model-versions history=75{
"error": false,
"results": {
"history": {
"history_id": 75,
"history_activity": "updated Application #1",
"history_meta": {...},
"history_page": "/admin/system/model/app/update/1",
"history_path": "611ad7939e287573aca1f772bfbc643a.json",
"history_remote_address": "127.0.0.1",
"history_table_id": 1,
"history_table_name": "app",
"history_type": "update",
"history_flag": 1,
"history_active": 1,
"history_created": "2019-01-30 08:10:05",
"history_updated": "2019-01-30 08:10:05",
"profile_id": 1,
"profile_name": "John Doe",
"profile_active": 1,
"profile_created": "2019-01-20 06:43:42",
"profile_updated": "2019-01-20 06:43:42"
},
"original": {
"profile_id": 1,
"app_id": 1,
"app_domain": "dev.cradle.local",
"app_title": "Sample App",
"app_updated": "2019-01-30 08:10:05"
},
"current": {
"profile_id": 1,
"app_id": 1,
"app_domain": "dev.cradle.local",
"app_title": "Sample App 2",
"app_updated": "2019-01-30 08:10:05"
}
}
}Authentication events manages users from sign up to log in.
Creates a user that can login.
| Name | Validation | Description | Example |
|---|---|---|---|
| profile_name | required | Name of the user | Jane Doe |
| auth_type | optional | Name of the role to assume | admin |
| auth_active | optional | Whether if this already verified | 1 |
| auth_slug | required | Email Address | [email protected] |
| auth_password | required | Password | 123 |
| confirm | required | Confirming the password | 123 |
cradle(function() {
//make a Request and Response
$payload = $this->makePayload();
//set the staging data
$payload['request']
->setStage('profile_name', 'Jane Doe')
->setStage('auth_type', 'user')
->setStage('auth_active', 1)
->setStage('auth_slug', '[email protected]')
->setStage('auth_password', '123')
->setStage('confirm', '123');
$this->trigger('auth-create', $payload['request'], $payload['response']);
});$ bin/cradle auth-create profile_name="Jane Doe" auth_type=user auth_active=1 [email protected] auth_password=123 confirm=123{
"error": false,
"results": {
"auth_id": 2,
"auth_type": 2,
"auth_slug": "[email protected]",
"auth_active": 1,
"auth_created": "2019-01-30 08:10:05",
"auth_updated": "2019-01-30 08:10:05",
"profile_id": 2,
"profile_name": "Jane Doe",
"profile_active": 1,
"profile_created": "2019-01-30 08:10:05",
"profile_updated": "2019-01-30 08:10:05"
}
}Gets the users information, including password
Use this event securely
| Name | Validation | Description | Example |
|---|---|---|---|
| [unique field] | required |
auth_id or auth_slug
|
{"auth_id": 1} |
cradle(function() {
//make a Request and Response
$payload = $this->makePayload();
//set the staging data
$payload['request']->setStage('auth_slug', '[email protected]');
$this->trigger('auth-detail', $payload['request'], $payload['response']);
});$ bin/cradle auth-detail [email protected]{
"error": false,
"results": {
"auth_id": 2,
"auth_type": 2,
"auth_slug": "[email protected]",
"auth_password": "$32abcd54...",
"auth_active": 1,
"auth_created": "2019-01-30 08:10:05",
"auth_updated": "2019-01-30 08:10:05",
"profile_id": 2,
"profile_name": "Jane Doe",
"profile_active": 1,
"profile_created": "2019-01-30 08:10:05",
"profile_updated": "2019-01-30 08:10:05"
}
}Sends out an email to recover the account.
| Name | Validation | Description | Example |
|---|---|---|---|
| [unique field] | required |
auth_id or auth_slug
|
{"auth_id": 1} |
cradle(function() {
//make a Request and Response
$payload = $this->makePayload();
//set the staging data
$payload['request']->setStage('auth_slug', '[email protected]');
$this->trigger('auth-forgot', $payload['request'], $payload['response']);
});$ bin/cradle auth-forgot [email protected]{
"error": false,
"results": {
"auth_id": 2,
"auth_type": 2,
"auth_slug": "[email protected]",
"auth_active": 1,
"auth_created": "2019-01-30 08:10:05",
"auth_updated": "2019-01-30 08:10:05",
"profile_id": 2,
"profile_name": "Jane Doe",
"profile_active": 1,
"profile_created": "2019-01-30 08:10:05",
"profile_updated": "2019-01-30 08:10:05"
}
}Updates a user's information.
| Name | Validation | Description | Example |
|---|---|---|---|
| profile_name | optional | Name of the user | Jane Doe |
| auth_type | optional | Name of the role to assume | admin |
| auth_active | optional | Whether if this already verified | 1 |
| auth_slug | optional | Email Address | [email protected] |
| auth_password | optional | Password | 123 |
| confirm | optional | Confirming the password | 123 |
cradle(function() {
//make a Request and Response
$payload = $this->makePayload();
//set the staging data
$payload['request']
->setStage('profile_name', 'Jane Doe')
->setStage('auth_type', 'user')
->setStage('auth_active', 1)
->setStage('auth_slug', '[email protected]')
->setStage('auth_password', '123')
->setStage('confirm', '123');
$this->trigger('auth-update', $payload['request'], $payload['response']);
});$ bin/cradle auth-update profile_name="Jane Doe" auth_type=user auth_active=1 [email protected] auth_password=123 confirm=123{
"error": false,
"results": {
"auth_id": 2,
"auth_type": 2,
"auth_slug": "[email protected]",
"auth_active": 1,
"auth_created": "2019-01-30 08:10:05",
"auth_updated": "2019-01-30 08:10:05",
"profile_id": 2,
"profile_name": "Jane Doe",
"profile_active": 1,
"profile_created": "2019-01-30 08:10:05",
"profile_updated": "2019-01-30 08:10:05"
}
}Checks if the user email and password are correct
Use this event securely
| Name | Validation | Description | Example |
|---|---|---|---|
| auth_slug | required | Log In Email | [email protected] |
| auth_password | required | Password | 123 |
cradle(function() {
//make a Request and Response
$payload = $this->makePayload();
//set the staging data
$payload['request']
->setStage('auth_slug', '[email protected]')
->setStage('auth_password', '123');
$this->trigger('auth-login', $payload['request'], $payload['response']);
});$ bin/cradle auth-login [email protected] auth_password=123{
"error": false,
"results": {
"auth_id": 2,
"auth_type": 2,
"auth_slug": "[email protected]",
"auth_active": 1,
"auth_created": "2019-01-30 08:10:05",
"auth_updated": "2019-01-30 08:10:05",
"profile_id": 2,
"profile_name": "Jane Doe",
"profile_active": 1,
"profile_created": "2019-01-30 08:10:05",
"profile_updated": "2019-01-30 08:10:05"
}
}Sends out an email to verify the account
| Name | Validation | Description | Example |
|---|---|---|---|
| [unique field] | required |
auth_id or auth_slug
|
{"auth_id": 1} |
cradle(function() {
//make a Request and Response
$payload = $this->makePayload();
//set the staging data
$payload['request']->setStage('auth_slug', '[email protected]');
$this->trigger('auth-verify', $payload['request'], $payload['response']);
});$ bin/cradle auth-verify [email protected]{
"error": false,
"results": {
"auth_id": 2,
"auth_type": 2,
"auth_slug": "[email protected]",
"auth_active": 1,
"auth_created": "2019-01-30 08:10:05",
"auth_updated": "2019-01-30 08:10:05",
"profile_id": 2,
"profile_name": "Jane Doe",
"profile_active": 1,
"profile_created": "2019-01-30 08:10:05",
"profile_updated": "2019-01-30 08:10:05"
}
}2.B. Reference: Validation Types
2.D. Reference: Indexes & Relations
3.A. Reference: Cradle on Shared Hosts
3.B. Reference: Command Line Tools
3.C. Reference: Architecture Recommendations
4.4. Intro to Handlebars Templating
4.B. Reference: Handlebars Helpers
4.C. Reference: Doon Interfaces
4.D. Reference: Global Package Methods