Open Source Content Management Framework

MgdSchema file properties

  1. Defining Custom Types
    1. Defining Storage Locations
  2. Defining Properties
    1. Settting the Property Type
    2. Specifying the Database Data Type
    3. Resolving Property Name and Table Field Conflicts.
    4. Setting the Primary Key
    5. Setting database index (since Ragnaroek 8.09.3)
  3. Defining Tree Hierarchies
  4. References to Other Types
  5. Including Other Schemas
  6. Creating Types with Multilingual Content

MgdSchema files use XML attributes and properties for defining the object types handled within the Midgard persistent storage framework.

Some type and table names are reserved since Midgard 1.8. See the list of reserved words.

Mandatory attributes are:

  • type
  • property
  • name

Defining Custom Types

For every newly-defined type, mandatory attributes have to be set. To define a new MySuperClass type, use the type element:

<type name="MySuperClass">
</type>

This is sufficient to create a new type and initialize the corresponding new class when the schema is loaded. Such a type is accessible on the midgard-php level as the MySuperClass class.

Defining Storage Locations

Empty classes (let's say "interfaces" on midgard-php4 level) may be constructed without storage (i.e. a corresponding database table) defined. To set the table name for a particular type, the XML property table should be used:

<type name="MySuperClass" table="my_table">
</type>

Classname and table name have to be exactly the same if the object's record should be be fetchable by the mgd_get_object_by_guid function. In any other case classname and table name can be different. This limitation will be resolved in the future

Defining Properties

To define class members (object properties) for a new type, use property elements for child attributes:

<type name="MySuperClass" table="my_table">
   <property name="title"/>
</type>

On the midgard-php, you can get or set the property value using the typical PHP syntax: $object->title.

Settting the Property Type

By default all properties are string type, unless another type is distinctly set. Available data types are:

  • string
  • integer
  • unsigned integer
  • text (longtext is deprecated)
  • float
  • bool
  • datetime
  • guid

For every XML property data type there is a corresponding database data type:

  • string is equal to varchar(255)
  • integer is equal to int(11) (Values can range from -2,147,483,648 to 2,147,483,647)
  • unsigned integer is equal to int(11) (Values can range from 0 to 4,294,967,295)
  • text is equal to text ( or longtext )
  • float is equal to float
  • bool is equal to boolean
  • guid is equal to varchar(80)

The application has to set a correct GUID value if the property type is defined as guid. To define a column with an optional GUID value (i.e. if the application should accept empty values), the type should be set to string and dbtype="varchar(80)" should be defined.

Specifying the Database Data Type

The additional XML property dbtype may be used when a specific database type is needed, for example, a property with the string type could use the varchar(80) type instead of varchar(255).

<property name="title" type="string" dbtype="varchar(80)"/>

or

<property name="info" type="string" dbtype="set('auth')"/>

Resolving Property Name and Table Field Conflicts.

The XML property field can be used if you want the object's property name to be different from the table's column name.

<property name="title" type="string" field="otherfield"/>

This describes that object's property 'title' will use the column 'otherfield' as its value storage. This is equal to SQL's SELECT table.otherfield AS title.

Setting the Primary Key

When a type has many properties defined and one of those should be used as (or better, point to) the table's primary key, the XML property primaryfield can be used.

<property name="primary" type="unsigned integer" primaryfield="id"/>

primaryfield is defined as an attribute of a property, not of a type. primaryfield also defines the property's database data type. This takes precedence over the field XML property (i.e. primaryfield will be used and field will be ignored)

Since midgard 1.8, primaryfield's type must be defined as unsigned integer

Setting database index (since Ragnaroek 8.09.3)

If property's field has special usage (e.g. holds a reference for other record), create index. By default indexes are not created for all properties. To set it, use reserved attribue 'index'.

<property="count" type="int" index="yes"/>

Note, that by default indexes are created for such properties and fields:

  • up property
  • parent property
  • property which is a link
  • property which is a link target (is linked)

Also, internally indexes are created for:

  • 'sid' property if object is multilingual
  • 'sitegroup' property

Do not create indexes for boolean properties, as it won't improve performance.

Defining Tree Hierarchies

MgdSchema is able to create tree hierarchies. Objects of the same type may be managed in a tree structure by using the XML property upfield. For defining a type as a 'child' object of another type, the XML properties parentfield and parent should be used.

  • upfield is defined as property of an XML 'property' attribute
  • parentfield is defined as property of an XML 'property' attribute
  • parent is defined as property of an XML 'type' attribute

Properties which are parentfield or upfield must be the type of unsigned integer, guid or string.

This definition describes the MyClass type, which is a node in the MySuperClass tree, and also may have own nodes with objects of the same (MyClass) Type. Useful methods for such types are documented in MgdSchema object's API (list_childs, is_in_tree, get_by_path).

References to Other Types

The link attribute's property should be used when the object's property (and the column's record value) holds a pointer to another type. The property's value should hold the primary property value of the referenced type.

<property name="creator"  type="unsigned integer" link="midgard_person:id"/>

The special : separator describes which property of the referenced type should be used as the property's value. If this separator is not defined, the guid property of the referenced type is used by default.

Properties which are links must be the type of unsigned integer, guid or string.

See how to query referenced objects

Including Other Schemas

Applications may use as many schemas as needed. The include attribute can be used to load other schemas. There is no limitation to the number of included schemas. The full path to the schema file to be included can be freely defined.

<include name="/home/smith/midgard/schemas/favourite.xml"/>

Creating Types with Multilingual Content

Multilang properties are described for backward compatibility and may change in the future

To use multilingual features in a newly-created type, the properties multilang and table should be set.

<property name="content" type="longtext" multilang="yes" table="childnodes_i"/>

There is no need to define 'multilang' for every property when more than one property has multilingual content. This value is "inherited" and used for every XML property which has the same multilingual table set as value.

Multilang support in MgdSchema has a few limitations:

  • defined table must be suffixed with '_i'
  • property 'sid' must be defined as class member
Tagged
mgdschema
ragnaroek
vinland
thor
Designed by Nemein, hosted by Anykey