Extending the Midgard Classes

The class skeletons in Midgard Base Classes show how to build an infrastructure to create new classes based on Midgard Objects. Unfortunalety you can not simply inherit from them directly. Some Parts prevent this, so I had to write some wrappers to make regular inheritance possible. Be aware that these classes are only basically tested yet...

How it works

Basically you have to copy all the data elements of the MidgardObject by hand but rely on inheritance for the available object methods. In theory you should be able to use the Cxxx classes like you would use the regular Midgard classes, with a few exceptions:

Object Construction

The constructors of the wrapper classes has two forms: Called with no parameters, it will create an empty object, like you get if you call mgd_get_xxx();. Called with an integer parameter it tries to retrieve the Midgard Object with the given ID from the Database.

Record Creation

You create the object by first calling it with an empty constructor, then fill in all neccessary values and call Cxxx::Create(). It will fill in all values and update the object itself. The object remains valid. You still have to ensure that all neccessary variables are filled.

Record Deletion

Upon calling Cxxx::delete() the object will automagically delete all attached parameters and attachments (including their parameters in turn), so you shouldn't get into dependency Problems. The object is (naturally) invalid after the call.

Error handling

The classes do error handling as far as they are able to do it. Semantics is roughly the same as you are used to whitin the Midgard system. For instance you still have to check mgd_errstr() after each operation. Since there is no possiblty to directly manipulate mgd_errstr() from your applications, some error messages get lost in a simple false. The code should be simple enough though to get along with this restriction.

Ideas

Some of the Midgard functions could be added to the different wrappers. CArticle already does this for the Approval Mechanism, but it could be done for many of the Midgard functions. For example CPerson could directly support the Memebership infrastructure thus wrapping away most of the Membership functions which are sometimes a little bit tricky to use. Theoretically you could insert over 90 percent of the Midgard Functions into these classes.

Integrate direct support for fetch Traversables. I'm not sure if this is possible at all. Currently you have to individually construct objects of the Wrapper classes after you've retrieved the Record ID with fetch(). My current opinion is that you can't successfully wrap the hybrid objects. Looking at it from an OOP Point of view, this design is very tricky. Instead you could create functions (or list classes) that work with ID Arrays, instead of fetching everything. The complete Database access shouldn't happen before you call the constructor of the Object itself. The Problem ist, that the Midgard Library doesn't support retrievals like this, so the best way currently working with the mgd_list_xxx functions to retrieve the IDs.