Quickstart Guide

Introduction

This Quickstart guide is designed as a resource for PHP developers to learn how to structure and create new modules within the Elentra Platform using our latest development standards and best practices.

History of Entrada/Elentra

The history of Entrada development goes back over a decade and as time has passed, best practices in both the industry and our codebase have improved. These improvements change the way that we write our code. Even though the way that we write our code has improved we have not, in many cases, gone back and updated older modules within the application.

While this can cause some confusion and perhaps frustration for new developers, it is important to realize that updating older modules in the application would potentially cause significant merge conflicts for schools that have customized those modules to meet their specific needs. The time taken to resolve these conflicts would be time taken away from the development of new functionality to support the mission of the institutions.

Instead of a large rewrite of the core codebase, the Elentra Development Community in 2016 committed to moving ahead with a transition to Service Oriented Architecture using the Lumen Laravel PHP framework. This transition began with Entrada ME 1.10 and this documentation will be updated accordingly to reflect these changes.

New developers should also get familiar to seeing both the Entrada and Elentra branding within the platform. In 2018 we underwent a large community-wide re-brand from Entrada to Elentra, and we decided that updating the older codebase to use the new Elentra name was not time well spent. Class, variable, and constant names containing Entrada will remain until the transition to SOA is complete.

Creating a New Module

Elentra ME

This documentation will walk you through step-by-step creating a new module that we are calling "Sandbox" in Elentra ME. This new Sandbox module will consist of the following:

  1. A new migration to accommodate the new database table and ACL rules.

  2. A new model that will be used to access the new table.

  3. A new public module that will show the learners a list of all of the sandboxes.

  4. A new admin module that will allow administrative users to add, edit, and delete the sandboxes.

  5. A new view helper that will render the form used on both the add and edit pages, and another that will render a simple sidebar item.

Pay special attention to note of the bolded words above: migration, model, public module, admin module, and view helper. This terminology is frequently used by Elentra developers.

All files that are references within the document can be downloaded here for review.

Let's Begin

Open the ~/Sites/elentra-1x-me folder using PhpStorm or whatever IDE/Editor you have selected. Ensure that you set the tab size in your editor to 4 spaces as the tab character will not be accepted. For more information on coding standards visit the Coding Standards section.

1. Create a New Database Migration

This new Sandbox module is going to need a new table in the elentra database. In order to systematically and consistently apply these types of changes you would create a migration.

A migration is used to record and apply changes and data transformations within the Elentra databases. For more information on how to use migrations please see the Database documentation section.

To create a new migration run the following command in the terminal, from within the docker container, in /var/www/vhosts/elentra-1x-me within the Elentra root folder:

You will be asked to provide the corresponding GitHub Issue number, and then a new file will be generated within the www-root/core/library/Migrate folder that looks like 2017_01_11_150030_1477.php. This file will have up(), down(), and audit() methods that you must complete.

Creating a migration for a new Elentra setting

When creating a new Elentra setting, the command:

will prompt a series of questions which will generate a boilerplate migration for the new Elentra setting.

Running Elentra migrations

Once your new migration file has been created, you can apply and test these changes by executing the following:

2. Create the New Model

You will use the Model_Sandbox class exclusively to access the new elentra.sandboxes table created by the migration. You can create a template for the new Model by running:

Once the model has been created it will reside in the filesystem as www-root/core/library/Models/Sandbox.php and you will use Model_Sandbox throughout the Elentra codebase. This is possible thanks to Composer's ability to support both PSR-0 and PSR-4 autoloading.

Here are a few examples of how you can use your new model:

Inserting data

Selecting data

Updating data

Deleting data

3. Create the new Public Module

Elentra does not use a typical MVC pattern as you would recognize from frameworks like Laravel or Symfony. Although similar in effect, our pattern is not entirely object oriented; we use a mix of object oriented and procedural design patterns.

Elentra's .htaccess file contains mod_rewrite rules that pipe the majority of requests through the index.php and admin.php files. The index.php file is used to display public modules, whereas the admin.php file is used to display admin modules.

One significant difference between most MVC frameworks and Elentra is that our request routing is entirely automatic vs. being manually defined in a routes file. For example, if you visit http://elentra-1x-me.localhost/profile/gradebook/assignments in your browser, Elentra will load the www-root/core/modules/public/profile/gradebook/assignments/index.inc.php file.

For a more thorough overview of this information please see the Directory Structure section within Overview.

We will begin by creating a public module in the www-root/core/modules/public folder. Create a new file in this directory called sandbox.inc.php and place the following inside:

4. Create the new Admin Modules

While the public module example above was quite simple (there was only a single file), you can create a much more extensible hierarchy by creating components within your modules. Here is an example of the Sandbox modules administrative file structure:

sandbox.inc.php (1 of 5)

Within www-root/core/modules/admin/sandbox.inc.php place the following content:

sandbox/add.inc.php (2 of 5)

Within www-root/core/modules/admin/sandbox/add.inc.php place the following content:

sandbox/delete.inc.php (3 of 5)

Within www-root/core/modules/admin/sandbox/delete.inc.php place the following content:

sandbox/edit.inc.php (4 of 5)

Within www-root/core/modules/admin/sandbox/edit.inc.php place the following content:

sandbox/index.inc.php (5 of 5)

Within www-root/core/modules/admin/sandbox/index.inc.php place the following content:

5. Create the new View Helpers

A view helper allows you to create a single block of reusable code that can be displayed in many places. There are quite a few presently undocumented options and features of our view helpers so we would encourage you to review the files within the www-root/core/library/Views/ directory for more information. Developer Tip: HTMLTemplate.php is an especially interesting feature.

You will notice that if you visit http://elentra-1x-me.localhost/sandbox in your web browser that you will now see a PHP error. That is due to the fact that we are using view helpers on lines 30 - 31 of www-root/core/modules/public/sandbox.inc.php but have not yet created the files.

Proceed with creating the two new files to accommodate the Views_Sandbox_Sidebar and Views_Sandbox_Form view helpers:

Sandbox/Form.php (1 of 2)

Within www-root/core/library/Views/Sandbox/Form.php place the following content:

Sandbox/Sidebar.php (2 of 2)

Within www-root/core/library/Views/Sandbox/Sidebar.php place the following content:

Finishing Tasks

At this point you should have a relatively functional module that allows you to create, read, update, and delete items from the elentra.sandboxes table. There a few final tasks to complete the new module.

1. Add an ACL Array Entry

Elentra's ACL is quite powerful, albeit slightly complex. For more information on exactly how the Access Control Level feature works please visit the Elentra ACL section.

Within the www-root/core/library/Entrada/authentication/entrada_acl.inc.php file you will want to add the resource_type that you created back in the migration to the $modules array. This will allow groups other than medtech:admin to access your module based on elentra_auth.acl_permissionsrecords that have been setup for this resource_type.

For example:

2. Add an Admin Menu Entry

The Admin tab within the primary navigation near the top of the Elentra user interface would benefit from having a "Manage Sandbox" link added to it.

In order to do this add the following line to the $MODULES section of the www-root/core/config/settings.inc.php file:

This will give anyone with create access to the sandbox resource a menu item within the Admin tab.

Getting Help

This Quickstart Guide is intended to give you an overview of how to create a new module within Entrada ME 1.8. It will also give you a glimpse into how Elentra operates. If you would like a more in-depth one-on-one tutorial, please contact the Elentra Consortium team or reach out in our Slack channel.

Last updated