XVIII. Code Snippets Reference

Midgard uses code snippets and snippetdirs for handling library-like code in a format that enables sharing the code between hosts. Code snippets are stored in snippetdir tree hierarchies within the Midgard database.

1. Snippet Record Definition

A snippet record contains information about a snippet and the snippetdir it resides in.

Fields of a snippet record

id

The id of the snippet record.

up

The id of the snippetdir the snippet is in.

name

The name of the snippet record.

code

The code of the snippet record. The content of this field is the actual code that gets executed.

author

The person id of the author of the snippet.

creator

The person id of the creator of the snippet.

created

Date and time the Snippet was created.

revisor

The person id of the last revisor of the snippet.

revised

Date and time the Snippet was last revised.

revision

An integer representing the number of times the snippet has been revised.

sitegroup

This id of the sitegroup the snippet belongs to.

2. Snippet Object Definition

This section describes the content of snippet objects. Most object parameters map directly to the record fields described above.

The functions listed within the object definition are the object methods that are available for the object. Usage information about those methods can be found in Object Methods.

/* Snippet Object Prototype */

Class snippet {

  var $N;             # Only with mgd_list_XXX functions.
  var $id;
  var $up;
  var $name;
  var $code;
  var $sitegroup;

  function fetch();    # Only with mgd_list_XXX functions.

  function create();
  function update();
  function delete();

  function createattachment();
  function updateattachment();
  function deleteattachment();
  function getattachment();
  function listattahcments();
  function openattachment();
  function serveattachement();

  function listparameters();
  function parameter();
  function searchparameters();
 
  function getsitegroup();
  function setsitegroup();

}
Table of Contents
mgd_create_snippet — Create a snippet
mgd_delete_snippet — Delete a snippet
mgd_get_snippet — Get a snippet
mgd_get_snippet_by_name — Get a snippet by its name
mgd_include_snippet — Include a snippet
mgd_list_snippets — List snippets
mgd_update_snippet — Update a snippet