-
Notifications
You must be signed in to change notification settings - Fork 18
MgdSchema
Midgard Schema is a data abstraction system which is used to define data structures in XML files. Each MgdSchema class corresponds to one table in the database. The rows of the table can be accessed as native objects in PHP with Metadata attached.
MgdSchema XML definitions include information about fieldnames (which are available as object attributes) and the corresponding data types. Aside from that, they can mark fields as links (allowing querying by linked constraints) and they can also include hierarchic information, i.e. tree structures. Here's for example the (slightly shortened) MgdSchema for midgard_article
:
<type name="midgard_article" table="article" parent="midgard_topic">
<property name="id" type="unsigned integer" primaryfield="id">
<description>Local non-replication-safe database identifier</description>
</property>
<property name="name" type="string" index="yes">
<description>URL name of the article</description>
</property>
<property name="extra1" type="string">
<description>Extra string field</description>
</property>
<property name="extra2" type="string">
<description>Extra string field</description>
</property>
<property name="extra3" type="string">
<description>Extra string field</description>
</property>
<property name="type" type="integer" index="yes">
<description>Type of the article</description>
</property>
<property name="up" type="unsigned integer" link="midgard_article:id" upfield="up">
<description>Possible prior part of the article</description>
</property>
<property name="topic" type="unsigned integer" link="midgard_topic:id" parentfield="topic">
<description>Topic the article is under</description>
</property>
<property name="title" type="string">
<description>Title of the article</description>
</property>
<property name="abstract" type="text">
<description>Short abstract of the article</description>
</property>
<property name="content" type="text">
<description>Content of the article</description>
</property>
<property name="url" type="string" index="yes">
<description>External URL of the article</description>
</property>
<property name="lang" type="unsigned integer" link="midgard_language:id">
<description>Language the article is in</description>
</property>
</type>
Once this MgdSchema is read by the system, it will provide the midgard_article
PHP class, which you can use to interact with the data:
$article = new midgard_article($id);
echo '<h1>' . $article->title . '</h1>';
$article->abstract = 'My first article';
$article->update();
Query Builder or Midgard Collector are used to retrieve MgdSchema objects from the database. Midgard Reflection is available for writing Schema agnostic applications like Asgard.
In standard Midgard installations, at least these MgdSchemas are available:
- Articles
- Attachments
- Groups
- Events
- Hosts
- Pages
- Page Elements
- Pagelinks
- Parameters
- Persons
- Snippetdirs
- Snippets
- Styles
- Style Elements
- Topics
They are defined in the file MgdObjects.xml
http://www.midgard-project.org/documentation/mgdschema/
http://www.midgard-project.org/documentation/mgdschema-file-properties/
http://www.midgard-project.org/documentation/mgdschema-in-php/