One of the most powerful features of BEdita is the possibility to define and use free semantic relations between objects. In this article I'm going to show you how build and use them.

BEdita objects

BEdita is completely object-oriented, so every element is an object with a specific object type. The object type itself defines some particular behaviors like the possibility to be showed in a certain module, the possibility to stay in the tree structure and the way to relate with other object types. You can find the BEdita object types inside the table object_types that contains id, name and module fields. To create a new relations we'll use the id of the object types.

Where do I define relations between objects?

The first thing to know is that these relations have to be defined in a configuration file, in particular in bedita-app/config/bedita.cfg.php. You can find some default relations in bedita-app/config/bedita.ini.php but this file shouldn't be touched (may be overwritten during an update of BEdita), so have a look at the relations in this file only as reference.

In bedita.cfg.php you can find the configuration variable:


commented. Uncomment it and let's customize your relations.
Choose a name
for your relations for example "speakers":

$config["objRelationType"] = array(
   "speakers" => array()

In this way I'm going to define a free relation named "speakers" that can link all objects. Now go to Addressbook module (this module use Card objects, as you can see in object_types table) and click on create "new card". Have a look at Relationship tab and you can see that the new relation appears in it (figure 1).

Now you can click on "Connect new items" button to link other objects to this one, change order of related objects by drag & drop (figure 2) and then save the card to estabilish the relation.

In this way we have defined the relation for all object types so if you look at other modules like Documents, Events, Galleries, etc... you'll find the "speakers" relation in the Relationship tab. But if I want that the relation is estabilished only between some objects, how can I do it?

Customizing a relation between some object types

Suppose that I have to manage a festival site. I can create all festival events thorugh Events module and all people that partecipate to the festival through Addressbook module. Some of this people will be speakers so I will have to associate the events to the cards of the speakers through the "speakers" relation. I want to use my "speakers" relation only to link events to cards, I don't want to see and to use this relation in Galleries module, for instance. Edit $config["objRelationType"] in this way:

$config["objRelationType"] = array(
   "speakers" => array(
      "left" => array("card"),
      "right" => array("event")

Here I define that the "speakers" relation is estabilished between some object types. On the left I have card objects and on the right I have event objects. Note that the order of the object types in "left", "right" key is indifferent.

In this way only in Events and Addressbook mdoules you can see "speakers" in Relationship tab.

If you want to use this relation for other object types it's enough add ids to "left" or "right" key so, for example:

$config["objRelationType"] = array(
   "speakers" => array(
      "left" => array("card"),
      "right" => array("event","documents")

With this definition I can associate documents and events from a card object and I can associate only cards from a document or an event object.


One way relations

The relations are built in both directions by default, so I can see the association from both the objects involved. In some rare case I could desire that the relation were shown only in one direction. In these cases we can build a one way relation always editing bedita.cfg.php file.

$config["cfgOneWayRelation"] = array(
   "other one way relation"

Now if I create a "speakers" relation from card to event I will see the relation inside the card object but I will not see it inside the event object.


Relations in frontend

As explained in "My first frontend" you'll find the semantic relations between objects in an array named "relations" so for example in an event related with some card by "speakers" relation I will have:

[relations] => Array (
[speakers] => array( 
   0 => card1, 
   1 => card2, 

At the end

At the end of this article you should be able to build your custom semantic relations between objects in simple or complex way to model your BEdita instance according to your needs.