Skip to the content
Documentation

The bit-field algorithm

No ratings yet

Exponential stores which languages an object has, and whether it is always available, in one integer: a bit field. This page describes the database fields involved, for developers who query them directly.

Language IDs

Every content language is a row of the table ezcontent_language: its ID, its locale (such as ger-DE) and its name. The IDs are powers of two: 2, 4, 8, 16 and so on. A new language gets the lowest power of two no other language has. The value 1 (bit 0) is not a language: it marks an object as always available.

PHP integers have 64 bits, one of them the sign and one the always-available flag, so an installation holds at most 62 content languages (30 on 32-bit PHP), as eZContentLanguage::maxCount() says.

The fields

Table and field Holds
ezcontentobject.language_mask The sum of the IDs of the languages the published version has, plus 1 when the object is always available
ezcontentobject.initial_language_id The ID of the object's main language
ezcontentobject_version.language_mask The sum of the IDs of the languages of that version, plus 1
ezcontentobject_version.initial_language_id The ID of the language the version was edited in
ezcontentobject_attribute.language_code, language_id The locale of the translation the attribute belongs to, and its language ID (plus 1 for the main language of an always-available object)
ezcontentclass.always_available 1 when new objects of the class are always available
ezcontentclass.language_mask, initial_language_id The languages of the class name and description, and the class's main language

The object's mask is updated whenever its languages change, that is when a translation is added or removed or the flag is changed.

Example

With English (ID 2) and French (ID 4):

language_mask Bits The object
2 00010 exists in English
3 00011 exists in English and is always available
4 00100 exists in French
5 00101 exists in French and is always available
6 00110 exists in English and French
7 00111 exists in English and French and is always available

Filtering

To find the objects in a language, the kernel tests one bit: objects in French are those with language_mask & 4 > 0. To show a siteaccess's content, it combines the IDs of its SiteLanguageList[] into one mask and keeps the objects whose mask shares a bit with it, or that have bit 0 set. Which translation is shown is then decided by the order of the list. This works on every database engine the kernel supports.

In PHP, use the API rather than the bits: eZContentLanguage::fetchByLocale(), eZContentLanguage::maskByLocale(), $object->languages() and $object->attribute( 'always_available' ).

More

Contributors

Comments

Add a comment

Comments are read by a moderator before they appear.