Chapter 18. Midgard Objects and Methods

Table of Contents
$object->create — Create a record
$object->createattachment — Create a record attachment
$object->delete — Delete a record
$object->deleteattachment — Delete a record attachment
$object->getattachment — Get a record attachment
$object->getsitegroup — Get the sitegroup a record belongs to
$object->guid — Get the GUID (Global Unique IDentificator) of an object
$object->listattachments — List the attachments to a record
$object->listparameters — List the parameters/parameter domains for a record
$object->openattachment — Open a record attachment as a file handle
$object->parameter — Set or get a record parameter
$object->searchparameters — Search record parameters
$object->serveattachment — Serve a record attachment
$object->setscore — Set the score of a record
$object->setsitegroup — Set the sitegroup a record belongs to
$object->settype — Set the type of a record
$object->update — Update a record
$object->updateattachment — Update a record attachment

Midgard 1.4 (Bifrost) introduces an object oriented approach to the creation and manipulation of records. This allows for better readable code. It also can save typing, especially when updating records. This section covers the object oriented methods, and to what objects they are available.

Midgard objects share some common characteristics that are explained below and in the following sections, especially a common set of object methods.

Midgard-PHP objects aren't genuine PHP class instances but get built by the Midgard PHP extension using PHP's internal API. Different Midgard functions return objects of the same class in different "states": "Fetchables" as returned by the mgd_list_*() functions, and "full instances" of a single Midgard record as generated by mgd_get_*(). The differences between those "states" are described below.

Warning

Note that class members of the form __*__ are private by definition. No application should ever access those, not even read-only!

Fetchables. The objects returned by the mgd_list_*() functions are "truncated" (due to obvious performance issues) and have only the following five common members:


    <?php
// General object prototype for fetchables

class MidgardFetchable {
  $__table__;     // PRIVATE!
  $__res__;       // PRIVATE!

  $N;             // Number of items in the list
  $id;            // id of the current instance
  $sitegroup;     // sitegroup of the current instance
  
  fetch();        // The only method: fetches the next
                  // instance in the result list
}
    

Both $N and $__res__ are specific only to this truncated form of Midgard objects and are used internally by the fetch() method. Most specific Midgard classes currently have more members than the ones mentioned above. Those additional members help easily building lists, but may become deprecated in the future.

Full instances. The full instances of Midgard classes must be obtained with the appropriate mgd_get_*() function. Those mgd_get_*() functions return a fully fledged object without $N and $__res__, but with all the members and methods properties described in the manual chapter explaining the object.