School IT Expert

Build a Contact Management Application

joomlaExtensionsTo demonstrate how to use Fabrik we will now go through the process of setting up a simple Contacts Management application. This is a fairly simple application, but it will include setting up a one-to-one table relationships and a many-to-many. 

You'll need to install Fabrik to get yourself started.


Introduction

In this application we will have tables for people, and establishments.  We will need contact details for both people and establishments.  This will include some common information (address, tel number etc...) so we will use an additional table called contact_details and create a one-to-one relationship with the people and establishment tables.  We will also create a table called employments to demonstrate a many-to-many relationship between people and establishments.

 

Create a List

The first step, is to create a list.

  1. Go to Components > Fabrik > Lists.
  2. Click New.
  3. In the left pane, under Details, give your list a Label and an Introduction(description).
    1. Label - People
    2. Introduction - Individuals that we'd like to keep in contact with.
  4. In the right pane, under Data, confirm that the connection is for the site database.
  5. Enter a Table name of fabrik_people.
  6. Save your list.

 

This process will create a new list item in Fabrik, but it also creates a new Fabrik Form and a Fabrik Group (both called People).  Additionally it will create two new Elements (id and date), and importantly a table in your Joomla database, called fabrik_people.

 

You will typically want to hide the id and date fields from any list view.

  1. Go to Components > Fabrik > Elements.
  2. Click the related Show In Lisk green tick against the element that you want to hide

 

Repeat this process with a Label of "Establishments" with an Introduction of "Establishments that we'd like to have contact details for", and call the Table "fabrik_establishments".

 

Add Some Elements

In Fabrik, Elements become fields in your database table.  We will now add some new Elements to the People group and the Establishments group.

  1. Go to Components > Fabrik > Elements.
  2. From the Select Group filter, choose People.
    1. This will limit the view, to only those elements for the People group.
  3. Click New.
  4. Enter a Name of first_name.
  5. Add a Label of First Name.
  6. From the Plug-in drop-down, choose Field.
  7. Click Save.

Repeat this process for Surname.

Also select Establishments in the Select Group filter as before, and repeat this process to add a new element called Name, for the Establishments group.

 

One-to-one Relationship

We will now create the contact details table.  We will start by creating a new list called Contact Details...

  1. Go to Components > Fabrik > Lists.
  2. Click New.
    1. In the left pane, under Details, give your list a Label and an Introduction(description).
    2. Label - Contact Details
    3. Introduction - Contact details for individuals and establishments.
    4. In the right pane, under Data, confirm that the connection is for the site database.
    5. Enter a Table name of fabrik_contact_details.
  3. Save your list.

 

Now we can create the required elements...

  1. Go to Components > Fabrik > Elements.
  2. From the Select Group filter, choose Contact Details.
  3. Click New.
    1. Enter a Name of street.
    2. Add a Label of Street.
    3. From the Plug-in drop-down, choose Field.
  4. Click Save.

Repeat this process to create Field elements for Town, County, Postcode and Telephone.

 

We will now add two reference fields for the People and Establishments tables.

  1. Go to Components > Fabrik > Elements.
  2. From the Select Group filter, choose Contact Details.
  3. Click New.
    1. Enter a Name of people_id.
    2. Add a Label of People id.
    3. From the Plug-in drop-down, choose databasejoin.
    4. In the Options section, choose the fabrik_people Table.
    5. For Value select id.
    6. For Label select first_name.
  4. Click Save.

Once you've created the people_id element, you will typically want to hide it.

  1. Go to Components > Fabrik > Elements.
  2. From the Plugin drop-down, choose databasejoin.
  3. Select the people_id element for editing.
  4. In the Options section, set Hidden to Yes.

 

Repeat this process to create a Field element for establishment_id.

 

Inner Join

Now that the tables and elements have been created, we can create inner joins for the one-to-one relationships.

  1. Go to Components > Fabrik > Lists.
  2. Click People to edit the People list.
    1. In the right-pane, select Data, and then Joins.
    2. Click Add.
    3. For Join type select Inner Join.
    4. Select fabrik_people for the From drop-down.
    5. Select fabrik_contact_details for the To drop-down.
    6. Select id for From column.
    7. Select people_id for To column.
    8. Select Yes for Delete joined data.
  3. Save your changes.

Repeat this process for the Establishments list.

 

Front-end Display

Now we are ready to show the People and Establishment lists in the front-end.

  1. Go to Menu > Main Menu.
  2. Click New.
  3. For Menu Item Type, select Fabrik - List.
  4. Under Required Settings, choose People from the drop-down.
  5. Enter People for the Menu Title.
  6. Click Save.

Now visit the front-end and click your newly created link for People.

You will be able to add new people to the system by clicking on the Green Plus symbol.

 


More articles of interest...

{module More articles of interest...}

Thanks for visiting!