# Modules

# Audit

At the moment this module has 2 main features:

  • When using the API endpoints with an authenticated user, all tables that have creator_username, creator_timestamp, editor_username and editor_timestamp columns will have this 4 columns populated, this way the system can tell who and when a record was created, and also date and user of the last change. This behaviour will happen by default with all tables. Notice when using the SDK you are not authenticated therefore this fields will not be populated.

  • the second feature is optional and by default is turned off. It can be enabled on the init.ini file in settings.audit. If enabled it will populate the ay_audit table, where you can find a new entry for each update or delete that occurs. This way the system knows the when, who and what changed on each single record. It's also possible to remove specific schemas from being part of the audit, this is usefull for tables taht generates a lot of data and might not be essencial to be part of the audit system.

audit-blacklist = "GameplayLog,GameplayLogState"

Dependencies:

  • Audit (class)
  • ay_audit (table)
  • settings.audit (init)

# Analytics

Some systems needs to gather information and keep it in a format that can be easily consumed by some endpoint or by the MAYS UI Dashboard (if you want to know how to configure meta data for dashboards go to Dashboard on the main menu). In order to save the information it's pretty simple.


use mays\core\AnalyticLogger;

$analitic_log = new AnalyticLogger();
$analitic_log->saveMonthlyLog("GROSS_AMOUNT_SOLD", "", $sale->total_value);

$analitic_log->saveWeeklyLog("GROSS_AMOUNT_SOLD", "", $sale->total_value);

In this example we are saving in two different granularities (week and month) the gross amount of product sold. The system will always assume the event is happening on that moment (so it will use the current date). You can define any custom string that represents a type of event or something you want to track (in this case GROSS_AMOUNT_SOLD). The second argument is another string that can be specific for a given event (it will not be grouped), and the third argument is the value that is going to be added to the tracker.

Dependencies:

  • connectors\GoogleAnalytics (class)
  • ay_google_analytics (table)
  • keys.ganalytics (init)
  • ganalytics-view-id (init)

# Scheduled Tasks

# Cron jobs

In order to make the creation and management of cron jobs we can use the class SystemEvent, an example is also available on the folder crons.

# Delaying a task

Some tasks are more intensive than others, so you can postpone a task to run in the background. In order to make that the framework has the class CronTask.

Schedulling a task is as easy as this.


$data = [
  "email" => "john.snow@afteryou.pt",
  "subject" => "New message",
  "body" => "Hi John! You know nothing!",
];
CronTask::scheduleTask('2023-09-10 10:00', 'SEND_EMAIL', $data, "");

This would run as near as the date that was schedulled, the SEND_MAIL is only a string to allow your to make the post process of the task, data stores the information needed to run the task, and the last parameter allow your to update a task if you already have a previous Id. In this case, since this is a custom task, if you want to send an email you would need to edit crons/schedule.php file and implement the execution of the task.

Already built-in is the processing and optimization of images that can be turned on on the init.ini file using the property settings.image-post-processing = true, which will delay the creation of optimized files (after an upload of an image for instance).

In order to work this module requires that a cron job (crons/schedule.php)runs every 5 minutes on the server, this setup needs to be done manually on the server.

Dependencies:

  • schema\CronTask (class)
  • SystemEvent (class)
  • ay_sysevent (table)
  • ay_cron_task (table)
  • settings.image-post-processing (init)

# Debug, Log and Errors

To easily create a log on a file we can use the Debug class, check out the following example:

Debug::log($message);

Sometimes the system produces errors that need to trigger different level of alerts, to deal with errors the framework implements the Error class that can fire to different channels.

new Error("Error message", -1)

The above example just creates an object with a message and code.

The following examples also fires an action to a specific channel.

new Error("Error message", -1, "", Error::EMAIL);
//will send you an email using the template INTERNAL-SYSTEM-LOG

new Error("Error message", -1, "", Error::SLACK);
//requires specific configuration on slack and on your init.ini file

new Error("Error message", -1, "", Error::FILE);
//similar to the Debug but this class is meant for errors only.

Dependencies:

  • Debug (class)
  • Error (class)
  • settings.log-level-low (init)
  • settings.log-level-high (init)
  • settings.log-level-critical (init)
  • keys.slack-webhook (init)

# Emails

This is a simple module that allows to send simple emails or html template based emails.

The following is an example of an email without any template.


use mays\core\Mailer;

$mailer = new Mailer();
//from, array of "to", subject, body and attachments
$ok = $mailer->sendMail(
        ["noreply@afteryou.pt", "AY"],
        [
          ["suporte@afteryou.pt", "AY Support"]
        ],
        "The subject",
        "The body <b>can use html</b>",
        ["attached_file.pdf"]
      );

Another example, but now using a template (a template is has predefined subject and html body, typically with placeholders that can be dynamically replaced).


use mays\core\Mailer;

$mailer = new Mailer();
$ok = $mailer->sendEmailTemplate(
    "PASSWORD-RECOVERY",
    [
      "email" => "some dynamic variable"
    ],
    [
      [$email, $name]
    ]
  );

Notice the configuration of the email server used is configured under the MAYS UI.

Also the MAYS UI allows customers to define a simple image for the header, footer and also a text for a signature. This elements can be used as regular placeholders on any template.

# Forms and Models

# SMS

# Web Router

Last Updated: 8/25/2023, 10:25:50 PM